Skip to content

Commit

Permalink
cut: set exit code to 1 if dir is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Jan 26, 2024
1 parent 5bd00eb commit c8cd355
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/uu/cut/src/cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, IsTerminal, Read, Write};
use std::path::Path;
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::error::{set_exit_code, FromIo, UResult, USimpleError};
use uucore::line_ending::LineEnding;

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

if path.is_dir() {
show_error!("{}: Is a directory", filename.maybe_quote());
set_exit_code(1);
continue;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ fn test_is_a_directory() {

ucmd.arg("-b1")
.arg("some")
.run()
.fails()
.code_is(1)
.stderr_is("cut: some: Is a directory\n");
}

Expand All @@ -228,7 +229,8 @@ fn test_no_such_file() {
new_ucmd!()
.arg("-b1")
.arg("some")
.run()
.fails()
.code_is(1)
.stderr_is("cut: some: No such file or directory\n");
}

Expand Down

0 comments on commit c8cd355

Please sign in to comment.