From afe9d17258852c1af26ff704e989fe2fab77a8fe Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Fri, 14 Jun 2024 00:06:59 +0800 Subject: [PATCH 1/4] Reproduce #14076 The `with_stderr_contains()` (as well as the new `with_stderr_data()` too, see #14060) has no effect when using with `run_expect_error()`. --- tests/testsuite/check_cfg.rs | 4 +++- tests/testsuite/freshness.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index 4274bdfe1ee..497c0aeb420 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -632,7 +632,9 @@ fn config_invalid_empty() { .build(); p.cargo("check") - .with_stderr_contains("[..]missing field `level`[..]") + .with_stderr_contains( + "[..]missing field `level`[..] THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T", + ) .run_expect_error(); } diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index cc9b516391d..a412a993bf8 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2936,6 +2936,9 @@ fn use_mtime_cache_in_cargo_home() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([CWD]): [..] + + THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T + [CHECKING] foo v0.5.0 ([CWD]) [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]", ) From fde13213813957595253669f8fd6f8ce62ad410d Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 22:55:38 +0800 Subject: [PATCH 2/4] Remove `Execs::run_expect_error` to avoid #14076 --- crates/cargo-test-support/src/lib.rs | 9 --------- tests/testsuite/check_cfg.rs | 3 ++- tests/testsuite/freshness.rs | 3 ++- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 09644298316..5146f9b84d8 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -915,15 +915,6 @@ impl Execs { } } - #[track_caller] - pub fn run_expect_error(&mut self) { - self.ran = true; - let p = (&self.process_builder).clone().unwrap(); - if self.match_process(&p).is_ok() { - panic!("test was expected to fail, but succeeded running {}", p); - } - } - /// Runs the process, checks the expected output, and returns the first /// JSON object on stdout. #[track_caller] diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index 497c0aeb420..cbb1f5b7696 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -632,10 +632,11 @@ fn config_invalid_empty() { .build(); p.cargo("check") + .with_status(101) .with_stderr_contains( "[..]missing field `level`[..] THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T", ) - .run_expect_error(); + .run(); } #[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")] diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index a412a993bf8..9ba9598f8bf 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2933,6 +2933,7 @@ fn use_mtime_cache_in_cargo_home() { p.change_file("src/lib.rs", "illegal syntax"); p.cargo("check -v") .env("CARGO_HOME", &cargo_home) + .with_status(101) .with_stderr( "\ [DIRTY] foo v0.5.0 ([CWD]): [..] @@ -2942,5 +2943,5 @@ fn use_mtime_cache_in_cargo_home() { [CHECKING] foo v0.5.0 ([CWD]) [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]", ) - .run_expect_error(); + .run(); } From b254699e298ad27f5f4262e1c9e97c1a2ca6ea2a Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 23:00:19 +0800 Subject: [PATCH 3/4] Revert "Reproduce #14076" This reverts commit 18f4c3f3d1f90d88c3ea667f51b093d4e1b8deec. --- tests/testsuite/check_cfg.rs | 4 +--- tests/testsuite/freshness.rs | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index cbb1f5b7696..a1de4e91d96 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -633,9 +633,7 @@ fn config_invalid_empty() { p.cargo("check") .with_status(101) - .with_stderr_contains( - "[..]missing field `level`[..] THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T", - ) + .with_stderr_contains("[..]missing field `level`[..]") .run(); } diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 9ba9598f8bf..4ac2c01411b 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2937,9 +2937,6 @@ fn use_mtime_cache_in_cargo_home() { .with_stderr( "\ [DIRTY] foo v0.5.0 ([CWD]): [..] - - THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T - [CHECKING] foo v0.5.0 ([CWD]) [RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]", ) From 6ae78e8d86cab911aa818f666b370a4b8c4eed30 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 23:14:07 +0800 Subject: [PATCH 4/4] Fix regression since #14076 is now resolved --- tests/testsuite/freshness.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 4ac2c01411b..c89d86f84cc 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -2934,7 +2934,7 @@ fn use_mtime_cache_in_cargo_home() { p.cargo("check -v") .env("CARGO_HOME", &cargo_home) .with_status(101) - .with_stderr( + .with_stderr_contains( "\ [DIRTY] foo v0.5.0 ([CWD]): [..] [CHECKING] foo v0.5.0 ([CWD])