Merge pull request #5909 from cakebaker/split_fix_error_message_if_file_doesnt_exist

split: fix error message shown if file doesn't exist
This commit is contained in:
Sylvestre Ledru 2024-03-13 17:41:56 +01:00 committed by GitHub
commit 62a3fb8d3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View file

@ -1635,12 +1635,8 @@ fn split(settings: &Settings) -> UResult<()> {
let r_box = if settings.input == "-" {
Box::new(stdin()) as Box<dyn Read>
} else {
let r = File::open(Path::new(&settings.input)).map_err_context(|| {
format!(
"cannot open {} for reading: No such file or directory",
settings.input.quote()
)
})?;
let r = File::open(Path::new(&settings.input))
.map_err_context(|| format!("cannot open {} for reading", settings.input.quote()))?;
Box::new(r) as Box<dyn Read>
};
let mut reader = if let Some(c) = settings.io_blksize {

View file

@ -123,6 +123,15 @@ fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}
#[test]
fn test_split_non_existing_file() {
new_ucmd!()
.arg("non-existing")
.fails()
.code_is(1)
.stderr_is("split: cannot open 'non-existing' for reading: No such file or directory\n");
}
#[test]
fn test_split_default() {
let (at, mut ucmd) = at_and_ucmd!();