Skip to content

Commit

Permalink
Apply -Zpanic-abort-tests to doctests too
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Feb 2, 2024
1 parent 4b22dcf commit 2559146
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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],
Expand Down
31 changes: 31 additions & 0 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2559146

Please sign in to comment.