Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use unicode_width::UnicodeWidthChar;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::format_usage;
use uucore::show;
use uucore::translate;

const TAB_WIDTH: usize = 8;
Expand Down Expand Up @@ -155,7 +156,14 @@ fn fold(
stdin_buf = stdin();
&mut stdin_buf as &mut dyn Read
} else {
file_buf = File::open(Path::new(filename)).map_err_context(|| filename.to_string())?;
// Like GNU, report the error but keep processing the remaining files.
match File::open(Path::new(filename)) {
Ok(f) => file_buf = f,
Err(e) => {
show!(e.map_err_context(|| filename.to_string()));
continue;
}
}
&mut file_buf as &mut dyn Read
});

Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,21 @@ fn test_bytewise_fold_at_read_buffer_boundary() {
.stdout_is_bytes(expected);
}

#[test]
fn test_continue_after_missing_file() {
// A nonexistent operand must not abort the run: the surrounding files are
// still folded, the error is reported on stderr, and the exit status is 1.
let ts = TestScenario::new(util_name!());
ts.fixtures.write("first.txt", "hello\n");
ts.fixtures.write("third.txt", "world\n");

ts.ucmd()
.args(&["first.txt", "absent.txt", "third.txt"])
.fails_with_code(1)
.stdout_is("hello\nworld\n")
.stderr_is("fold: absent.txt: No such file or directory\n");
}
Comment thread
sylvestre marked this conversation as resolved.

#[test]
fn test_obsolete_syntax() {
new_ucmd!()
Expand Down
Loading