From 0a20aabc6a05c0a832c5fa6482d471f2a3b66864 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 15 Jun 2024 22:55:38 +0800 Subject: [PATCH] Remove `Execs::run_expect_error` to avoid #14060 --- crates/cargo-test-support/src/lib.rs | 9 --------- tests/testsuite/check_cfg.rs | 3 ++- tests/testsuite/freshness.rs | 3 ++- tests/testsuite/help.rs | 3 ++- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 09644298316b..5146f9b84d87 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 497c0aeb4200..cbb1f5b76966 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 a412a993bf83..9ba9598f8bf7 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(); } diff --git a/tests/testsuite/help.rs b/tests/testsuite/help.rs index 80d2360347c3..e8fd57646acb 100644 --- a/tests/testsuite/help.rs +++ b/tests/testsuite/help.rs @@ -147,9 +147,10 @@ fn help_alias() { // The `empty-alias` returns an error. cargo_process("help empty-alias") .env("PATH", Path::new("")) + .with_status(101) .with_stderr_contains("THIS RANDOM SENTENCE SHOULD FAIL THIS TEST BUT DIDN'T [..] The subcommand 'empty-alias' wasn't recognized [..]", ) - .run_expect_error(); + .run(); // Because `simple-alias` aliases a subcommand with no arguments, help shows the manpage. help_with_man_and_path("", "simple-alias", "build", Path::new(""));