@@ -129,6 +129,13 @@ mod __doctest_mod {{
129
129
130
130
pub static BINARY_PATH: OnceLock<PathBuf> = OnceLock::new();
131
131
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\" );
132
139
133
140
#[allow(unused)]
134
141
pub fn doctest_path() -> Option<&'static PathBuf> {{
@@ -266,13 +273,14 @@ fn main() {returns_result} {{
266
273
)
267
274
. unwrap ( ) ;
268
275
}
276
+ let should_panic = scraped_test. langstr . should_panic ;
269
277
let not_running = ignore || scraped_test. no_run ( opts) ;
270
278
writeln ! (
271
279
output_merged_tests,
272
280
"
273
281
mod {test_id} {{
274
282
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,
276
284
test::StaticTestFn(
277
285
|| {{{runner}}},
278
286
));
@@ -294,7 +302,6 @@ if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
294
302
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
295
303
}}
296
304
" ,
297
- should_panic = scraped_test. langstr. should_panic,
298
305
)
299
306
} ,
300
307
)
0 commit comments