Skip to content
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
51 changes: 24 additions & 27 deletions tests/by-util/test_tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ fn test_tee_no_more_writeable_2() {

#[cfg(target_os = "linux")]
mod linux_only {
use crate::common::util::{AtPath, TestScenario, UCommand};
use crate::common::util::{AtPath, CmdResult, TestScenario, UCommand};

use std::fmt::Write;
use std::fs::File;
use std::process::{Output, Stdio};
use std::process::Stdio;
use std::time::Duration;

fn make_broken_pipe() -> File {
Expand Down Expand Up @@ -200,64 +200,61 @@ mod linux_only {
unsafe { File::from_raw_fd(fds[0]) }
}

fn run_tee(proc: &mut UCommand) -> (String, Output) {
fn run_tee(proc: &mut UCommand) -> (String, CmdResult) {
let content = (1..=100_000).fold(String::new(), |mut output, x| {
let _ = writeln!(output, "{x}");
output
});

#[allow(deprecated)]
let output = proc
let result = proc
.ignore_stdin_write_error()
.set_stdin(Stdio::piped())
.run_no_wait()
.pipe_in_and_wait_with_output(content.as_bytes());
.pipe_in_and_wait(content.as_bytes());

(content, output)
(content, result)
}

fn expect_success(output: &Output) {
fn expect_success(result: &CmdResult) {
assert!(
output.status.success(),
result.succeeded(),
"Command was expected to succeed.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
assert!(
output.stderr.is_empty(),
result.stderr_str().is_empty(),
"Unexpected data on stderr.\n stderr = {}",
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
}

fn expect_failure(output: &Output, message: &str) {
fn expect_failure(result: &CmdResult, message: &str) {
assert!(
!output.status.success(),
!result.succeeded(),
"Command was expected to fail.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
assert!(
std::str::from_utf8(&output.stderr)
.unwrap()
.contains(message),
result.stderr_str().contains(message),
"Expected to see error message fragment {} in stderr, but did not.\n stderr = {}",
message,
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
}

fn expect_silent_failure(output: &Output) {
fn expect_silent_failure(result: &CmdResult) {
assert!(
!output.status.success(),
!result.succeeded(),
"Command was expected to fail.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
assert!(
output.stderr.is_empty(),
result.stderr_str().is_empty(),
"Unexpected data on stderr.\n stderr = {}",
std::str::from_utf8(&output.stderr).unwrap(),
std::str::from_utf8(result.stderr()).unwrap(),
);
}

Expand Down
9 changes: 0 additions & 9 deletions tests/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,15 +2609,6 @@ impl UChild {
self.wait().unwrap()
}

/// Convenience method for [`UChild::pipe_in`] and then [`UChild::wait_with_output`]
#[deprecated = "Please use pipe_in_and_wait() -> CmdResult instead."]
pub fn pipe_in_and_wait_with_output<T: Into<Vec<u8>>>(mut self, content: T) -> Output {
self.pipe_in(content);

#[allow(deprecated)]
self.wait_with_output().unwrap()
}

/// Write some bytes to the child process stdin.
///
/// This function is meant for small data and faking user input like typing a `yes` or `no`.
Expand Down
Loading