Skip to content

Commit

Permalink
fix(test): Remove with_stdout/with_stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 24, 2024
1 parent 61b8903 commit 7ab9320
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! # Deprecated comparisons
//!
//! Cargo's tests are in transition from internal-only pattern and normalization routines used in
//! asserts like [`crate::Execs::with_stdout`] to [`assert_e2e`] and [`assert_ui`].
//! asserts like [`crate::Execs::with_stdout_contains`] to [`assert_e2e`] and [`assert_ui`].
//!
//! ## Patterns
//!
Expand Down
31 changes: 2 additions & 29 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,10 @@ impl Project {
/// # Example:
///
/// ```no_run
/// # use cargo_test_support::str;
/// # let p = cargo_test_support::project().build();
/// p.process(&p.bin("foo"))
/// .with_stdout("bar\n")
/// .with_stdout_data(str!["bar\n"])
/// .run();
/// ```
pub fn process<T: AsRef<OsStr>>(&self, program: T) -> Execs {
Expand Down Expand Up @@ -644,9 +645,7 @@ struct RawOutput {
pub struct Execs {
ran: bool,
process_builder: Option<ProcessBuilder>,
expect_stdout: Option<String>,
expect_stdin: Option<String>,
expect_stderr: Option<String>,
expect_exit_code: Option<i32>,
expect_stdout_data: Option<snapbox::Data>,
expect_stderr_data: Option<snapbox::Data>,
Expand All @@ -673,22 +672,6 @@ impl Execs {

/// # Configure assertions
impl Execs {
/// Verifies that stdout is equal to the given lines.
/// See [`compare`] for supported patterns.
#[deprecated(note = "replaced with `Execs::with_stdout_data(expected)`")]
pub fn with_stdout<S: ToString>(&mut self, expected: S) -> &mut Self {
self.expect_stdout = Some(expected.to_string());
self
}

/// Verifies that stderr is equal to the given lines.
/// See [`compare`] for supported patterns.
#[deprecated(note = "replaced with `Execs::with_stderr_data(expected)`")]
pub fn with_stderr<S: ToString>(&mut self, expected: S) -> &mut Self {
self.expect_stderr = Some(expected.to_string());
self
}

/// Verifies that stdout is equal to the given lines.
///
/// See [`compare::assert_e2e`] for assertion details.
Expand Down Expand Up @@ -1058,9 +1041,7 @@ impl Execs {
#[track_caller]
fn verify_checks_output(&self, stdout: &[u8], stderr: &[u8]) {
if self.expect_exit_code.unwrap_or(0) != 0
&& self.expect_stdout.is_none()
&& self.expect_stdin.is_none()
&& self.expect_stderr.is_none()
&& self.expect_stdout_data.is_none()
&& self.expect_stderr_data.is_none()
&& self.expect_stdout_contains.is_empty()
Expand Down Expand Up @@ -1154,12 +1135,6 @@ impl Execs {
),
}

if let Some(expect_stdout) = &self.expect_stdout {
compare::match_exact(expect_stdout, stdout, "stdout", stderr, cwd)?;
}
if let Some(expect_stderr) = &self.expect_stderr {
compare::match_exact(expect_stderr, stderr, "stderr", stdout, cwd)?;
}
if let Some(expect_stdout_data) = &self.expect_stdout_data {
if let Err(err) = self.assert.try_eq(
Some(&"stdout"),
Expand Down Expand Up @@ -1227,8 +1202,6 @@ pub fn execs() -> Execs {
Execs {
ran: false,
process_builder: None,
expect_stdout: None,
expect_stderr: None,
expect_stdin: None,
expect_exit_code: Some(0),
expect_stdout_data: None,
Expand Down
3 changes: 2 additions & 1 deletion crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! ```no_run
//! use cargo_test_support::registry::Package;
//! use cargo_test_support::project;
//! use cargo_test_support::str;
//!
//! // Publish package "a" depending on "b".
//! Package::new("a", "1.0.0")
Expand Down Expand Up @@ -38,7 +39,7 @@
//! "#)
//! .build();
//!
//! p.cargo("run").with_stdout("24").run();
//! p.cargo("run").with_stdout_data(str!["24"]).run();
//! ```

use crate::git::repo;
Expand Down

0 comments on commit 7ab9320

Please sign in to comment.