1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

ls: compile regexes outside of loop in tests

This commit is contained in:
Daniel Hofstetter 2025-01-10 07:42:13 +01:00
parent c872cfa5d1
commit e777db9304

View file

@ -1096,13 +1096,16 @@ fn test_ls_long() {
let at = &scene.fixtures; let at = &scene.fixtures;
at.touch(at.plus_as_string("test-long")); at.touch(at.plus_as_string("test-long"));
#[cfg(not(windows))]
let regex = r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*";
#[cfg(windows)]
let regex = r"[-dl](r[w-]x){3}.*";
let re = &Regex::new(regex).unwrap();
for arg in LONG_ARGS { for arg in LONG_ARGS {
let result = scene.ucmd().arg(arg).arg("test-long").succeeds(); let result = scene.ucmd().arg(arg).arg("test-long").succeeds();
#[cfg(not(windows))] result.stdout_matches(re);
result.stdout_matches(&Regex::new(r"[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}.*").unwrap());
#[cfg(windows)]
result.stdout_matches(&Regex::new(r"[-dl](r[w-]x){3}.*").unwrap());
} }
} }
@ -1115,23 +1118,30 @@ fn test_ls_long_format() {
at.touch(at.plus_as_string("test-long-dir/test-long-file")); at.touch(at.plus_as_string("test-long-dir/test-long-file"));
at.mkdir(at.plus_as_string("test-long-dir/test-long-dir")); at.mkdir(at.plus_as_string("test-long-dir/test-long-dir"));
for arg in LONG_ARGS { // Assuming sane username do not have spaces within them.
// Assuming sane username do not have spaces within them. // A line of the output should be:
// A line of the output should be: // One of the characters -bcCdDlMnpPsStTx?
// One of the characters -bcCdDlMnpPsStTx? // rwx, with - for missing permissions, thrice.
// rwx, with - for missing permissions, thrice. // Zero or one "." for indicating a file with security context
// Zero or one "." for indicating a file with security context // A number, preceded by column whitespace, and followed by a single space.
// A number, preceded by column whitespace, and followed by a single space. // A username, currently [^ ], followed by column whitespace, twice (or thrice for Hurd).
// A username, currently [^ ], followed by column whitespace, twice (or thrice for Hurd). // A number, followed by a single space.
// A number, followed by a single space. // A month, followed by a single space.
// A month, followed by a single space. // A day, preceded by column whitespace, and followed by a single space.
// A day, preceded by column whitespace, and followed by a single space. // Either a year or a time, currently [0-9:]+, preceded by column whitespace,
// Either a year or a time, currently [0-9:]+, preceded by column whitespace, // and followed by a single space.
// and followed by a single space. // Whatever comes after is irrelevant to this specific test.
// Whatever comes after is irrelevant to this specific test. let re = &Regex::new(
scene.ucmd().arg(arg).arg("test-long-dir").succeeds().stdout_matches(&Regex::new(
r"\n[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}\.? +\d+ [^ ]+ +[^ ]+( +[^ ]+)? +\d+ [A-Z][a-z]{2} {0,2}\d{0,2} {0,2}[0-9:]+ " r"\n[-bcCdDlMnpPsStTx?]([r-][w-][xt-]){3}\.? +\d+ [^ ]+ +[^ ]+( +[^ ]+)? +\d+ [A-Z][a-z]{2} {0,2}\d{0,2} {0,2}[0-9:]+ "
).unwrap()); ).unwrap();
for arg in LONG_ARGS {
scene
.ucmd()
.arg(arg)
.arg("test-long-dir")
.succeeds()
.stdout_matches(re);
} }
// This checks for the line with the .. entry. The uname and group should be digits. // This checks for the line with the .. entry. The uname and group should be digits.