Skip to content

Commit

Permalink
Auto merge of #13388 - Nemo157:panic-abort-doc-tests, r=epage
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Feb 2, 2024
2 parents 258fa84 + 2559146 commit cdf84b6
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 cdf84b6

Please sign in to comment.