diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2024-03-31 21:15:37 +0200 |
---|---|---|
committer | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2024-04-01 22:57:18 +0200 |
commit | 4a1bd78f482f31b183d07ff4d91cfbcd95ebd5cd (patch) | |
tree | fac68ee6c8409217b6352f2527f269f206788783 /tests/by-util/test_ls.rs | |
parent | 8f791da213f826d130369a74466ae14199cf6efe (diff) |
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.
Diffstat (limited to 'tests/by-util/test_ls.rs')
-rw-r--r-- | tests/by-util/test_ls.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 3f0154f7a..efe9e1056 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -45,11 +45,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(); new_ucmd!().arg("-il").succeeds(); |