From c8cd35570830c9d8fb583fa7cdb0d2090b8d673e Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 26 Jan 2024 10:18:44 +0100 Subject: [PATCH] cut: set exit code to 1 if dir is specified --- src/uu/cut/src/cut.rs | 3 ++- tests/by-util/test_cut.rs | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 2a3196d002e..f3f87beef79 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -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; @@ -319,6 +319,7 @@ fn cut_files(mut filenames: Vec, mode: &Mode) { if path.is_dir() { show_error!("{}: Is a directory", filename.maybe_quote()); + set_exit_code(1); continue; } diff --git a/tests/by-util/test_cut.rs b/tests/by-util/test_cut.rs index cdda057ad9d..bfa0885cee9 100644 --- a/tests/by-util/test_cut.rs +++ b/tests/by-util/test_cut.rs @@ -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"); } @@ -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"); }