Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07d41a7
Correctly handle `--no-run` rustdoc test option
GuillaumeGomez Jul 13, 2025
796c4ef
Correctly handle `should_panic` doctest attribute
GuillaumeGomez Jul 7, 2025
11b7070
Add regression test for #143009
GuillaumeGomez Jul 4, 2025
21a4d9d
Update std doctests
GuillaumeGomez Jul 7, 2025
5f2ae4f
Add regression test for #143858
GuillaumeGomez Jul 13, 2025
b001ba6
Add FIXME comments to use `test::ERROR_EXIT_CODE` once public and fix…
GuillaumeGomez Aug 1, 2025
030b664
Use libtest `ERROR_EXIT_CODE` constant
GuillaumeGomez Oct 4, 2025
560d450
Correctly handle `should_panic` on targets not supporting it
GuillaumeGomez Oct 5, 2025
a11fe5d
Add diagnostic items for `pub mod consts` of FP types
samueltardieu Oct 6, 2025
b70e20a
Correctly handle `-C panic=abort` in doctests
GuillaumeGomez Oct 7, 2025
594f9c6
Clarify how to remediate the panic_immediate_abort error
ia0 Oct 8, 2025
6060bcc
Improve error messages for failing `should_panic` doctests
GuillaumeGomez Oct 8, 2025
973ddd8
Do not invalidate CFG caches in CtfeLimit.
cjgillot Oct 8, 2025
d4ecd71
format: some small cleanup
hkBst Oct 8, 2025
730221e
Fix double error for `#[no_mangle]` on closures
JonathanBrouwer Oct 8, 2025
c050bfb
Fix double error for `#[no_mangle]` on consts
JonathanBrouwer Oct 8, 2025
28c8cf6
Rollup merge of #143900 - GuillaumeGomez:fix-no-run, r=fmease
chenyukang Oct 9, 2025
632e546
Rollup merge of #147420 - samueltardieu:diag-items/consts-mod, r=joboet
chenyukang Oct 9, 2025
54aab31
Rollup merge of #147467 - JonathanBrouwer:double_warnings, r=Jonathan…
chenyukang Oct 9, 2025
8b701ae
Rollup merge of #147470 - ia0:immediate-abort, r=Mark-Simulacrum
chenyukang Oct 9, 2025
fbda090
Rollup merge of #147480 - cjgillot:invalidate-ctfelimit, r=tmiasko
chenyukang Oct 9, 2025
4617330
Rollup merge of #147481 - hkBst:format-1, r=jackh726
chenyukang Oct 9, 2025
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
Prev Previous commit
Next Next commit
Improve error messages for failing should_panic doctests
Added missing FIXME comments
  • Loading branch information
GuillaumeGomez committed Oct 8, 2025
commit 6060bccd26b9a3a6bc14fd26e47d35fccdf590a3
48 changes: 42 additions & 6 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ enum TestFailure {
///
/// This typically means an assertion in the test failed or another form of panic occurred.
ExecutionFailure(process::Output),
/// The test is marked `should_panic` but the test binary executed successfully.
UnexpectedRunPass,
/// The test is marked `should_panic` but the test binary didn't panic.
NoPanic(Option<String>),
}

enum DirState {
Expand Down Expand Up @@ -812,6 +812,9 @@ fn run_test(
// (cfg!(target_family = "wasm") || cfg!(target_os = "zkvm"))
// && !cfg!(target_os = "emscripten")
// ```
//
// FIXME: All this code is terrible and doesn't take into account `TargetTuple::TargetJson`.
// If `libtest` doesn't allow to handle this case, we'll need to use a rustc's API instead.
&& let TargetTuple::TargetTuple(ref s) = rustdoc_options.target
&& let mut iter = s.split('-')
&& let Some(arch) = iter.next()
Expand Down Expand Up @@ -876,12 +879,41 @@ fn run_test(
#[cfg(windows)]
Some(STATUS_FAIL_FAST_EXCEPTION) => {}
#[cfg(unix)]
None if out.status.signal() == Some(SIGABRT) => {}
None => match out.status.signal() {
Some(SIGABRT) => {}
Some(signal) => {
return (
duration,
Err(TestFailure::NoPanic(Some(format!(
"Test didn't panic, but it's marked `should_panic` (exit signal: {signal}).",
)))),
);
}
None => {
return (
duration,
Err(TestFailure::NoPanic(Some(format!(
"Test didn't panic, but it's marked `should_panic` and exited with no error code and no signal.",
)))),
);
}
},
#[cfg(not(unix))]
None => return (duration, Err(TestFailure::NoPanic(None))),
// Upon an abort, Fuchsia returns the status code
// `ZX_TASK_RETCODE_EXCEPTION_KILL`.
#[cfg(target_os = "fuchsia")]
Some(ZX_TASK_RETCODE_EXCEPTION_KILL) => {}
_ => return (duration, Err(TestFailure::UnexpectedRunPass)),
Some(exit_code) => {
let err_msg = if !out.status.success() {
Some(format!(
"Test didn't panic, but it's marked `should_panic` (exit status: {exit_code}).",
))
} else {
None
};
return (duration, Err(TestFailure::NoPanic(err_msg)));
}
}
} else if !out.status.success() {
return (duration, Err(TestFailure::ExecutionFailure(out)));
Expand Down Expand Up @@ -1190,8 +1222,12 @@ fn doctest_run_fn(
TestFailure::UnexpectedCompilePass => {
eprint!("Test compiled successfully, but it's marked `compile_fail`.");
}
TestFailure::UnexpectedRunPass => {
eprint!("Test didn't panic, but it's marked `should_panic`.");
TestFailure::NoPanic(msg) => {
if let Some(msg) = msg {
eprint!("{msg}");
} else {
eprint!("Test didn't panic, but it's marked `should_panic`.");
}
}
TestFailure::MissingErrorCodes(codes) => {
eprint!("Some expected error codes were not found: {codes:?}");
Expand Down
25 changes: 22 additions & 3 deletions src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,31 @@ mod __doctest_mod {{
#[cfg(windows)]
Some(STATUS_FAIL_FAST_EXCEPTION) => ExitCode::SUCCESS,
#[cfg(unix)]
None if out.status.signal() == Some(SIGABRT) => ExitCode::SUCCESS,
None => match out.status.signal() {{
Some(SIGABRT) => ExitCode::SUCCESS,
Some(signal) => {{
eprintln!(\"Test didn't panic, but it's marked `should_panic` (exit signal: {{signal}}).\");
ExitCode::FAILURE
}}
None => {{
eprintln!(\"Test didn't panic, but it's marked `should_panic` and exited with no error code and no signal.\");
ExitCode::FAILURE
}}
}},
#[cfg(not(unix))]
None => {{
eprintln!(\"Test didn't panic, but it's marked `should_panic`.\");
ExitCode::FAILURE
}}
// Upon an abort, Fuchsia returns the status code ZX_TASK_RETCODE_EXCEPTION_KILL.
#[cfg(target_os = \"fuchsia\")]
Some(ZX_TASK_RETCODE_EXCEPTION_KILL) => ExitCode::SUCCESS,
_ => {{
eprintln!(\"Test didn't panic, but it's marked `should_panic`.\");
Some(exit_code) => {{
if !out.status.success() {{
eprintln!(\"Test didn't panic, but it's marked `should_panic` (exit status: {{exit_code}}).\");
}} else {{
eprintln!(\"Test didn't panic, but it's marked `should_panic`.\");
}}
ExitCode::FAILURE
}}
}}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/rustdoc-should-panic/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn check_output(edition: &str, panic_abort: bool) {
"---- test.rs - bad_exit_code (line 1) stdout ----
Test executable failed (exit status: 1).",
"---- test.rs - did_not_panic (line 6) stdout ----
Test didn't panic, but it's marked `should_panic`.",
Test didn't panic, but it's marked `should_panic` (exit status: 1).",
"test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;",
];
for text in should_contain {
Expand Down
13 changes: 8 additions & 5 deletions tests/rustdoc-ui/doctest/failed-doctest-should-panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
// adapted to use that, and that normalize line can go away

//@ edition: 2024
//@ compile-flags:--test
//@ compile-flags:--test --test-args=--test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"
//@ failure-status: 101

/// ```should_panic
/// println!("Hello, world!");
/// ```
pub struct Foo;
//! ```should_panic
//! println!("Hello, world!");
//! ```
//!
//! ```should_panic
//! std::process::exit(2);
//! ```
15 changes: 10 additions & 5 deletions tests/rustdoc-ui/doctest/failed-doctest-should-panic.stdout
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@

running 1 test
test $DIR/failed-doctest-should-panic.rs - Foo (line 12) ... FAILED
running 2 tests
test $DIR/failed-doctest-should-panic.rs - (line 12) ... FAILED
test $DIR/failed-doctest-should-panic.rs - (line 16) ... FAILED

failures:

---- $DIR/failed-doctest-should-panic.rs - Foo (line 12) stdout ----
---- $DIR/failed-doctest-should-panic.rs - (line 12) stdout ----
Test didn't panic, but it's marked `should_panic`.

---- $DIR/failed-doctest-should-panic.rs - (line 16) stdout ----
Test didn't panic, but it's marked `should_panic` (exit status: 2).


failures:
$DIR/failed-doctest-should-panic.rs - Foo (line 12)
$DIR/failed-doctest-should-panic.rs - (line 12)
$DIR/failed-doctest-should-panic.rs - (line 16)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

all doctests ran in $TIME; merged doctests compilation took $TIME
Loading