@@ -136,13 +136,20 @@ mod __doctest_mod {{
136
136
}}
137
137
138
138
#[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 {{
140
140
let out = std::process::Command::new(bin)
141
141
.env(self::RUN_OPTION, test_nb.to_string())
142
142
.args(std::env::args().skip(1).collect::<Vec<_>>())
143
143
.output()
144
144
.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() {{
146
153
if let Some(code) = out.status.code() {{
147
154
eprintln!(\" Test executable failed (exit status: {{code}}).\" );
148
155
}} else {{
@@ -265,7 +272,7 @@ fn main() {returns_result} {{
265
272
"
266
273
mod {test_id} {{
267
274
pub 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 ,
269
276
test::StaticTestFn(
270
277
|| {{{runner}}},
271
278
));
@@ -274,7 +281,6 @@ test::StaticTestFn(
274
281
file = scraped_test. path( ) ,
275
282
line = scraped_test. line,
276
283
no_run = scraped_test. no_run( opts) ,
277
- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
278
284
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
279
285
// don't give it the function to run.
280
286
runner = if not_running {
@@ -283,11 +289,12 @@ test::StaticTestFn(
283
289
format!(
284
290
"
285
291
if 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} ))
287
293
}} else {{
288
294
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
289
295
}}
290
296
" ,
297
+ should_panic = scraped_test. langstr. should_panic,
291
298
)
292
299
} ,
293
300
)
0 commit comments