@@ -136,13 +136,20 @@ mod __doctest_mod {{
136136 }}
137137
138138 #[allow(unused)]
139- pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{
139+ pub fn doctest_runner(bin: &std::path::Path, test_nb: usize, should_panic: bool ) -> ExitCode {{
140140 let out = std::process::Command::new(bin)
141141 .env(self::RUN_OPTION, test_nb.to_string())
142142 .args(std::env::args().skip(1).collect::<Vec<_>>())
143143 .output()
144144 .expect(\" failed to run command\" );
145- if !out.status.success() {{
145+ if should_panic {{
146+ if out.status.code() != Some(101) {{
147+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
148+ ExitCode::FAILURE
149+ }} else {{
150+ ExitCode::SUCCESS
151+ }}
152+ }} else if !out.status.success() {{
146153 if let Some(code) = out.status.code() {{
147154 eprintln!(\" Test executable failed (exit status: {{code}}).\" );
148155 }} else {{
@@ -265,7 +272,7 @@ fn main() {returns_result} {{
265272 "
266273mod {test_id} {{
267274pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
268- {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic} ,
275+ {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false ,
269276test::StaticTestFn(
270277 || {{{runner}}},
271278));
@@ -274,7 +281,6 @@ test::StaticTestFn(
274281 file = scraped_test. path( ) ,
275282 line = scraped_test. line,
276283 no_run = scraped_test. no_run( opts) ,
277- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
278284 // Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
279285 // don't give it the function to run.
280286 runner = if not_running {
@@ -283,11 +289,12 @@ test::StaticTestFn(
283289 format!(
284290 "
285291if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
286- test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
292+ test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic} ))
287293}} else {{
288294 test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
289295}}
290296" ,
297+ should_panic = scraped_test. langstr. should_panic,
291298 )
292299 } ,
293300 )
0 commit comments