Skip to content

Commit cdf84b6

Browse files
committed
Auto merge of #13388 - Nemo157:panic-abort-doc-tests, r=epage
Apply `-Zpanic-abort-tests` to doctests too ### What does this PR try to resolve? `cranelift` doesn't support unwinding, which causes issues with `should_panic` tests. Attempting to use `-Zpanic-abort-tests` to fix that still fails with doctests because they attempt to use unwinding. `rustdoc` already supports specifying `-Cpanic=abort` and correctly handles ` ```should_panic` tests with it enabled, so we can just start passing it when `-Zpanic-abort-tests` is set. Fixes rust-lang/rust#120578 (when using `-Zbuild-std=std,panic_abort` too)
2 parents 258fa84 + 2559146 commit cdf84b6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/cargo/ops/cargo_test.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::core::compiler::{Compilation, CompileKind, Doctest, Metadata, Unit, UnitOutput};
2+
use crate::core::profiles::PanicStrategy;
23
use crate::core::shell::Verbosity;
34
use crate::core::{TargetKind, Workspace};
45
use crate::ops;
@@ -244,6 +245,10 @@ fn run_doc_tests(
244245
}
245246
}
246247

248+
if unit.profile.panic != PanicStrategy::Unwind {
249+
p.arg("-C").arg(format!("panic={}", unit.profile.panic));
250+
}
251+
247252
for &rust_dep in &[
248253
&compilation.deps_output[&unit.kind],
249254
&compilation.deps_output[&CompileKind::Host],

tests/testsuite/test.rs

+31
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,37 @@ fn panic_abort_tests() {
44894489
.run();
44904490
}
44914491

4492+
#[cargo_test] // Unlike with rustc, `rustdoc --test -Cpanic=abort` already works on stable
4493+
fn panic_abort_doc_tests() {
4494+
let p = project()
4495+
.file(
4496+
"Cargo.toml",
4497+
r#"
4498+
[package]
4499+
name = 'foo'
4500+
version = '0.1.0'
4501+
4502+
[profile.dev]
4503+
panic = 'abort'
4504+
"#,
4505+
)
4506+
.file(
4507+
"src/lib.rs",
4508+
r#"
4509+
//! ```should_panic
4510+
//! panic!();
4511+
//! ```
4512+
"#,
4513+
)
4514+
.build();
4515+
4516+
p.cargo("test --doc -Z panic-abort-tests -v")
4517+
.with_stderr_contains("[..]rustc[..]--crate-name foo [..]-C panic=abort[..]")
4518+
.with_stderr_contains("[..]rustdoc[..]--crate-name foo [..]--test[..]-C panic=abort[..]")
4519+
.masquerade_as_nightly_cargo(&["panic-abort-tests"])
4520+
.run();
4521+
}
4522+
44924523
#[cargo_test(nightly, reason = "-Zpanic-abort-tests in rustc is unstable")]
44934524
fn panic_abort_only_test() {
44944525
let p = project()

0 commit comments

Comments
 (0)