@@ -129,13 +129,15 @@ mod __doctest_mod {{
129129 }}
130130
131131 #[allow(unused)]
132- pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{
132+ pub fn doctest_runner(bin: &std::path::Path, test_nb: usize, should_panic: bool ) -> ExitCode {{
133133 let out = std::process::Command::new(bin)
134134 .env(self::RUN_OPTION, test_nb.to_string())
135135 .args(std::env::args().skip(1).collect::<Vec<_>>())
136136 .output()
137137 .expect(\" failed to run command\" );
138- if !out.status.success() {{
138+ if should_panic && out.status.code() != Some(101) {{
139+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
140+ }} else if !out.status.success() {{
139141 if let Some(code) = out.status.code() {{
140142 eprintln!(\" Test executable failed (exit status: {{code}}).\" );
141143 }} else {{
@@ -257,7 +259,7 @@ fn main() {returns_result} {{
257259 "
258260mod {test_id} {{
259261pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
260- {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic} ,
262+ {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false ,
261263test::StaticTestFn(
262264 || {{{runner}}},
263265));
@@ -266,7 +268,6 @@ test::StaticTestFn(
266268 file = scraped_test. path( ) ,
267269 line = scraped_test. line,
268270 no_run = scraped_test. langstr. no_run,
269- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
270271 // Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
271272 // don't give it the function to run.
272273 runner = if not_running {
@@ -275,11 +276,12 @@ test::StaticTestFn(
275276 format!(
276277 "
277278if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
278- test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
279+ test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic} ))
279280}} else {{
280281 test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
281282}}
282283" ,
284+ should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
283285 )
284286 } ,
285287 )
0 commit comments