Skip to content

Commit

Permalink
Add with_stdout_unordered.
Browse files Browse the repository at this point in the history
This adds Execs::with_stdout_unordered to check stdout ignoring the
order of lines.
  • Loading branch information
ehuss committed Sep 7, 2023
1 parent 016fe19 commit 0adb9f1
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 0adb9f1

Please sign in to comment.