mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
tests/ls: Add tests to ensure env var is used as a last resort
This commit is contained in:
parent
6760d63539
commit
c58575edaa
1 changed files with 65 additions and 0 deletions
|
@ -2622,6 +2622,71 @@ fn test_ls_quoting_style() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ls_quoting_style_env_var_default() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
at.touch(at.plus_as_string("foo-1"));
|
||||||
|
at.touch(at.plus_as_string("bar-2"));
|
||||||
|
|
||||||
|
// If no quoting style argument is provided, the QUOTING_STYLE environment variable
|
||||||
|
// shall be used.
|
||||||
|
|
||||||
|
let correct_c = "\"bar-2\"\n\"foo-1\"";
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.env("QUOTING_STYLE", "c")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(format!("{correct_c}\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ls_quoting_style_arg_overrides_env_var() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
at.touch(at.plus_as_string("foo-1"));
|
||||||
|
at.touch(at.plus_as_string("bar-2"));
|
||||||
|
|
||||||
|
// The quoting style given by the env variable should be
|
||||||
|
// overriden by any escape style provided by argument.
|
||||||
|
for (arg, correct) in [
|
||||||
|
("--quoting-style=literal", "foo-1"),
|
||||||
|
("-N", "foo-1"),
|
||||||
|
("--quoting-style=escape", "foo-1"),
|
||||||
|
("-b", "foo-1"),
|
||||||
|
("--quoting-style=shell-escape", "foo-1"),
|
||||||
|
("--quoting-style=shell-escape-always", "'foo-1'"),
|
||||||
|
("--quoting-style=shell", "foo-1"),
|
||||||
|
("--quoting-style=shell-always", "'foo-1'"),
|
||||||
|
] {
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.env("QUOTING_STYLE", "c")
|
||||||
|
.arg("--hide-control-chars")
|
||||||
|
.arg(arg)
|
||||||
|
.arg("foo-1")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(format!("{correct}\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another loop to check for the C quoting style that is used as a default above.
|
||||||
|
for (arg, correct) in [
|
||||||
|
("--quoting-style=c", "\"foo-1\""),
|
||||||
|
("-Q", "\"foo-1\""),
|
||||||
|
("--quote-name", "\"foo-1\""),
|
||||||
|
] {
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.env("QUOTING_STYLE", "literal")
|
||||||
|
.arg("--hide-control-chars")
|
||||||
|
.arg(arg)
|
||||||
|
.arg("foo-1")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_only(format!("{correct}\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_quoting_and_color() {
|
fn test_ls_quoting_and_color() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue