mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
tsort: returns error when input is dir - same as GNU tsort (#5860)
* fix: return error when input is dir * test: when tsort is given a dir * fix: do not need to mention tsort in error message * test: using concrete directory name * tsort: fix formatting in test --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
63ef7e4fdf
commit
746a7b14d0
2 changed files with 17 additions and 1 deletions
|
@ -32,7 +32,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
stdin_buf = stdin();
|
stdin_buf = stdin();
|
||||||
&mut stdin_buf as &mut dyn Read
|
&mut stdin_buf as &mut dyn Read
|
||||||
} else {
|
} else {
|
||||||
file_buf = File::open(Path::new(&input)).map_err_context(|| input.to_string())?;
|
let path = Path::new(&input);
|
||||||
|
if path.is_dir() {
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
1,
|
||||||
|
format!("{}: read error: Is a directory", input),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
file_buf = File::open(path).map_err_context(|| input.to_string())?;
|
||||||
&mut file_buf as &mut dyn Read
|
&mut file_buf as &mut dyn Read
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -64,3 +64,12 @@ fn test_multiple_arguments() {
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("unexpected argument 'invalid_file' found");
|
.stderr_contains("unexpected argument 'invalid_file' found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_error_on_dir() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.mkdir("tsort_test_dir");
|
||||||
|
ucmd.arg("tsort_test_dir")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("tsort: tsort_test_dir: read error: Is a directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue