Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add with_stdout_unordered. #12635

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
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