mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
seq: use stdout.write_all() instead of print!()
Change from using `print!()` to using `stdout.write_all()` in order to allow the main function to handle broken pipe errors gracefully.
This commit is contained in:
parent
92a1f1422e
commit
96b8616a1a
2 changed files with 49 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::common::util::*;
|
||||
use std::io::Read;
|
||||
|
||||
#[test]
|
||||
fn test_rejects_nan() {
|
||||
|
@ -176,3 +177,26 @@ fn test_width_negative_zero() {
|
|||
.stdout_is("-0\n01\n")
|
||||
.no_stderr();
|
||||
}
|
||||
|
||||
// TODO This is duplicated from `test_yes.rs`; refactor them.
|
||||
/// Run `seq`, capture some of the output, close the pipe, and verify it.
|
||||
fn run(args: &[&str], expected: &[u8]) {
|
||||
let mut cmd = new_ucmd!();
|
||||
let mut child = cmd.args(args).run_no_wait();
|
||||
let mut stdout = child.stdout.take().unwrap();
|
||||
let mut buf = vec![0; expected.len()];
|
||||
stdout.read_exact(&mut buf).unwrap();
|
||||
drop(stdout);
|
||||
assert!(child.wait().unwrap().success());
|
||||
assert_eq!(buf.as_slice(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_neg_inf() {
|
||||
run(&["--", "-inf", "0"], b"-inf\n-inf\n-inf\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inf() {
|
||||
run(&["inf"], b"1\n2\n3\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue