From c619dbc99c35ffa55e59caea3df2d260b057e84e Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 29 Jan 2024 14:55:27 +0100 Subject: [PATCH] split: fix error msg shown if file doesn't exist --- src/uu/split/src/split.rs | 8 ++------ tests/by-util/test_split.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 8fd62c8a9af..7712e510124 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -1635,12 +1635,8 @@ fn split(settings: &Settings) -> UResult<()> { let r_box = if settings.input == "-" { Box::new(stdin()) as Box } 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 }; let mut reader = if let Some(c) = settings.io_blksize { diff --git a/tests/by-util/test_split.rs b/tests/by-util/test_split.rs index 4e98a046add..64eccf81ad8 100644 --- a/tests/by-util/test_split.rs +++ b/tests/by-util/test_split.rs @@ -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!();