Skip to content

Commit 62a3fb8

Browse files
authored
Merge pull request #5909 from cakebaker/split_fix_error_message_if_file_doesnt_exist
split: fix error message shown if file doesn't exist
2 parents 65fb81b + c619dbc commit 62a3fb8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/uu/split/src/split.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1635,12 +1635,8 @@ fn split(settings: &Settings) -> UResult<()> {
16351635
let r_box = if settings.input == "-" {
16361636
Box::new(stdin()) as Box<dyn Read>
16371637
} else {
1638-
let r = File::open(Path::new(&settings.input)).map_err_context(|| {
1639-
format!(
1640-
"cannot open {} for reading: No such file or directory",
1641-
settings.input.quote()
1642-
)
1643-
})?;
1638+
let r = File::open(Path::new(&settings.input))
1639+
.map_err_context(|| format!("cannot open {} for reading", settings.input.quote()))?;
16441640
Box::new(r) as Box<dyn Read>
16451641
};
16461642
let mut reader = if let Some(c) = settings.io_blksize {

tests/by-util/test_split.rs

+9
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ fn test_invalid_arg() {
123123
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
124124
}
125125

126+
#[test]
127+
fn test_split_non_existing_file() {
128+
new_ucmd!()
129+
.arg("non-existing")
130+
.fails()
131+
.code_is(1)
132+
.stderr_is("split: cannot open 'non-existing' for reading: No such file or directory\n");
133+
}
134+
126135
#[test]
127136
fn test_split_default() {
128137
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)