Skip to content

Commit

Permalink
Auto merge of #12635 - ehuss:with-stdout-unordered, r=weihanglo
Browse files Browse the repository at this point in the history
Add with_stdout_unordered.

This adds the `with_stdout_unordered` method to cargo's test system so that tests can use it to check stdout but ignoring the order of lines. Nothing in this PR actually uses this method, but it is added to support #12634. I also expect it could potentially be useful in other cases in the future.
  • Loading branch information
bors committed Sep 7, 2023
2 parents 36ee8ce + 0adb9f1 commit 282424e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ pub struct Execs {
expect_stdout_contains_n: Vec<(String, usize)>,
expect_stdout_not_contains: Vec<String>,
expect_stderr_not_contains: Vec<String>,
expect_stdout_unordered: Vec<String>,
expect_stderr_unordered: Vec<String>,
expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
expect_json: Option<String>,
Expand Down Expand Up @@ -671,6 +672,15 @@ impl Execs {
self
}

/// Verifies that all of the stdout output is equal to the given lines,
/// ignoring the order of the lines.
///
/// See [`Execs::with_stderr_unordered`] for more details.
pub fn with_stdout_unordered<S: ToString>(&mut self, expected: S) -> &mut Self {
self.expect_stdout_unordered.push(expected.to_string());
self
}

/// Verifies that all of the stderr output is equal to the given lines,
/// ignoring the order of the lines.
///
Expand Down Expand Up @@ -932,6 +942,7 @@ impl Execs {
&& self.expect_stdout_contains_n.is_empty()
&& self.expect_stdout_not_contains.is_empty()
&& self.expect_stderr_not_contains.is_empty()
&& self.expect_stdout_unordered.is_empty()
&& self.expect_stderr_unordered.is_empty()
&& self.expect_stderr_with_without.is_empty()
&& self.expect_json.is_none()
Expand Down Expand Up @@ -1036,6 +1047,9 @@ impl Execs {
for expect in self.expect_stderr_not_contains.iter() {
compare::match_does_not_contain(expect, stderr, cwd)?;
}
for expect in self.expect_stdout_unordered.iter() {
compare::match_unordered(expect, stdout, cwd)?;
}
for expect in self.expect_stderr_unordered.iter() {
compare::match_unordered(expect, stderr, cwd)?;
}
Expand Down Expand Up @@ -1075,6 +1089,7 @@ pub fn execs() -> Execs {
expect_stdout_contains_n: Vec::new(),
expect_stdout_not_contains: Vec::new(),
expect_stderr_not_contains: Vec::new(),
expect_stdout_unordered: Vec::new(),
expect_stderr_unordered: Vec::new(),
expect_stderr_with_without: Vec::new(),
expect_json: None,
Expand Down

0 comments on commit 282424e

Please sign in to comment.