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

ls: compute correct exit code on error

Note in particular that this seems to be the only tool where invalid
stringly-enum values cause a different exit code than invalid arguments.
This commit is contained in:
Ben Wiederhake 2024-03-31 21:15:37 +02:00
parent 8f791da213
commit 4a1bd78f48
2 changed files with 71 additions and 2 deletions

View file

@ -44,11 +44,64 @@ const COMMA_ARGS: &[&str] = &["-m", "--format=commas", "--for=commas"];
const COLUMN_ARGS: &[&str] = &["-C", "--format=columns", "--for=columns"];
#[test]
fn test_invalid_flag() {
new_ucmd!()
.arg("--invalid-argument")
.fails()
.no_stdout()
.code_is(2);
}
#[test]
fn test_invalid_value_returns_1() {
// Invalid values to flags *sometimes* result in error code 1:
for flag in [
"--classify",
"--color",
"--format",
"--hyperlink",
"--indicator-style",
"--quoting-style",
"--sort",
"--time",
] {
new_ucmd!()
.arg(&format!("{flag}=definitely_invalid_value"))
.fails()
.no_stdout()
.code_is(1);
}
}
#[test]
fn test_invalid_value_returns_2() {
// Invalid values to flags *sometimes* result in error code 2:
for flag in ["--block-size", "--width", "--tab-size"] {
new_ucmd!()
.arg(&format!("{flag}=definitely_invalid_value"))
.fails()
.no_stdout()
.code_is(2);
}
}
#[test]
fn test_ls_ls() {
new_ucmd!().succeeds();
}
#[test]
fn test_ls_help() {
// Because we have to work around a lot of clap's error handling and
// modify the exit-code, this is actually non-trivial.
new_ucmd!()
.arg("--help")
.succeeds()
.stdout_contains("--version")
.no_stderr();
}
#[test]
fn test_ls_i() {
new_ucmd!().arg("-i").succeeds();