@@ -289,7 +289,7 @@ pub(crate) fn run_tests(
289
289
for ( doctest, scraped_test) in & doctests {
290
290
tests_runner. add_test ( doctest, scraped_test, & target_str) ;
291
291
}
292
- if let Ok ( success) = tests_runner. run_tests (
292
+ if let Ok ( success) = tests_runner. run_merged_tests (
293
293
rustdoc_test_options,
294
294
edition,
295
295
& opts,
@@ -454,6 +454,7 @@ fn run_test(
454
454
doctest : RunnableDoctest ,
455
455
rustdoc_options : & RustdocOptions ,
456
456
supports_color : bool ,
457
+ is_multiple_tests : bool ,
457
458
report_unused_externs : impl Fn ( UnusedExterns ) ,
458
459
) -> Result < ( ) , TestFailure > {
459
460
let langstr = & doctest. langstr ;
@@ -474,11 +475,14 @@ fn run_test(
474
475
}
475
476
476
477
compiler. arg ( "--edition" ) . arg ( & doctest. edition . to_string ( ) ) ;
477
- compiler. env ( "UNSTABLE_RUSTDOC_TEST_PATH" , & doctest. test_opts . path ) ;
478
- compiler. env (
479
- "UNSTABLE_RUSTDOC_TEST_LINE" ,
480
- format ! ( "{}" , doctest. line as isize - doctest. full_test_line_offset as isize ) ,
481
- ) ;
478
+ if !is_multiple_tests {
479
+ // Setting these environment variables is unneeded if this is a merged doctest.
480
+ compiler. env ( "UNSTABLE_RUSTDOC_TEST_PATH" , & doctest. test_opts . path ) ;
481
+ compiler. env (
482
+ "UNSTABLE_RUSTDOC_TEST_LINE" ,
483
+ format ! ( "{}" , doctest. line as isize - doctest. full_test_line_offset as isize ) ,
484
+ ) ;
485
+ }
482
486
compiler. arg ( "-o" ) . arg ( & output_file) ;
483
487
if langstr. test_harness {
484
488
compiler. arg ( "--test" ) ;
@@ -521,18 +525,37 @@ fn run_test(
521
525
}
522
526
}
523
527
524
- compiler. arg ( "-" ) ;
525
- compiler. stdin ( Stdio :: piped ( ) ) ;
526
- compiler. stderr ( Stdio :: piped ( ) ) ;
528
+ // If this is a merged doctest, we need to write it into a file instead of using stdin
529
+ // because if the size of the merged doctests is too big, it'll simply break stdin.
530
+ if is_multiple_tests {
531
+ // It makes the compilation failure much faster if it is for a combined doctest.
532
+ compiler. arg ( "--error-format=short" ) ;
533
+ let input_file =
534
+ doctest. test_opts . outdir . path ( ) . join ( & format ! ( "doctest_{}.rs" , doctest. edition) ) ;
535
+ if std:: fs:: write ( & input_file, & doctest. full_test_code ) . is_err ( ) {
536
+ // If we cannot write this file for any reason, we leave. All combined tests will be
537
+ // tested as standalone tests.
538
+ return Err ( TestFailure :: CompileError ) ;
539
+ }
540
+ compiler. arg ( input_file) ;
541
+ compiler. stderr ( Stdio :: null ( ) ) ;
542
+ } else {
543
+ compiler. arg ( "-" ) ;
544
+ compiler. stdin ( Stdio :: piped ( ) ) ;
545
+ compiler. stderr ( Stdio :: piped ( ) ) ;
546
+ }
527
547
528
548
debug ! ( "compiler invocation for doctest: {compiler:?}" ) ;
529
549
530
550
let mut child = compiler. spawn ( ) . expect ( "Failed to spawn rustc process" ) ;
531
- {
551
+ let output = if is_multiple_tests {
552
+ let status = child. wait ( ) . expect ( "Failed to wait" ) ;
553
+ process:: Output { status, stdout : Vec :: new ( ) , stderr : Vec :: new ( ) }
554
+ } else {
532
555
let stdin = child. stdin . as_mut ( ) . expect ( "Failed to open stdin" ) ;
533
556
stdin. write_all ( doctest. full_test_code . as_bytes ( ) ) . expect ( "could write out test sources" ) ;
534
- }
535
- let output = child . wait_with_output ( ) . expect ( "Failed to read stdout" ) ;
557
+ child . wait_with_output ( ) . expect ( "Failed to read stdout" )
558
+ } ;
536
559
537
560
struct Bomb < ' a > ( & ' a str ) ;
538
561
impl Drop for Bomb < ' _ > {
@@ -885,8 +908,13 @@ fn doctest_run_fn(
885
908
edition : scraped_test. edition ( & rustdoc_options) ,
886
909
no_run : scraped_test. no_run ( & rustdoc_options) ,
887
910
} ;
888
- let res =
889
- run_test ( runnable_test, & rustdoc_options, doctest. supports_color , report_unused_externs) ;
911
+ let res = run_test (
912
+ runnable_test,
913
+ & rustdoc_options,
914
+ doctest. supports_color ,
915
+ false ,
916
+ report_unused_externs,
917
+ ) ;
890
918
891
919
if let Err ( err) = res {
892
920
match err {
0 commit comments