From 0adb9f1b2ad99af0103a293e053232a86643d20d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 6 Sep 2023 19:27:39 -0700 Subject: [PATCH] Add with_stdout_unordered. This adds Execs::with_stdout_unordered to check stdout ignoring the order of lines. --- crates/cargo-test-support/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 57dca45ce03..353f923101c 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -570,6 +570,7 @@ pub struct Execs { expect_stdout_contains_n: Vec<(String, usize)>, expect_stdout_not_contains: Vec, expect_stderr_not_contains: Vec, + expect_stdout_unordered: Vec, expect_stderr_unordered: Vec, expect_stderr_with_without: Vec<(Vec, Vec)>, expect_json: Option, @@ -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(&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. /// @@ -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() @@ -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)?; } @@ -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,