@@ -131,13 +131,20 @@ mod __doctest_mod {{
131
131
}}
132
132
133
133
#[allow(unused)]
134
- pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{
134
+ pub fn doctest_runner(bin: &std::path::Path, test_nb: usize, should_panic: bool ) -> ExitCode {{
135
135
let out = std::process::Command::new(bin)
136
136
.env(self::RUN_OPTION, test_nb.to_string())
137
137
.args(std::env::args().skip(1).collect::<Vec<_>>())
138
138
.output()
139
139
.expect(\" failed to run command\" );
140
- if !out.status.success() {{
140
+ if should_panic {{
141
+ if out.status.code() != Some(101) {{
142
+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
143
+ ExitCode::FAILURE
144
+ }} else {{
145
+ ExitCode::SUCCESS
146
+ }}
147
+ }} else if !out.status.success() {{
141
148
if let Some(code) = out.status.code() {{
142
149
eprintln!(\" Test executable failed (exit status: {{code}}).\" );
143
150
}} else {{
@@ -260,7 +267,7 @@ fn main() {returns_result} {{
260
267
"
261
268
mod {test_id} {{
262
269
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
263
- {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic} ,
270
+ {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false ,
264
271
test::StaticTestFn(
265
272
|| {{{runner}}},
266
273
));
@@ -269,7 +276,6 @@ test::StaticTestFn(
269
276
file = scraped_test. path( ) ,
270
277
line = scraped_test. line,
271
278
no_run = scraped_test. no_run( opts) ,
272
- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
273
279
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
274
280
// don't give it the function to run.
275
281
runner = if not_running {
@@ -278,11 +284,12 @@ test::StaticTestFn(
278
284
format!(
279
285
"
280
286
if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
281
- test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
287
+ test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic} ))
282
288
}} else {{
283
289
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
284
290
}}
285
291
" ,
292
+ should_panic = scraped_test. langstr. should_panic,
286
293
)
287
294
} ,
288
295
)
0 commit comments