mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
tests: Move seq/yes run function to Ucommand::run_stdout_starts_with
Tests for both `seq` and `yes` run a command that never terminates, and check the beggining of their output in stdout, move the copied parts of the wrapper function to common/util. We still need to use slightly different logic to parse exit value as `seq` returns success if stdout gets closed, while `yes` fails.
This commit is contained in:
parent
b540e18dec
commit
59cd6e5e41
3 changed files with 40 additions and 33 deletions
|
@ -3,7 +3,7 @@
|
|||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
use std::ffi::OsStr;
|
||||
use std::process::{ExitStatus, Stdio};
|
||||
use std::process::ExitStatus;
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
@ -22,15 +22,10 @@ fn check_termination(result: ExitStatus) {
|
|||
|
||||
const NO_ARGS: &[&str] = &[];
|
||||
|
||||
/// Run `yes`, capture some of the output, close the pipe, and verify it.
|
||||
/// Run `yes`, capture some of the output, then check exit status.
|
||||
fn run(args: &[impl AsRef<OsStr>], expected: &[u8]) {
|
||||
let mut cmd = new_ucmd!();
|
||||
let mut child = cmd.args(args).set_stdout(Stdio::piped()).run_no_wait();
|
||||
let buf = child.stdout_exact_bytes(expected.len());
|
||||
child.close_stdout();
|
||||
|
||||
check_termination(child.wait().unwrap().exit_status());
|
||||
assert_eq!(buf.as_slice(), expected);
|
||||
let result = new_ucmd!().args(args).run_stdout_starts_with(expected);
|
||||
check_termination(result.exit_status());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue