[tests/ls] Support user names containing dots

- Fix regex's in tests for `ls -l`
This commit is contained in:
Niyaz Nigmatullin 2023-04-26 14:22:35 +03:00
parent b79465a5e7
commit 467cbf30de

View file

@ -1276,7 +1276,7 @@ fn test_ls_long_formats() {
// Zero or one "." for indicating a file with security context // Zero or one "." for indicating a file with security context
// Regex for three names, so all of author, group and owner // Regex for three names, so all of author, group and owner
let re_three = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z_A-Z]+ ){3}0").unwrap(); let re_three = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z.A-Z]+ ){3}0").unwrap();
#[cfg(unix)] #[cfg(unix)]
let re_three_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){3}0").unwrap(); let re_three_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){3}0").unwrap();
@ -1285,13 +1285,13 @@ fn test_ls_long_formats() {
// - group and owner // - group and owner
// - author and owner // - author and owner
// - author and group // - author and group
let re_two = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z_A-Z]+ ){2}0").unwrap(); let re_two = Regex::new(r"[xrw-]{9}\.? \d ([-0-9_a-z.A-Z]+ ){2}0").unwrap();
#[cfg(unix)] #[cfg(unix)]
let re_two_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){2}0").unwrap(); let re_two_num = Regex::new(r"[xrw-]{9}\.? \d (\d+ ){2}0").unwrap();
// Regex for one name: author, group or owner // Regex for one name: author, group or owner
let re_one = Regex::new(r"[xrw-]{9}\.? \d [-0-9_a-z_A-Z]+ 0").unwrap(); let re_one = Regex::new(r"[xrw-]{9}\.? \d [-0-9_a-z.A-Z]+ 0").unwrap();
#[cfg(unix)] #[cfg(unix)]
let re_one_num = Regex::new(r"[xrw-]{9}\.? \d \d+ 0").unwrap(); let re_one_num = Regex::new(r"[xrw-]{9}\.? \d \d+ 0").unwrap();
@ -1640,88 +1640,103 @@ fn test_ls_styles() {
at.touch("test"); at.touch("test");
let re_full = Regex::new( let re_full = Regex::new(
r"[a-z-]* \d* \w* \w* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d* (\+|\-)\d{4} test\n", r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d* (\+|\-)\d{4} test\n",
) )
.unwrap(); .unwrap();
let re_long = let re_long =
Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2} test\n").unwrap(); Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}-\d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
let re_iso = Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{2}-\d{2} \d{2}:\d{2} test\n").unwrap(); let re_iso =
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{2}-\d{2} \d{2}:\d{2} test\n").unwrap();
let re_locale = let re_locale =
Regex::new(r"[a-z-]* \d* \w* \w* \d* [A-Z][a-z]{2} ( |\d)\d \d{2}:\d{2} test\n").unwrap(); Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* [A-Z][a-z]{2} ( |\d)\d \d{2}:\d{2} test\n")
let re_custom_format = Regex::new(r"[a-z-]* \d* \w* \w* \d* \d{4}__\d{2} test\n").unwrap(); .unwrap();
let re_custom_format =
Regex::new(r"[a-z-]* \d* [\w.]* [\w.]* \d* \d{4}__\d{2} test\n").unwrap();
//full-iso //full-iso
let result = scene scene
.ucmd() .ucmd()
.arg("-l") .arg("-l")
.arg("--time-style=full-iso") .arg("--time-style=full-iso")
.succeeds(); .succeeds()
assert!(re_full.is_match(result.stdout_str())); .stdout_matches(&re_full);
//long-iso //long-iso
let result = scene scene
.ucmd() .ucmd()
.arg("-l") .arg("-l")
.arg("--time-style=long-iso") .arg("--time-style=long-iso")
.succeeds(); .succeeds()
assert!(re_long.is_match(result.stdout_str())); .stdout_matches(&re_long);
//iso //iso
let result = scene.ucmd().arg("-l").arg("--time-style=iso").succeeds(); scene
assert!(re_iso.is_match(result.stdout_str())); .ucmd()
.arg("-l")
.arg("--time-style=iso")
.succeeds()
.stdout_matches(&re_iso);
//locale //locale
let result = scene.ucmd().arg("-l").arg("--time-style=locale").succeeds(); scene
assert!(re_locale.is_match(result.stdout_str())); .ucmd()
.arg("-l")
.arg("--time-style=locale")
.succeeds()
.stdout_matches(&re_locale);
//+FORMAT //+FORMAT
let result = scene scene
.ucmd() .ucmd()
.arg("-l") .arg("-l")
.arg("--time-style=+%Y__%M") .arg("--time-style=+%Y__%M")
.succeeds(); .succeeds()
assert!(re_custom_format.is_match(result.stdout_str())); .stdout_matches(&re_custom_format);
// Also fails due to not having full clap support for time_styles // Also fails due to not having full clap support for time_styles
scene.ucmd().arg("-l").arg("-time-style=invalid").fails(); scene.ucmd().arg("-l").arg("-time-style=invalid").fails();
//Overwrite options tests //Overwrite options tests
let result = scene scene
.ucmd() .ucmd()
.arg("-l") .arg("-l")
.arg("--time-style=long-iso") .arg("--time-style=long-iso")
.arg("--time-style=iso") .arg("--time-style=iso")
.succeeds(); .succeeds()
assert!(re_iso.is_match(result.stdout_str())); .stdout_matches(&re_iso);
let result = scene scene
.ucmd() .ucmd()
.arg("--time-style=iso") .arg("--time-style=iso")
.arg("--full-time") .arg("--full-time")
.succeeds(); .succeeds()
assert!(re_full.is_match(result.stdout_str())); .stdout_matches(&re_full);
let result = scene scene
.ucmd() .ucmd()
.arg("--full-time") .arg("--full-time")
.arg("--time-style=iso") .arg("--time-style=iso")
.succeeds(); .succeeds()
assert!(re_iso.is_match(result.stdout_str())); .stdout_matches(&re_iso);
let result = scene scene
.ucmd() .ucmd()
.arg("--full-time") .arg("--full-time")
.arg("--time-style=iso") .arg("--time-style=iso")
.arg("--full-time") .arg("--full-time")
.succeeds(); .succeeds()
assert!(re_full.is_match(result.stdout_str())); .stdout_matches(&re_full);
let result = scene scene
.ucmd() .ucmd()
.arg("--full-time") .arg("--full-time")
.arg("-x") .arg("-x")
.arg("-l") .arg("-l")
.succeeds(); .succeeds()
assert!(re_full.is_match(result.stdout_str())); .stdout_matches(&re_full);
at.touch("test2"); at.touch("test2");
let result = scene.ucmd().arg("--full-time").arg("-x").succeeds(); scene
assert_eq!(result.stdout_str(), "test test2\n"); .ucmd()
.arg("--full-time")
.arg("-x")
.succeeds()
.stdout_is("test test2\n");
} }
#[test] #[test]