@@ -78,15 +78,17 @@ fn try_run(build: &Build, cmd: &mut Command) -> bool {
78
78
true
79
79
}
80
80
81
- fn try_run_quiet ( build : & Build , cmd : & mut Command ) {
81
+ fn try_run_quiet ( build : & Build , cmd : & mut Command ) -> bool {
82
82
if !build. fail_fast {
83
83
if !build. try_run_quiet ( cmd) {
84
84
let mut failures = build. delayed_failures . borrow_mut ( ) ;
85
85
failures. push ( format ! ( "{:?}" , cmd) ) ;
86
+ return false ;
86
87
}
87
88
} else {
88
89
build. run_quiet ( cmd) ;
89
90
}
91
+ true
90
92
}
91
93
92
94
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
@@ -994,23 +996,19 @@ impl Step for Compiletest {
994
996
}
995
997
996
998
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
997
- pub struct Docs {
999
+ struct DocTest {
998
1000
compiler : Compiler ,
1001
+ path : & ' static str ,
1002
+ name : & ' static str ,
1003
+ is_ext_doc : bool ,
999
1004
}
1000
1005
1001
- impl Step for Docs {
1006
+ impl Step for DocTest {
1002
1007
type Output = ( ) ;
1003
- const DEFAULT : bool = true ;
1004
1008
const ONLY_HOSTS : bool = true ;
1005
1009
1006
1010
fn should_run ( run : ShouldRun ) -> ShouldRun {
1007
- run. path ( "src/doc" )
1008
- }
1009
-
1010
- fn make_run ( run : RunConfig ) {
1011
- run. builder . ensure ( Docs {
1012
- compiler : run. builder . compiler ( run. builder . top_stage , run. host ) ,
1013
- } ) ;
1011
+ run. never ( )
1014
1012
}
1015
1013
1016
1014
/// Run `rustdoc --test` for all documentation in `src/doc`.
@@ -1026,9 +1024,9 @@ impl Step for Docs {
1026
1024
1027
1025
// Do a breadth-first traversal of the `src/doc` directory and just run
1028
1026
// tests for all files that end in `*.md`
1029
- let mut stack = vec ! [ build. src. join( "src/doc" ) ] ;
1027
+ let mut stack = vec ! [ build. src. join( self . path ) ] ;
1030
1028
let _time = util:: timeit ( ) ;
1031
- let _folder = build. fold_output ( || "test_docs" ) ;
1029
+ let _folder = build. fold_output ( || format ! ( "test_{}" , self . name ) ) ;
1032
1030
1033
1031
while let Some ( p) = stack. pop ( ) {
1034
1032
if p. is_dir ( ) {
@@ -1046,11 +1044,64 @@ impl Step for Docs {
1046
1044
continue ;
1047
1045
}
1048
1046
1049
- markdown_test ( builder, compiler, & p) ;
1047
+ let test_result = markdown_test ( builder, compiler, & p) ;
1048
+ if self . is_ext_doc {
1049
+ let toolstate = if test_result {
1050
+ ToolState :: TestPass
1051
+ } else {
1052
+ ToolState :: TestFail
1053
+ } ;
1054
+ build. save_toolstate ( self . name , toolstate) ;
1055
+ }
1050
1056
}
1051
1057
}
1052
1058
}
1053
1059
1060
+ macro_rules! test_book {
1061
+ ( $( $name: ident, $path: expr, $book_name: expr, default =$default: expr; ) +) => {
1062
+ $(
1063
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
1064
+ pub struct $name {
1065
+ compiler: Compiler ,
1066
+ }
1067
+
1068
+ impl Step for $name {
1069
+ type Output = ( ) ;
1070
+ const DEFAULT : bool = $default;
1071
+ const ONLY_HOSTS : bool = true ;
1072
+
1073
+ fn should_run( run: ShouldRun ) -> ShouldRun {
1074
+ run. path( $path)
1075
+ }
1076
+
1077
+ fn make_run( run: RunConfig ) {
1078
+ run. builder. ensure( $name {
1079
+ compiler: run. builder. compiler( run. builder. top_stage, run. host) ,
1080
+ } ) ;
1081
+ }
1082
+
1083
+ fn run( self , builder: & Builder ) {
1084
+ builder. ensure( DocTest {
1085
+ compiler: self . compiler,
1086
+ path: $path,
1087
+ name: $book_name,
1088
+ is_ext_doc: !$default,
1089
+ } ) ;
1090
+ }
1091
+ }
1092
+ ) +
1093
+ }
1094
+ }
1095
+
1096
+ test_book ! (
1097
+ Nomicon , "src/doc/nomicon" , "nomicon" , default =false ;
1098
+ Reference , "src/doc/reference" , "reference" , default =false ;
1099
+ RustdocBook , "src/doc/rustdoc" , "rustdoc" , default =true ;
1100
+ RustByExample , "src/doc/rust-by-example" , "rust-by-example" , default =false ;
1101
+ TheBook , "src/doc/book" , "book" , default =false ;
1102
+ UnstableBook , "src/doc/unstable-book" , "unstable-book" , default =true ;
1103
+ ) ;
1104
+
1054
1105
#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
1055
1106
pub struct ErrorIndex {
1056
1107
compiler : Compiler ,
@@ -1101,13 +1152,13 @@ impl Step for ErrorIndex {
1101
1152
}
1102
1153
}
1103
1154
1104
- fn markdown_test ( builder : & Builder , compiler : Compiler , markdown : & Path ) {
1155
+ fn markdown_test ( builder : & Builder , compiler : Compiler , markdown : & Path ) -> bool {
1105
1156
let build = builder. build ;
1106
1157
let mut file = t ! ( File :: open( markdown) ) ;
1107
1158
let mut contents = String :: new ( ) ;
1108
1159
t ! ( file. read_to_string( & mut contents) ) ;
1109
1160
if !contents. contains ( "```" ) {
1110
- return ;
1161
+ return true ;
1111
1162
}
1112
1163
1113
1164
println ! ( "doc tests for: {}" , markdown. display( ) ) ;
@@ -1121,9 +1172,9 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) {
1121
1172
cmd. arg ( "--test-args" ) . arg ( test_args) ;
1122
1173
1123
1174
if build. config . quiet_tests {
1124
- try_run_quiet ( build, & mut cmd) ;
1175
+ try_run_quiet ( build, & mut cmd)
1125
1176
} else {
1126
- try_run ( build, & mut cmd) ;
1177
+ try_run ( build, & mut cmd)
1127
1178
}
1128
1179
}
1129
1180
0 commit comments