@@ -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. no_capture {
649631 // If `no_capture` is disabled, then we don't display rustc's output when compiling
@@ -726,7 +708,7 @@ fn run_test(
726708 if std:: fs:: write ( & runner_input_file, merged_test_code) . is_err ( ) {
727709 // If we cannot write this file for any reason, we leave. All combined tests will be
728710 // tested as standalone tests.
729- return ( instant. elapsed ( ) , Err ( TestFailure :: CompileError ) ) ;
711+ return ( instant. elapsed ( ) , Err ( RustdocResult :: CompileError ) ) ;
730712 }
731713 if !rustdoc_options. no_capture {
732714 // If `no_capture` is disabled, then we don't display rustc's output when compiling
@@ -785,7 +767,7 @@ fn run_test(
785767 let _bomb = Bomb ( & out) ;
786768 match ( output. status . success ( ) , langstr. compile_fail ) {
787769 ( true , true ) => {
788- return ( instant. elapsed ( ) , Err ( TestFailure :: UnexpectedCompilePass ) ) ;
770+ return ( instant. elapsed ( ) , Err ( RustdocResult :: UnexpectedCompilePass ) ) ;
789771 }
790772 ( true , false ) => { }
791773 ( false , true ) => {
@@ -801,12 +783,15 @@ fn run_test(
801783 . collect ( ) ;
802784
803785 if !missing_codes. is_empty ( ) {
804- return ( instant. elapsed ( ) , Err ( TestFailure :: MissingErrorCodes ( missing_codes) ) ) ;
786+ return (
787+ instant. elapsed ( ) ,
788+ Err ( RustdocResult :: MissingErrorCodes ( missing_codes) ) ,
789+ ) ;
805790 }
806791 }
807792 }
808793 ( false , false ) => {
809- return ( instant. elapsed ( ) , Err ( TestFailure :: CompileError ) ) ;
794+ return ( instant. elapsed ( ) , Err ( RustdocResult :: CompileError ) ) ;
810795 }
811796 }
812797
@@ -844,17 +829,9 @@ fn run_test(
844829 cmd. output ( )
845830 } ;
846831 match result {
847- Err ( e) => return ( duration, Err ( TestFailure :: ExecutionError ( e) ) ) ,
848- Ok ( out) => {
849- if langstr. should_panic && out. status . success ( ) {
850- return ( duration, Err ( TestFailure :: UnexpectedRunPass ) ) ;
851- } else if !langstr. should_panic && !out. status . success ( ) {
852- return ( duration, Err ( TestFailure :: ExecutionFailure ( out) ) ) ;
853- }
854- }
832+ Err ( e) => ( duration, Err ( RustdocResult :: ExecutionError ( e) ) ) ,
833+ Ok ( output) => ( duration, get_rustdoc_result ( output, langstr. should_panic ) ) ,
855834 }
856-
857- ( duration, Ok ( ( ) ) )
858835}
859836
860837/// Converts a path intended to use as a command to absolute if it is
@@ -1145,54 +1122,7 @@ fn doctest_run_fn(
11451122 run_test ( runnable_test, & rustdoc_options, doctest. supports_color , report_unused_externs) ;
11461123
11471124 if let Err ( err) = res {
1148- match err {
1149- TestFailure :: CompileError => {
1150- eprint ! ( "Couldn't compile the test." ) ;
1151- }
1152- TestFailure :: UnexpectedCompilePass => {
1153- eprint ! ( "Test compiled successfully, but it's marked `compile_fail`." ) ;
1154- }
1155- TestFailure :: UnexpectedRunPass => {
1156- eprint ! ( "Test executable succeeded, but it's marked `should_panic`." ) ;
1157- }
1158- TestFailure :: MissingErrorCodes ( codes) => {
1159- eprint ! ( "Some expected error codes were not found: {codes:?}" ) ;
1160- }
1161- TestFailure :: ExecutionError ( err) => {
1162- eprint ! ( "Couldn't run the test: {err}" ) ;
1163- if err. kind ( ) == io:: ErrorKind :: PermissionDenied {
1164- eprint ! ( " - maybe your tempdir is mounted with noexec?" ) ;
1165- }
1166- }
1167- TestFailure :: ExecutionFailure ( out) => {
1168- eprintln ! ( "Test executable failed ({reason})." , reason = out. status) ;
1169-
1170- // FIXME(#12309): An unfortunate side-effect of capturing the test
1171- // executable's output is that the relative ordering between the test's
1172- // stdout and stderr is lost. However, this is better than the
1173- // alternative: if the test executable inherited the parent's I/O
1174- // handles the output wouldn't be captured at all, even on success.
1175- //
1176- // The ordering could be preserved if the test process' stderr was
1177- // redirected to stdout, but that functionality does not exist in the
1178- // standard library, so it may not be portable enough.
1179- let stdout = str:: from_utf8 ( & out. stdout ) . unwrap_or_default ( ) ;
1180- let stderr = str:: from_utf8 ( & out. stderr ) . unwrap_or_default ( ) ;
1181-
1182- if !stdout. is_empty ( ) || !stderr. is_empty ( ) {
1183- eprintln ! ( ) ;
1184-
1185- if !stdout. is_empty ( ) {
1186- eprintln ! ( "stdout:\n {stdout}" ) ;
1187- }
1188-
1189- if !stderr. is_empty ( ) {
1190- eprintln ! ( "stderr:\n {stderr}" ) ;
1191- }
1192- }
1193- }
1194- }
1195-
1125+ eprint ! ( "{err}" ) ;
11961126 panic:: resume_unwind ( Box :: new ( ( ) ) ) ;
11971127 }
11981128 Ok ( ( ) )
0 commit comments