From 255914696a86f04563a12717262418e897309381 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Fri, 2 Feb 2024 19:13:10 +0100 Subject: [PATCH] Apply `-Zpanic-abort-tests` to doctests too --- src/cargo/ops/cargo_test.rs | 5 +++++ tests/testsuite/test.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 0d0bd800fa9..11097381dc0 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,4 +1,5 @@ use crate::core::compiler::{Compilation, CompileKind, Doctest, Metadata, Unit, UnitOutput}; +use crate::core::profiles::PanicStrategy; use crate::core::shell::Verbosity; use crate::core::{TargetKind, Workspace}; use crate::ops; @@ -244,6 +245,10 @@ fn run_doc_tests( } } + if unit.profile.panic != PanicStrategy::Unwind { + p.arg("-C").arg(format!("panic={}", unit.profile.panic)); + } + for &rust_dep in &[ &compilation.deps_output[&unit.kind], &compilation.deps_output[&CompileKind::Host], diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index a340f6586e9..a0fc23216d9 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -4489,6 +4489,37 @@ fn panic_abort_tests() { .run(); } +#[cargo_test] // Unlike with rustc, `rustdoc --test -Cpanic=abort` already works on stable +fn panic_abort_doc_tests() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = 'foo' + version = '0.1.0' + + [profile.dev] + panic = 'abort' + "#, + ) + .file( + "src/lib.rs", + r#" + //! ```should_panic + //! panic!(); + //! ``` + "#, + ) + .build(); + + p.cargo("test --doc -Z panic-abort-tests -v") + .with_stderr_contains("[..]rustc[..]--crate-name foo [..]-C panic=abort[..]") + .with_stderr_contains("[..]rustdoc[..]--crate-name foo [..]--test[..]-C panic=abort[..]") + .masquerade_as_nightly_cargo(&["panic-abort-tests"]) + .run(); +} + #[cargo_test(nightly, reason = "-Zpanic-abort-tests in rustc is unstable")] fn panic_abort_only_test() { let p = project()