@@ -30,6 +30,7 @@ use rustc_span::symbol::sym;
3030use rustc_span:: { FileName , Span } ;
3131use rustc_target:: spec:: { Target , TargetTuple } ;
3232use tempfile:: { Builder as TempFileBuilder , TempDir } ;
33+ use test:: test:: { RustdocResult , get_rustdoc_result} ;
3334use tracing:: debug;
3435
3536use self :: rust:: HirCollector ;
@@ -446,25 +447,6 @@ fn scrape_test_config(
446447 opts
447448}
448449
449- /// Documentation test failure modes.
450- enum TestFailure {
451- /// The test failed to compile.
452- CompileError ,
453- /// The test is marked `compile_fail` but compiled successfully.
454- UnexpectedCompilePass ,
455- /// The test failed to compile (as expected) but the compiler output did not contain all
456- /// expected error codes.
457- MissingErrorCodes ( Vec < String > ) ,
458- /// The test binary was unable to be executed.
459- ExecutionError ( io:: Error ) ,
460- /// The test binary exited with a non-zero exit code.
461- ///
462- /// This typically means an assertion in the test failed or another form of panic occurred.
463- ExecutionFailure ( process:: Output ) ,
464- /// The test is marked `should_panic` but the test binary executed successfully.
465- UnexpectedRunPass ,
466- }
467-
468450enum DirState {
469451 Temp ( TempDir ) ,
470452 Perm ( PathBuf ) ,
@@ -554,7 +536,7 @@ fn run_test(
554536 rustdoc_options : & RustdocOptions ,
555537 supports_color : bool ,
556538 report_unused_externs : impl Fn ( UnusedExterns ) ,
557- ) -> ( Duration , Result < ( ) , TestFailure > ) {
539+ ) -> ( Duration , Result < ( ) , RustdocResult > ) {
558540 let langstr = & doctest. langstr ;
559541 // Make sure we emit well-formed executable names for our target.
560542 let rust_out = add_exe_suffix ( "rust_out" . to_owned ( ) , & rustdoc_options. target ) ;
@@ -643,7 +625,7 @@ fn run_test(
643625 if std:: fs:: write ( & input_file, & doctest. full_test_code ) . is_err ( ) {
644626 // If we cannot write this file for any reason, we leave. All combined tests will be
645627 // tested as standalone tests.
646- return ( Duration :: default ( ) , Err ( TestFailure :: CompileError ) ) ;
628+ return ( Duration :: default ( ) , Err ( RustdocResult :: CompileError ) ) ;
647629 }
648630 if !rustdoc_options. nocapture {
649631 // If `nocapture` is disabled, then we don't display rustc's output when compiling
@@ -720,7 +702,7 @@ fn run_test(
720702 if std:: fs:: write ( & runner_input_file, merged_test_code) . is_err ( ) {
721703 // If we cannot write this file for any reason, we leave. All combined tests will be
722704 // tested as standalone tests.
723- return ( instant. elapsed ( ) , Err ( TestFailure :: CompileError ) ) ;
705+ return ( instant. elapsed ( ) , Err ( RustdocResult :: CompileError ) ) ;
724706 }
725707 if !rustdoc_options. nocapture {
726708 // If `nocapture` is disabled, then we don't display rustc's output when compiling
@@ -773,7 +755,7 @@ fn run_test(
773755 let _bomb = Bomb ( & out) ;
774756 match ( output. status . success ( ) , langstr. compile_fail ) {
775757 ( true , true ) => {
776- return ( instant. elapsed ( ) , Err ( TestFailure :: UnexpectedCompilePass ) ) ;
758+ return ( instant. elapsed ( ) , Err ( RustdocResult :: UnexpectedCompilePass ) ) ;
777759 }
778760 ( true , false ) => { }
779761 ( false , true ) => {
@@ -789,12 +771,15 @@ fn run_test(
789771 . collect ( ) ;
790772
791773 if !missing_codes. is_empty ( ) {
792- return ( instant. elapsed ( ) , Err ( TestFailure :: MissingErrorCodes ( missing_codes) ) ) ;
774+ return (
775+ instant. elapsed ( ) ,
776+ Err ( RustdocResult :: MissingErrorCodes ( missing_codes) ) ,
777+ ) ;
793778 }
794779 }
795780 }
796781 ( false , false ) => {
797- return ( instant. elapsed ( ) , Err ( TestFailure :: CompileError ) ) ;
782+ return ( instant. elapsed ( ) , Err ( RustdocResult :: CompileError ) ) ;
798783 }
799784 }
800785
@@ -832,17 +817,9 @@ fn run_test(
832817 cmd. output ( )
833818 } ;
834819 match result {
835- Err ( e) => return ( duration, Err ( TestFailure :: ExecutionError ( e) ) ) ,
836- Ok ( out) => {
837- if langstr. should_panic && out. status . success ( ) {
838- return ( duration, Err ( TestFailure :: UnexpectedRunPass ) ) ;
839- } else if !langstr. should_panic && !out. status . success ( ) {
840- return ( duration, Err ( TestFailure :: ExecutionFailure ( out) ) ) ;
841- }
842- }
820+ Err ( e) => ( duration, Err ( RustdocResult :: ExecutionError ( e) ) ) ,
821+ Ok ( output) => ( duration, get_rustdoc_result ( output, langstr. should_panic ) ) ,
843822 }
844-
845- ( duration, Ok ( ( ) ) )
846823}
847824
848825/// Converts a path intended to use as a command to absolute if it is
@@ -1136,54 +1113,7 @@ fn doctest_run_fn(
11361113 run_test ( runnable_test, & rustdoc_options, doctest. supports_color , report_unused_externs) ;
11371114
11381115 if let Err ( err) = res {
1139- match err {
1140- TestFailure :: CompileError => {
1141- eprint ! ( "Couldn't compile the test." ) ;
1142- }
1143- TestFailure :: UnexpectedCompilePass => {
1144- eprint ! ( "Test compiled successfully, but it's marked `compile_fail`." ) ;
1145- }
1146- TestFailure :: UnexpectedRunPass => {
1147- eprint ! ( "Test executable succeeded, but it's marked `should_panic`." ) ;
1148- }
1149- TestFailure :: MissingErrorCodes ( codes) => {
1150- eprint ! ( "Some expected error codes were not found: {codes:?}" ) ;
1151- }
1152- TestFailure :: ExecutionError ( err) => {
1153- eprint ! ( "Couldn't run the test: {err}" ) ;
1154- if err. kind ( ) == io:: ErrorKind :: PermissionDenied {
1155- eprint ! ( " - maybe your tempdir is mounted with noexec?" ) ;
1156- }
1157- }
1158- TestFailure :: ExecutionFailure ( out) => {
1159- eprintln ! ( "Test executable failed ({reason})." , reason = out. status) ;
1160-
1161- // FIXME(#12309): An unfortunate side-effect of capturing the test
1162- // executable's output is that the relative ordering between the test's
1163- // stdout and stderr is lost. However, this is better than the
1164- // alternative: if the test executable inherited the parent's I/O
1165- // handles the output wouldn't be captured at all, even on success.
1166- //
1167- // The ordering could be preserved if the test process' stderr was
1168- // redirected to stdout, but that functionality does not exist in the
1169- // standard library, so it may not be portable enough.
1170- let stdout = str:: from_utf8 ( & out. stdout ) . unwrap_or_default ( ) ;
1171- let stderr = str:: from_utf8 ( & out. stderr ) . unwrap_or_default ( ) ;
1172-
1173- if !stdout. is_empty ( ) || !stderr. is_empty ( ) {
1174- eprintln ! ( ) ;
1175-
1176- if !stdout. is_empty ( ) {
1177- eprintln ! ( "stdout:\n {stdout}" ) ;
1178- }
1179-
1180- if !stderr. is_empty ( ) {
1181- eprintln ! ( "stderr:\n {stderr}" ) ;
1182- }
1183- }
1184- }
1185- }
1186-
1116+ eprint ! ( "{err}" ) ;
11871117 panic:: resume_unwind ( Box :: new ( ( ) ) ) ;
11881118 }
11891119 Ok ( ( ) )
0 commit comments