Skip to content

Commit be87c96

Browse files
committed
Auto merge of #14785 - epage:test-unordered, r=ehuss
test(gc): Update remaining unordered tests to snapbox ### What does this PR try to resolve? This gets rid of the last unordered tests and removes the functions from `cargo-test-support` as part of #14039 Some tests are being less specific than they were before but in talking to ehuss, it sounded like that was ok. ### How should we test and review this PR? ### Additional information
2 parents d050945 + bfa097e commit be87c96

File tree

4 files changed

+60
-202
lines changed

4 files changed

+60
-202
lines changed

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

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
4444
use crate::cross_compile::try_alternate;
4545
use crate::paths;
46-
use crate::{diff, rustc_host};
46+
use crate::rustc_host;
4747
use anyhow::{bail, Result};
4848
use snapbox::Data;
4949
use snapbox::IntoData;
@@ -431,56 +431,6 @@ fn substitute_macros(input: &str) -> String {
431431
result
432432
}
433433

434-
/// Checks that the given string contains the given lines, ignoring the order
435-
/// of the lines.
436-
///
437-
/// See [Patterns](index.html#patterns) for more information on pattern matching.
438-
pub(crate) fn match_unordered(expected: &str, actual: &str, cwd: Option<&Path>) -> Result<()> {
439-
let expected = normalize_expected(expected, cwd);
440-
let actual = normalize_actual(actual, cwd);
441-
let e: Vec<_> = expected.lines().map(|line| WildStr::new(line)).collect();
442-
let mut a: Vec<_> = actual.lines().map(|line| WildStr::new(line)).collect();
443-
// match more-constrained lines first, although in theory we'll
444-
// need some sort of recursive match here. This handles the case
445-
// that you expect "a\n[..]b" and two lines are printed out,
446-
// "ab\n"a", where technically we do match unordered but a naive
447-
// search fails to find this. This simple sort at least gets the
448-
// test suite to pass for now, but we may need to get more fancy
449-
// if tests start failing again.
450-
a.sort_by_key(|s| s.line.len());
451-
let mut changes = Vec::new();
452-
let mut a_index = 0;
453-
let mut failure = false;
454-
455-
use crate::diff::Change;
456-
for (e_i, e_line) in e.into_iter().enumerate() {
457-
match a.iter().position(|a_line| e_line == *a_line) {
458-
Some(index) => {
459-
let a_line = a.remove(index);
460-
changes.push(Change::Keep(e_i, index, a_line));
461-
a_index += 1;
462-
}
463-
None => {
464-
failure = true;
465-
changes.push(Change::Remove(e_i, e_line));
466-
}
467-
}
468-
}
469-
for unmatched in a {
470-
failure = true;
471-
changes.push(Change::Add(a_index, unmatched));
472-
a_index += 1;
473-
}
474-
if failure {
475-
bail!(
476-
"Expected lines did not match (ignoring order):\n{}\n",
477-
diff::render_colored_changes(&changes)
478-
);
479-
} else {
480-
Ok(())
481-
}
482-
}
483-
484434
/// Checks that the given string contains the given contiguous lines
485435
/// somewhere.
486436
///

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub use cargo_test_macro::cargo_test;
105105
pub mod compare;
106106
pub mod containers;
107107
pub mod cross_compile;
108-
mod diff;
109108
pub mod git;
110109
pub mod install;
111110
pub mod paths;
@@ -651,8 +650,6 @@ pub struct Execs {
651650
expect_stderr_contains: Vec<String>,
652651
expect_stdout_not_contains: Vec<String>,
653652
expect_stderr_not_contains: Vec<String>,
654-
expect_stdout_unordered: Vec<String>,
655-
expect_stderr_unordered: Vec<String>,
656653
expect_stderr_with_without: Vec<(Vec<String>, Vec<String>)>,
657654
stream_output: bool,
658655
assert: snapbox::Assert,
@@ -751,43 +748,6 @@ impl Execs {
751748
self
752749
}
753750

754-
/// Verifies that all of the stdout output is equal to the given lines,
755-
/// ignoring the order of the lines.
756-
///
757-
/// See [`Execs::with_stderr_unordered`] for more details.
758-
#[deprecated(note = "replaced with `Execs::with_stdout_data(expected.unordered())`")]
759-
pub fn with_stdout_unordered<S: ToString>(&mut self, expected: S) -> &mut Self {
760-
self.expect_stdout_unordered.push(expected.to_string());
761-
self
762-
}
763-
764-
/// Verifies that all of the stderr output is equal to the given lines,
765-
/// ignoring the order of the lines.
766-
///
767-
/// See [`compare`] for supported patterns.
768-
///
769-
/// This is useful when checking the output of `cargo build -v` since
770-
/// the order of the output is not always deterministic.
771-
/// Recommend use `with_stderr_contains` instead unless you really want to
772-
/// check *every* line of output.
773-
///
774-
/// Be careful when using patterns such as `[..]`, because you may end up
775-
/// with multiple lines that might match, and this is not smart enough to
776-
/// do anything like longest-match. For example, avoid something like:
777-
///
778-
/// ```text
779-
/// [RUNNING] `rustc [..]
780-
/// [RUNNING] `rustc --crate-name foo [..]
781-
/// ```
782-
///
783-
/// This will randomly fail if the other crate name is `bar`, and the
784-
/// order changes.
785-
#[deprecated(note = "replaced with `Execs::with_stderr_data(expected.unordered())`")]
786-
pub fn with_stderr_unordered<S: ToString>(&mut self, expected: S) -> &mut Self {
787-
self.expect_stderr_unordered.push(expected.to_string());
788-
self
789-
}
790-
791751
/// Verify that a particular line appears in stderr with and without the
792752
/// given substrings. Exactly one line must match.
793753
///
@@ -993,8 +953,6 @@ impl Execs {
993953
&& self.expect_stderr_contains.is_empty()
994954
&& self.expect_stdout_not_contains.is_empty()
995955
&& self.expect_stderr_not_contains.is_empty()
996-
&& self.expect_stdout_unordered.is_empty()
997-
&& self.expect_stderr_unordered.is_empty()
998956
&& self.expect_stderr_with_without.is_empty()
999957
{
1000958
panic!(
@@ -1107,12 +1065,6 @@ impl Execs {
11071065
for expect in self.expect_stderr_not_contains.iter() {
11081066
compare::match_does_not_contain(expect, stderr, cwd)?;
11091067
}
1110-
for expect in self.expect_stdout_unordered.iter() {
1111-
compare::match_unordered(expect, stdout, cwd)?;
1112-
}
1113-
for expect in self.expect_stderr_unordered.iter() {
1114-
compare::match_unordered(expect, stderr, cwd)?;
1115-
}
11161068
for (with, without) in self.expect_stderr_with_without.iter() {
11171069
compare::match_with_without(stderr, with, without, cwd)?;
11181070
}
@@ -1141,8 +1093,6 @@ pub fn execs() -> Execs {
11411093
expect_stderr_contains: Vec::new(),
11421094
expect_stdout_not_contains: Vec::new(),
11431095
expect_stderr_not_contains: Vec::new(),
1144-
expect_stdout_unordered: Vec::new(),
1145-
expect_stderr_unordered: Vec::new(),
11461096
expect_stderr_with_without: Vec::new(),
11471097
stream_output: false,
11481098
assert: compare::assert_e2e(),

0 commit comments

Comments
 (0)