Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cut: set exit code to 1 if directory is specified #5886

Merged
merged 2 commits into from
Jan 26, 2024
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
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
11 changes: 8 additions & 3 deletions tests/by-util/test_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,25 @@ fn test_zero_terminated_only_delimited() {
}

#[test]
fn test_directory_and_no_such_file() {
fn test_is_a_directory() {
let (at, mut ucmd) = at_and_ucmd!();

at.mkdir("some");

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

#[test]
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
Loading