Skip to content
Closed
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
6 changes: 0 additions & 6 deletions src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

match result {
Ok(()) => Ok(()),
Err(err) if err.kind() == std::io::ErrorKind::BrokenPipe => {
// GNU seq prints the Broken pipe message but still exits with status 0
let err = err.map_err_context(|| "write error".into());
uucore::show_error!("{err}");
Ok(())
}
Err(err) => Err(err.map_err_context(|| "write error".into())),
}
}
Expand Down
27 changes: 15 additions & 12 deletions tests/by-util/test_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore lmnop xlmnop
// spell-checker:ignore lmnop xlmnop EPIPE
use uutests::new_ucmd;

#[test]
Expand All @@ -12,7 +12,7 @@ fn test_invalid_arg() {

#[test]
#[cfg(unix)]
fn test_broken_pipe_still_exits_success() {
fn test_broken_pipe_exits_with_error() {
use std::process::Stdio;

let mut child = new_ucmd!()
Expand All @@ -26,8 +26,9 @@ fn test_broken_pipe_still_exits_success() {
child.close_stdout();
let result = child.wait().unwrap();

// GNU seq exits with code 1 on write error (when SIGPIPE is ignored/handled)
result
.code_is(0)
.code_is(1)
.stderr_contains("write error: Broken pipe");
}

Expand Down Expand Up @@ -653,47 +654,48 @@ fn test_neg_inf() {
new_ucmd!()
.args(&["--", "-inf", "0"])
.run_stdout_starts_with(b"-inf\n-inf\n-inf\n")
.success();
.code_is(1);
}

#[test]
fn test_neg_infinity() {
new_ucmd!()
.args(&["--", "-infinity", "0"])
.run_stdout_starts_with(b"-inf\n-inf\n-inf\n")
.success();
.code_is(1);
}

#[test]
fn test_inf() {
// Note: run_stdout_starts_with closes stdout early, causing EPIPE and exit code 1
new_ucmd!()
.args(&["inf"])
.run_stdout_starts_with(b"1\n2\n3\n")
.success();
.code_is(1);
}

#[test]
fn test_infinity() {
new_ucmd!()
.args(&["infinity"])
.run_stdout_starts_with(b"1\n2\n3\n")
.success();
.code_is(1);
}

#[test]
fn test_inf_width() {
new_ucmd!()
.args(&["-w", "1.000", "inf", "inf"])
.run_stdout_starts_with(b"1.000\n inf\n inf\n inf\n")
.success();
.code_is(1);
}

#[test]
fn test_neg_inf_width() {
new_ucmd!()
.args(&["-w", "1.000", "-inf", "-inf"])
.run_stdout_starts_with(b"1.000\n -inf\n -inf\n -inf\n")
.success();
.code_is(1);
}

#[test]
Expand Down Expand Up @@ -1074,11 +1076,11 @@ fn test_precision_corner_cases() {
.succeeds()
.stdout_is("1.00\n2.20\n");

// Infinity is ignored
// Infinity is ignored (exits with code 1 due to EPIPE when stdout closes)
new_ucmd!()
.args(&["1", "1.2", "inf"])
.run_stdout_starts_with(b"1.0\n2.2\n3.4\n")
.success();
.code_is(1);
}

// GNU `seq` manual only makes guarantees about `-w` working if the
Expand Down Expand Up @@ -1138,8 +1140,9 @@ fn test_equalize_widths_corner_cases() {

// We can't really pad with infinite number of zeros, so `-w` is ignored.
// (there is another test with infinity as an increment above)
// Exits with code 1 due to EPIPE when stdout closes.
new_ucmd!()
.args(&["-w", "1", "1.2", "inf"])
.run_stdout_starts_with(b"1.0\n2.2\n3.4\n")
.success();
.code_is(1);
}
Loading