Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply -Zpanic-abort-tests to doctests too #13388

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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