Skip to content

Commit 1ee6ba0

Browse files
Correctly handle should_panic on targets not supporting it
1 parent 030b664 commit 1ee6ba0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/librustdoc/doctest/runner.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ mod __doctest_mod {{
129129
130130
pub static BINARY_PATH: OnceLock<PathBuf> = OnceLock::new();
131131
pub const RUN_OPTION: &str = \"RUSTDOC_DOCTEST_RUN_NB_TEST\";
132+
// On some platforms, exit code can only be 0 or 1, preventing us to actually know if it's a
133+
// panic. In this case, we ignore the tests with `should_panic`.
134+
//
135+
// Emscripten can catch panics but other wasm targets cannot
136+
pub const SHOULD_PANIC_DISABLED: bool = (
137+
cfg!(target_family = \"wasm\") || cfg!(target_os = \"zkvm\")
138+
) && !cfg!(target_os = \"emscripten\");
132139
133140
#[allow(unused)]
134141
pub fn doctest_path() -> Option<&'static PathBuf> {{
@@ -266,13 +273,14 @@ fn main() {returns_result} {{
266273
)
267274
.unwrap();
268275
}
276+
let should_panic = scraped_test.langstr.should_panic;
269277
let not_running = ignore || scraped_test.no_run(opts);
270278
writeln!(
271279
output_merged_tests,
272280
"
273281
mod {test_id} {{
274282
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
275-
{test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false,
283+
{test_name:?}, {ignore} || ({should_panic} && crate::__doctest_mod::SHOULD_PANIC_DISABLED), {file:?}, {line}, {no_run}, false,
276284
test::StaticTestFn(
277285
|| {{{runner}}},
278286
));
@@ -294,7 +302,6 @@ if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
294302
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
295303
}}
296304
",
297-
should_panic = scraped_test.langstr.should_panic,
298305
)
299306
},
300307
)

0 commit comments

Comments
 (0)