1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 05:57:46 +00:00

sort: open the output file at the beginning

This causes us to print an error message about an invalid output file
right at the start of the invocation, but *after*  verifying other arguments.
This commit is contained in:
Michael Debertol 2021-07-30 20:48:07 +02:00
parent c6e044927c
commit a33b6d87b5
4 changed files with 80 additions and 30 deletions

View file

@ -959,3 +959,30 @@ fn test_key_takes_one_arg() {
.succeeds()
.stdout_is_fixture("keys_open_ended.expected");
}
#[test]
fn test_verifies_out_file() {
let inputs = ["" /* no input */, "some input"];
for &input in &inputs {
new_ucmd!()
.args(&["-o", "nonexistent_dir/nonexistent_file"])
.pipe_in(input)
.fails()
.status_code(2)
.stderr_only(
#[cfg(not(windows))]
"sort: open failed: nonexistent_dir/nonexistent_file: No such file or directory",
#[cfg(windows)]
"sort: open failed: nonexistent_dir/nonexistent_file: The system cannot find the path specified.",
);
}
}
#[test]
fn test_verifies_out_file_after_keys() {
new_ucmd!()
.args(&["-o", "nonexistent_dir/nonexistent_file", "-k", "0"])
.fails()
.status_code(2)
.stderr_contains("failed to parse key");
}