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

ls: Fix device display (#2855)

This commit is contained in:
kimono-koans 2022-01-14 17:39:56 -06:00 committed by GitHub
parent 3cc1fb593a
commit fd5310411e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 160 additions and 23 deletions

View file

@ -56,8 +56,70 @@ fn test_ls_ordering() {
.stdout_matches(&Regex::new("some-dir1:\\ntotal 0").unwrap());
}
//#[cfg(all(feature = "mknod"))]
#[test]
fn test_ls_devices() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.mkdir("some-dir1");
// Regex tests correct device ID and correct (no pad) spacing for a single file
#[cfg(any(target_os = "macos", target_os = "ios"))]
{
scene
.ucmd()
.arg("-al")
.arg("/dev/null")
.succeeds()
.stdout_matches(&Regex::new("[^ ] 3, 2 [^ ]").unwrap());
}
#[cfg(target_os = "linux")]
{
scene
.ucmd()
.arg("-al")
.arg("/dev/null")
.succeeds()
.stdout_matches(&Regex::new("[^ ] 1, 3 [^ ]").unwrap());
}
// Regex tests alignment against a file (stdout is a link to a tty)
#[cfg(unix)]
{
let res = scene
.ucmd()
.arg("-alL")
.arg("/dev/null")
.arg("/dev/stdout")
.succeeds();
let null_len = String::from_utf8(res.stdout().to_owned())
.ok()
.unwrap()
.lines()
.next()
.unwrap()
.strip_suffix("/dev/null")
.unwrap()
.len();
let stdout_len = String::from_utf8(res.stdout().to_owned())
.ok()
.unwrap()
.lines()
.nth(1)
.unwrap()
.strip_suffix("/dev/stdout")
.unwrap()
.len();
assert_eq!(stdout_len, null_len);
}
}
#[cfg(all(feature = "chmod"))]
#[test]
#[cfg(feature = "chmod")]
fn test_ls_io_errors() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;