mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests/ls: add tests for colors
This commit is contained in:
parent
fd957dd148
commit
c5792a4c47
1 changed files with 44 additions and 7 deletions
|
@ -374,19 +374,56 @@ fn test_ls_recursive() {
|
||||||
assert!(result.stdout.contains("a\\b:\nb"));
|
assert!(result.stdout.contains("a\\b:\nb"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_ls_color() {
|
fn test_ls_ls_color() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
at.mkdir("a");
|
at.mkdir("a");
|
||||||
|
at.mkdir("a/nested_dir");
|
||||||
at.mkdir("z");
|
at.mkdir("z");
|
||||||
at.touch(&at.plus_as_string("a/a"));
|
at.touch(&at.plus_as_string("a/nested_file"));
|
||||||
scene.ucmd().arg("--color").succeeds();
|
at.touch("test-color");
|
||||||
scene.ucmd().arg("--color=always").succeeds();
|
|
||||||
scene.ucmd().arg("--color=never").succeeds();
|
let a_with_colors = "\x1b[01;34ma\x1b[0m";
|
||||||
scene.ucmd().arg("--color").arg("a").succeeds();
|
let z_with_colors = "\x1b[01;34mz\x1b[0m";
|
||||||
scene.ucmd().arg("--color=always").arg("a/a").succeeds();
|
let nested_dir_with_colors = "\x1b[01;34mnested_dir\x1b[0m";
|
||||||
scene.ucmd().arg("--color=never").arg("z").succeeds();
|
|
||||||
|
// Color is disabled by default
|
||||||
|
let result = scene.ucmd().succeeds();
|
||||||
|
assert!(!result.stdout.contains(a_with_colors));
|
||||||
|
assert!(!result.stdout.contains(z_with_colors));
|
||||||
|
|
||||||
|
// Color should be enabled
|
||||||
|
let result = scene.ucmd().arg("--color").succeeds();
|
||||||
|
assert!(result.stdout.contains(a_with_colors));
|
||||||
|
assert!(result.stdout.contains(z_with_colors));
|
||||||
|
|
||||||
|
// Color should be enabled
|
||||||
|
let result = scene.ucmd().arg("--color=always").succeeds();
|
||||||
|
assert!(result.stdout.contains(a_with_colors));
|
||||||
|
assert!(result.stdout.contains(z_with_colors));
|
||||||
|
|
||||||
|
// Color should be disabled
|
||||||
|
let result = scene.ucmd().arg("--color=never").succeeds();
|
||||||
|
assert!(!result.stdout.contains(a_with_colors));
|
||||||
|
assert!(!result.stdout.contains(z_with_colors));
|
||||||
|
|
||||||
|
// Nested dir should be shown and colored
|
||||||
|
let result = scene.ucmd().arg("--color").arg("a").succeeds();
|
||||||
|
assert!(result.stdout.contains(nested_dir_with_colors));
|
||||||
|
|
||||||
|
// Color has no effect
|
||||||
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--color=always")
|
||||||
|
.arg("a/nested_file")
|
||||||
|
.succeeds();
|
||||||
|
assert!(result.stdout.contains("a/nested_file\n"));
|
||||||
|
|
||||||
|
// No output
|
||||||
|
let result = scene.ucmd().arg("--color=never").arg("z").succeeds();
|
||||||
|
assert_eq!(result.stdout, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))] // Truncate not available on mac or win
|
#[cfg(not(any(target_os = "macos", target_os = "windows")))] // Truncate not available on mac or win
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue