mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
sort: validate input files at startup
This commit is contained in:
parent
a33b6d87b5
commit
1bb530eebb
2 changed files with 26 additions and 2 deletions
|
@ -1106,6 +1106,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
);
|
||||
}
|
||||
|
||||
// Verify that we can open all input files.
|
||||
// It is the correct behavior to close all files afterwards,
|
||||
// and to reopen them at a later point. This is different from how the output file is handled,
|
||||
// probably to prevent running out of file descriptors.
|
||||
for file in &files {
|
||||
open(file);
|
||||
}
|
||||
|
||||
let output = Output::new(matches.value_of(options::OUTPUT));
|
||||
|
||||
settings.init_precomputed();
|
||||
|
|
|
@ -979,10 +979,26 @@ fn test_verifies_out_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_verifies_out_file_after_keys() {
|
||||
fn test_verifies_files_after_keys() {
|
||||
new_ucmd!()
|
||||
.args(&["-o", "nonexistent_dir/nonexistent_file", "-k", "0"])
|
||||
.args(&[
|
||||
"-o",
|
||||
"nonexistent_dir/nonexistent_file",
|
||||
"-k",
|
||||
"0",
|
||||
"nonexistent_dir/input_file",
|
||||
])
|
||||
.fails()
|
||||
.status_code(2)
|
||||
.stderr_contains("failed to parse key");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_verifies_input_files() {
|
||||
new_ucmd!()
|
||||
.args(&["/dev/random", "nonexistent_file"])
|
||||
.fails()
|
||||
.status_code(2)
|
||||
.stderr_is("sort: cannot read: nonexistent_file: No such file or directory");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue