@@ -129,15 +129,19 @@ mod __doctest_mod {{
129
129
}}
130
130
131
131
#[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 {{
133
133
let out = std::process::Command::new(bin)
134
134
.env(self::RUN_OPTION, test_nb.to_string())
135
135
.args(std::env::args().skip(1).collect::<Vec<_>>())
136
136
.output()
137
137
.expect(\" failed to run command\" );
138
138
if !out.status.success() {{
139
139
if let Some(code) = out.status.code() {{
140
- eprintln!(\" Test executable failed (exit status: {{code}}).\" );
140
+ if should_panic {{
141
+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
142
+ }} else {{
143
+ eprintln!(\" Test executable failed (exit status: {{code}}).\" );
144
+ }}
141
145
}} else {{
142
146
eprintln!(\" Test executable failed (terminated by signal).\" );
143
147
}}
@@ -220,34 +224,40 @@ fn generate_mergeable_doctest(
220
224
output_merged_tests : & mut String ,
221
225
) -> String {
222
226
let test_id = format ! ( "__doctest_{id}" ) ;
227
+ let should_panic = !scraped_test. langstr . no_run && scraped_test. langstr . should_panic ;
223
228
224
229
if ignore {
225
230
// We generate nothing else.
226
231
writeln ! ( output, "pub mod {test_id} {{}}\n " ) . unwrap ( ) ;
227
232
} else {
228
233
writeln ! ( output, "pub mod {test_id} {{\n {}{}" , doctest. crates, doctest. maybe_crate_attrs)
229
234
. unwrap ( ) ;
235
+ let mut returns_result = false ;
230
236
if doctest. has_main_fn {
231
237
output. push_str ( & doctest. everything_else ) ;
232
238
} else {
233
- let returns_result = if doctest. everything_else . trim_end ( ) . ends_with ( "(())" ) {
239
+ let return_value = if doctest. everything_else . trim_end ( ) . ends_with ( "(())" ) {
240
+ returns_result = true ;
234
241
"-> Result<(), impl core::fmt::Debug>"
235
242
} else {
236
243
""
237
244
} ;
238
245
write ! (
239
246
output,
240
247
"\
241
- fn main() {returns_result } {{
248
+ fn main() {return_value } {{
242
249
{}
243
250
}}" ,
244
251
doctest. everything_else
245
252
)
246
253
. unwrap ( ) ;
247
254
}
255
+ let ( should_panic_pre, should_panic_post) =
256
+ super :: make:: should_panic_wrapper ( should_panic, returns_result) ;
248
257
writeln ! (
249
258
output,
250
- "\n pub fn __main_fn() -> impl std::process::Termination {{ main() }} \n }}\n "
259
+ "\n pub fn __main_fn() -> impl std::process::Termination {{{should_panic_pre}main()\
260
+ {should_panic_post}}} \n }}\n "
251
261
)
252
262
. unwrap ( ) ;
253
263
}
@@ -257,7 +267,7 @@ fn main() {returns_result} {{
257
267
"
258
268
mod {test_id} {{
259
269
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
260
- {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic} ,
270
+ {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false ,
261
271
test::StaticTestFn(
262
272
|| {{{runner}}},
263
273
));
@@ -266,7 +276,6 @@ test::StaticTestFn(
266
276
file = scraped_test. path( ) ,
267
277
line = scraped_test. line,
268
278
no_run = scraped_test. langstr. no_run,
269
- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
270
279
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
271
280
// don't give it the function to run.
272
281
runner = if not_running {
@@ -275,7 +284,7 @@ test::StaticTestFn(
275
284
format!(
276
285
"
277
286
if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
278
- 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} ))
279
288
}} else {{
280
289
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
281
290
}}
0 commit comments