@@ -459,7 +459,12 @@ fn run_test(
459459 let stdin = child. stdin . as_mut ( ) . expect ( "Failed to open stdin" ) ;
460460 stdin. write_all ( test. as_bytes ( ) ) . expect ( "could write out test sources" ) ;
461461 }
462- let output = child. wait_with_output ( ) . expect ( "Failed to read stdout" ) ;
462+ let output = if is_multiple_tests {
463+ let status = child. wait ( ) . expect ( "Failed to wait" ) ;
464+ process:: Output { status, stdout : Vec :: new ( ) , stderr : Vec :: new ( ) }
465+ } else {
466+ child. wait_with_output ( ) . expect ( "Failed to read stdout" )
467+ } ;
463468
464469 struct Bomb < ' a > ( & ' a str ) ;
465470 impl Drop for Bomb < ' _ > {
@@ -540,17 +545,17 @@ fn run_test(
540545 cmd. output ( )
541546 } ;
542547 match result {
543- Err ( e) => return Err ( TestFailure :: ExecutionError ( e) ) ,
548+ Err ( e) => Err ( TestFailure :: ExecutionError ( e) ) ,
544549 Ok ( out) => {
545550 if lang_string. should_panic && out. status . success ( ) {
546- return Err ( TestFailure :: UnexpectedRunPass ) ;
551+ Err ( TestFailure :: UnexpectedRunPass )
547552 } else if !lang_string. should_panic && !out. status . success ( ) {
548- return Err ( TestFailure :: ExecutionFailure ( out) ) ;
553+ Err ( TestFailure :: ExecutionFailure ( out) )
554+ } else {
555+ Ok ( ( ) )
549556 }
550557 }
551558 }
552-
553- Ok ( ( ) )
554559}
555560
556561/// Converts a path intended to use as a command to absolute if it is
@@ -1275,11 +1280,14 @@ impl DocTestKinds {
12751280 doctest : DocTest ,
12761281 opts : & GlobalTestOptions ,
12771282 edition : Edition ,
1283+ rustdoc_options : & RustdocOptions ,
12781284 unused_externs : & Arc < Mutex < Vec < UnusedExterns > > > ,
12791285 ) {
12801286 if doctest. failed_ast
12811287 || doctest. lang_string . compile_fail
12821288 || doctest. lang_string . test_harness
1289+ || rustdoc_options. nocapture
1290+ || rustdoc_options. test_args . iter ( ) . any ( |arg| arg == "--show-output" )
12831291 || doctest. crate_attrs . contains ( "#![no_std]" )
12841292 {
12851293 self . standalone . push ( doctest. generate_test_desc_and_fn (
@@ -1305,6 +1313,7 @@ impl DocTestKinds {
13051313 }
13061314 let Self { mut standalone, others } = self ;
13071315 let mut ran_edition_tests = 0 ;
1316+ let mut nb_errors = 0 ;
13081317
13091318 for ( edition, mut doctests) in others {
13101319 doctests. sort_by ( |a, b| a. name . cmp ( & b. name ) ) ;
@@ -1347,7 +1356,7 @@ fn main() {{
13471356}}" ,
13481357 )
13491358 . unwrap ( ) ;
1350- if let Err ( TestFailure :: CompileError ) = run_test (
1359+ let ret = run_test (
13511360 output,
13521361 supports_color,
13531362 None ,
@@ -1358,7 +1367,8 @@ fn main() {{
13581367 edition,
13591368 |_: UnusedExterns | { } ,
13601369 false ,
1361- ) {
1370+ ) ;
1371+ if let Err ( TestFailure :: CompileError ) = ret {
13621372 // We failed to compile all compatible tests as one so we push them into the
13631373 // "standalone" doctests.
13641374 debug ! ( "Failed to compile compatible doctests for edition {edition} all at once" ) ;
@@ -1371,13 +1381,20 @@ fn main() {{
13711381 }
13721382 } else {
13731383 ran_edition_tests += 1 ;
1384+ if ret. is_err ( ) {
1385+ nb_errors += 1 ;
1386+ }
13741387 }
13751388 }
13761389
13771390 if ran_edition_tests == 0 || !standalone. is_empty ( ) {
13781391 standalone. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( & b. desc . name . as_slice ( ) ) ) ;
13791392 test:: test_main ( & test_args, standalone, None ) ;
13801393 }
1394+ if nb_errors != 0 {
1395+ // libtest::ERROR_EXIT_CODE is not public but it's the same value.
1396+ std:: process:: exit ( 101 ) ;
1397+ }
13811398 }
13821399}
13831400
@@ -1538,7 +1555,13 @@ impl Tester for Collector {
15381555 path,
15391556 no_run,
15401557 ) ;
1541- self . tests . add_doctest ( doctest, & opts, edition, & self . unused_extern_reports ) ;
1558+ self . tests . add_doctest (
1559+ doctest,
1560+ & opts,
1561+ edition,
1562+ & self . rustdoc_options ,
1563+ & self . unused_extern_reports ,
1564+ ) ;
15421565 }
15431566
15441567 fn get_line ( & self ) -> usize {
0 commit comments