Skip to content

Commit a04e2e5

Browse files
committed
Auto merge of #5392 - ehuss:test-does-not-contain, r=alexcrichton
cargotest: Fix `with_*_does_not_contain` to support `[..]` and macro matching. I changed it so that it is essentially the opposite of `with_*_contains` to keep it symmetric. Any in-flight PRs using the old style will need to be updated (else they will incorrectly silently pass). Alternatively, we could rename the method to avoid that. The following tests contained brackets, so they were not checking what they thought they were checking. I did a cursory look at them, but perhaps someone else could double-check that they make sense. Asserting what *doesn't* happen can be tricky since there is an infinite number of things that won't happen. Preferably a test would assert that it appears in one scenario and not another (like `incremental_profile` does), but some of them don't or can't. ``` build::incremental_profile build::incremental_config build::cargo_compile_with_workspace_excluded build::build_all_exclude build::targets_selected_default check::targets_selected_default check::check_filters rustc::targets_selected_default rustc_info_cache::rustc_info_cache warn_on_failure::no_warning_on_bin_failure warn_on_failure::warning_on_lib_failure ``` BTW, would you be interested in a PR that adds some documentation to `cargotest`? I've discovered things I didn't know where there. I think some docstrings on some of the methods, and a short guide for new contributors would be helpful.
2 parents 5ac4ab1 + e7896a2 commit a04e2e5

4 files changed

Lines changed: 27 additions & 17 deletions

File tree

tests/testsuite/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn bench_multiple_targets() {
267267
.with_status(0)
268268
.with_stdout_contains("test run1 ... bench: [..]")
269269
.with_stdout_contains("test run2 ... bench: [..]")
270-
.with_stdout_does_not_contain("run3"),
270+
.with_stdout_does_not_contain("[..]run3[..]"),
271271
);
272272
}
273273

tests/testsuite/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4509,7 +4509,7 @@ fn build_virtual_manifest_one_project() {
45094509
p.cargo("build").arg("-p").arg("foo"),
45104510
execs()
45114511
.with_status(0)
4512-
.with_stderr_does_not_contain("bar")
4512+
.with_stderr_does_not_contain("[..]bar[..]")
45134513
.with_stderr_contains("[..] Compiling foo v0.1.0 ([..])")
45144514
.with_stderr(
45154515
"[..] Compiling [..] v0.1.0 ([..])\n\

tests/testsuite/cargotest/support/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,16 +687,26 @@ impl Execs {
687687
}
688688
}
689689
MatchKind::NotPresent => {
690-
if !actual.contains(out) {
691-
Ok(())
692-
} else {
690+
let mut a = actual.lines();
691+
let e = out.lines();
692+
693+
let mut diffs = self.diff_lines(a.clone(), e.clone(), true);
694+
while let Some(..) = a.next() {
695+
let a = self.diff_lines(a.clone(), e.clone(), true);
696+
if a.len() < diffs.len() {
697+
diffs = a;
698+
}
699+
}
700+
if diffs.is_empty() {
693701
Err(format!(
694702
"expected not to find:\n\
695703
{}\n\n\
696704
but found in output:\n\
697705
{}",
698706
out, actual
699707
))
708+
} else {
709+
Ok(())
700710
}
701711
}
702712
}

tests/testsuite/check.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ fn check_filters() {
743743
.with_status(0)
744744
.with_stderr_contains("[..]unused_normal_lib[..]")
745745
.with_stderr_contains("[..]unused_normal_bin[..]")
746-
.with_stderr_does_not_contain("unused_normal_t1")
747-
.with_stderr_does_not_contain("unused_normal_ex1")
748-
.with_stderr_does_not_contain("unused_normal_b1")
749-
.with_stderr_does_not_contain("unused_unit_"),
746+
.with_stderr_does_not_contain("[..]unused_normal_t1[..]")
747+
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
748+
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
749+
.with_stderr_does_not_contain("[..]unused_unit_[..]"),
750750
);
751751
p.root().join("target").rm_rf();
752752
assert_that(
@@ -764,8 +764,8 @@ fn check_filters() {
764764
.with_stderr_contains("[..]unused_unit_t1[..]")
765765
.with_stderr_contains("[..]unused_normal_ex1[..]")
766766
.with_stderr_contains("[..]unused_unit_ex1[..]")
767-
.with_stderr_does_not_contain("unused_normal_b1")
768-
.with_stderr_does_not_contain("unused_unit_b1"),
767+
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
768+
.with_stderr_does_not_contain("[..]unused_unit_b1[..]"),
769769
);
770770
p.root().join("target").rm_rf();
771771
assert_that(
@@ -775,12 +775,12 @@ fn check_filters() {
775775
.with_stderr_contains("[..]unused_normal_lib[..]")
776776
.with_stderr_contains("[..]unused_normal_bin[..]")
777777
.with_stderr_contains("[..]unused_unit_t1[..]")
778-
.with_stderr_does_not_contain("unused_unit_lib")
779-
.with_stderr_does_not_contain("unused_unit_bin")
780-
.with_stderr_does_not_contain("unused_normal_ex1")
781-
.with_stderr_does_not_contain("unused_normal_b1")
782-
.with_stderr_does_not_contain("unused_unit_ex1")
783-
.with_stderr_does_not_contain("unused_unit_b1"),
778+
.with_stderr_does_not_contain("[..]unused_unit_lib[..]")
779+
.with_stderr_does_not_contain("[..]unused_unit_bin[..]")
780+
.with_stderr_does_not_contain("[..]unused_normal_ex1[..]")
781+
.with_stderr_does_not_contain("[..]unused_normal_b1[..]")
782+
.with_stderr_does_not_contain("[..]unused_unit_ex1[..]")
783+
.with_stderr_does_not_contain("[..]unused_unit_b1[..]"),
784784
);
785785
p.root().join("target").rm_rf();
786786
assert_that(

0 commit comments

Comments
 (0)