Skip to content

Commit e580627

Browse files
authored
Merge pull request #5886 from cakebaker/cut_set_exit_code
cut: set exit code to 1 if directory is specified
2 parents 79ac89e + c8cd355 commit e580627

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/uu/cut/src/cut.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fs::File;
1111
use std::io::{stdin, stdout, BufReader, BufWriter, IsTerminal, Read, Write};
1212
use std::path::Path;
1313
use uucore::display::Quotable;
14-
use uucore::error::{FromIo, UResult, USimpleError};
14+
use uucore::error::{set_exit_code, FromIo, UResult, USimpleError};
1515
use uucore::line_ending::LineEnding;
1616

1717
use self::searcher::Searcher;
@@ -319,6 +319,7 @@ fn cut_files(mut filenames: Vec<String>, mode: &Mode) {
319319

320320
if path.is_dir() {
321321
show_error!("{}: Is a directory", filename.maybe_quote());
322+
set_exit_code(1);
322323
continue;
323324
}
324325

tests/by-util/test_cut.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,25 @@ fn test_zero_terminated_only_delimited() {
212212
}
213213

214214
#[test]
215-
fn test_directory_and_no_such_file() {
215+
fn test_is_a_directory() {
216216
let (at, mut ucmd) = at_and_ucmd!();
217217

218218
at.mkdir("some");
219219

220220
ucmd.arg("-b1")
221221
.arg("some")
222-
.run()
222+
.fails()
223+
.code_is(1)
223224
.stderr_is("cut: some: Is a directory\n");
225+
}
224226

227+
#[test]
228+
fn test_no_such_file() {
225229
new_ucmd!()
226230
.arg("-b1")
227231
.arg("some")
228-
.run()
232+
.fails()
233+
.code_is(1)
229234
.stderr_is("cut: some: No such file or directory\n");
230235
}
231236

0 commit comments

Comments
 (0)