1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #7341 from cakebaker/tee_fix_usage_of_deprecated_function_in_tests

tee: fix usage of deprecated function in tests
This commit is contained in:
Sylvestre Ledru 2025-02-23 16:21:34 +01:00 committed by GitHub
commit 9f643838b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 36 deletions

View file

@ -160,11 +160,11 @@ fn test_tee_no_more_writeable_2() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
mod linux_only { mod linux_only {
use crate::common::util::{AtPath, TestScenario, UCommand}; use crate::common::util::{AtPath, CmdResult, TestScenario, UCommand};
use std::fmt::Write; use std::fmt::Write;
use std::fs::File; use std::fs::File;
use std::process::{Output, Stdio}; use std::process::Stdio;
use std::time::Duration; use std::time::Duration;
fn make_broken_pipe() -> File { fn make_broken_pipe() -> File {
@ -200,64 +200,61 @@ mod linux_only {
unsafe { File::from_raw_fd(fds[0]) } 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 content = (1..=100_000).fold(String::new(), |mut output, x| {
let _ = writeln!(output, "{x}"); let _ = writeln!(output, "{x}");
output output
}); });
#[allow(deprecated)] let result = proc
let output = proc
.ignore_stdin_write_error() .ignore_stdin_write_error()
.set_stdin(Stdio::piped()) .set_stdin(Stdio::piped())
.run_no_wait() .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!( assert!(
output.status.success(), result.succeeded(),
"Command was expected to succeed.\nstdout = {}\n stderr = {}", "Command was expected to succeed.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(), std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(), std::str::from_utf8(result.stderr()).unwrap(),
); );
assert!( assert!(
output.stderr.is_empty(), result.stderr_str().is_empty(),
"Unexpected data on stderr.\n stderr = {}", "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!( assert!(
!output.status.success(), !result.succeeded(),
"Command was expected to fail.\nstdout = {}\n stderr = {}", "Command was expected to fail.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(), std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(), std::str::from_utf8(result.stderr()).unwrap(),
); );
assert!( assert!(
std::str::from_utf8(&output.stderr) result.stderr_str().contains(message),
.unwrap()
.contains(message),
"Expected to see error message fragment {} in stderr, but did not.\n stderr = {}", "Expected to see error message fragment {} in stderr, but did not.\n stderr = {}",
message, 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!( assert!(
!output.status.success(), !result.succeeded(),
"Command was expected to fail.\nstdout = {}\n stderr = {}", "Command was expected to fail.\nstdout = {}\n stderr = {}",
std::str::from_utf8(&output.stdout).unwrap(), std::str::from_utf8(result.stdout()).unwrap(),
std::str::from_utf8(&output.stderr).unwrap(), std::str::from_utf8(result.stderr()).unwrap(),
); );
assert!( assert!(
output.stderr.is_empty(), result.stderr_str().is_empty(),
"Unexpected data on stderr.\n stderr = {}", "Unexpected data on stderr.\n stderr = {}",
std::str::from_utf8(&output.stderr).unwrap(), std::str::from_utf8(result.stderr()).unwrap(),
); );
} }

View file

@ -2609,15 +2609,6 @@ impl UChild {
self.wait().unwrap() 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. /// 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`. /// This function is meant for small data and faking user input like typing a `yes` or `no`.