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;
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 {
let result = scene.ucmd().arg(arg).arg("test-long").succeeds();
#[cfg(not(windows))]
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());
result.stdout_matches(re);
}
}
@ -1115,7 +1118,6 @@ fn test_ls_long_format() {
at.touch(at.plus_as_string("test-long-dir/test-long-file"));
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.
// A line of the output should be:
// One of the characters -bcCdDlMnpPsStTx?
@ -1129,9 +1131,17 @@ fn test_ls_long_format() {
// Either a year or a time, currently [0-9:]+, preceded by column whitespace,
// and followed by a single space.
// Whatever comes after is irrelevant to this specific test.
scene.ucmd().arg(arg).arg("test-long-dir").succeeds().stdout_matches(&Regex::new(
let re = &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:]+ "
).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.