Skip to content

Commit af739fa

Browse files
committed
split: fix error msg shown if file doesn't exist
1 parent c439f81 commit af739fa

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
@@ -1626,12 +1626,8 @@ fn split(settings: &Settings) -> UResult<()> {
16261626
let r_box = if settings.input == "-" {
16271627
Box::new(stdin()) as Box<dyn Read>
16281628
} else {
1629-
let r = File::open(Path::new(&settings.input)).map_err_context(|| {
1630-
format!(
1631-
"cannot open {} for reading: No such file or directory",
1632-
settings.input.quote()
1633-
)
1634-
})?;
1629+
let r = File::open(Path::new(&settings.input))
1630+
.map_err_context(|| format!("cannot open {} for reading", settings.input.quote()))?;
16351631
Box::new(r) as Box<dyn Read>
16361632
};
16371633
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)