Skip to content

Commit 8ab42d9

Browse files
Correcty handle should_panic on unsupported targets
1 parent adaf3e0 commit 8ab42d9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library/test/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ pub fn convert_benchmarks_to_tests(tests: Vec<TestDescAndFn>) -> Vec<TestDescAnd
570570
.collect()
571571
}
572572

573+
pub fn cannot_handle_should_panic() -> bool {
574+
(cfg!(target_family = "wasm") || cfg!(target_os = "zkvm")) && !cfg!(target_os = "emscripten")
575+
}
576+
573577
pub fn run_test(
574578
opts: &TestOpts,
575579
force_ignore: bool,
@@ -581,9 +585,8 @@ pub fn run_test(
581585
let TestDescAndFn { desc, testfn } = test;
582586

583587
// Emscripten can catch panics but other wasm targets cannot
584-
let ignore_because_no_process_support = desc.should_panic != ShouldPanic::No
585-
&& (cfg!(target_family = "wasm") || cfg!(target_os = "zkvm"))
586-
&& !cfg!(target_os = "emscripten");
588+
let ignore_because_no_process_support =
589+
desc.should_panic != ShouldPanic::No && cannot_handle_should_panic();
587590

588591
if force_ignore || desc.ignore || ignore_because_no_process_support {
589592
let message = CompletedTest::new(id, desc, TrIgnored, None, Vec::new());

src/librustdoc/doctest/runner.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,13 @@ test::StaticTestFn(
267267
runner = if not_running {
268268
"test::assert_test_result(Ok::<(), String>(()))".to_string()
269269
} else {
270+
// One case to consider: if this is a `should_panic` doctest, on some targets, libtest
271+
// ignores such tests because it's not supported. The first `if` checks exactly that.
270272
format!(
271273
"
272-
if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
274+
if {should_panic} && test::cannot_handle_should_panic() {{
275+
test::assert_test_result(Ok::<(), String>(()))
276+
}} else if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
273277
test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic}))
274278
}} else {{
275279
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())

0 commit comments

Comments
 (0)