@@ -39,6 +39,7 @@ impl DocTestRunner {
3939 doctest : & DocTestBuilder ,
4040 scraped_test : & ScrapedDocTest ,
4141 target_str : & str ,
42+ opts : & RustdocOptions ,
4243 ) {
4344 let ignore = match scraped_test. langstr . ignore {
4445 Ignore :: All => true ,
@@ -62,6 +63,7 @@ impl DocTestRunner {
6263 self . nb_tests,
6364 & mut self . output,
6465 & mut self . output_merged_tests,
66+ opts,
6567 ) ,
6668 ) ) ;
6769 self . supports_color &= doctest. supports_color ;
@@ -134,13 +136,21 @@ mod __doctest_mod {{
134136 }}
135137
136138 #[allow(unused)]
137- 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 {{
138140 let out = std::process::Command::new(bin)
139141 .env(self::RUN_OPTION, test_nb.to_string())
140142 .args(std::env::args().skip(1).collect::<Vec<_>>())
141143 .output()
142144 .expect(\" failed to run command\" );
143- if !out.status.success() {{
145+ if should_panic {{
146+ // FIXME: use test::ERROR_EXIT_CODE once public
147+ if out.status.code() != Some(101) {{
148+ eprintln!(\" Test didn't panic, but it's marked `should_panic`.\" );
149+ ExitCode::FAILURE
150+ }} else {{
151+ ExitCode::SUCCESS
152+ }}
153+ }} else if !out.status.success() {{
144154 if let Some(code) = out.status.code() {{
145155 eprintln!(\" Test executable failed (exit status: {{code}}).\" );
146156 }} else {{
@@ -223,6 +233,7 @@ fn generate_mergeable_doctest(
223233 id : usize ,
224234 output : & mut String ,
225235 output_merged_tests : & mut String ,
236+ opts : & RustdocOptions ,
226237) -> String {
227238 let test_id = format ! ( "__doctest_{id}" ) ;
228239
@@ -256,22 +267,21 @@ fn main() {returns_result} {{
256267 )
257268 . unwrap ( ) ;
258269 }
259- let not_running = ignore || scraped_test. langstr . no_run ;
270+ let not_running = ignore || scraped_test. no_run ( opts ) ;
260271 writeln ! (
261272 output_merged_tests,
262273 "
263274mod {test_id} {{
264275pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
265- {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic} ,
276+ {test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false ,
266277test::StaticTestFn(
267278 || {{{runner}}},
268279));
269280}}" ,
270281 test_name = scraped_test. name,
271282 file = scraped_test. path( ) ,
272283 line = scraped_test. line,
273- no_run = scraped_test. langstr. no_run,
274- should_panic = !scraped_test. langstr. no_run && scraped_test. langstr. should_panic,
284+ no_run = scraped_test. no_run( opts) ,
275285 // Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
276286 // don't give it the function to run.
277287 runner = if not_running {
@@ -280,11 +290,12 @@ test::StaticTestFn(
280290 format!(
281291 "
282292if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
283- test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
293+ test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic} ))
284294}} else {{
285295 test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
286296}}
287297" ,
298+ should_panic = scraped_test. langstr. should_panic,
288299 )
289300 } ,
290301 )
0 commit comments