Skip to content

Commit 282424e

Browse files
committed
Auto merge of #12635 - ehuss:with-stdout-unordered, r=weihanglo
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.
2 parents 36ee8ce + 0adb9f1 commit 282424e

File tree

1 file changed

+15
-0
lines changed
  • crates/cargo-test-support/src

1 file changed

+15
-0
lines changed

crates/cargo-test-support/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ pub struct Execs {
570570
expect_stdout_contains_n: Vec<(String, usize)>,
571571
expect_stdout_not_contains: Vec<String>,
572572
expect_stderr_not_contains: Vec<String>,
573+
expect_stdout_unordered: Vec<String>,
573574
expect_stderr_unordered: Vec<String>,
574575
expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
575576
expect_json: Option<String>,
@@ -671,6 +672,15 @@ impl Execs {
671672
self
672673
}
673674

675+
/// Verifies that all of the stdout output is equal to the given lines,
676+
/// ignoring the order of the lines.
677+
///
678+
/// See [`Execs::with_stderr_unordered`] for more details.
679+
pub fn with_stdout_unordered<S: ToString>(&mut self, expected: S) -> &mut Self {
680+
self.expect_stdout_unordered.push(expected.to_string());
681+
self
682+
}
683+
674684
/// Verifies that all of the stderr output is equal to the given lines,
675685
/// ignoring the order of the lines.
676686
///
@@ -932,6 +942,7 @@ impl Execs {
932942
&& self.expect_stdout_contains_n.is_empty()
933943
&& self.expect_stdout_not_contains.is_empty()
934944
&& self.expect_stderr_not_contains.is_empty()
945+
&& self.expect_stdout_unordered.is_empty()
935946
&& self.expect_stderr_unordered.is_empty()
936947
&& self.expect_stderr_with_without.is_empty()
937948
&& self.expect_json.is_none()
@@ -1036,6 +1047,9 @@ impl Execs {
10361047
for expect in self.expect_stderr_not_contains.iter() {
10371048
compare::match_does_not_contain(expect, stderr, cwd)?;
10381049
}
1050+
for expect in self.expect_stdout_unordered.iter() {
1051+
compare::match_unordered(expect, stdout, cwd)?;
1052+
}
10391053
for expect in self.expect_stderr_unordered.iter() {
10401054
compare::match_unordered(expect, stderr, cwd)?;
10411055
}
@@ -1075,6 +1089,7 @@ pub fn execs() -> Execs {
10751089
expect_stdout_contains_n: Vec::new(),
10761090
expect_stdout_not_contains: Vec::new(),
10771091
expect_stderr_not_contains: Vec::new(),
1092+
expect_stdout_unordered: Vec::new(),
10781093
expect_stderr_unordered: Vec::new(),
10791094
expect_stderr_with_without: Vec::new(),
10801095
expect_json: None,

0 commit comments

Comments
 (0)