@@ -18,9 +18,10 @@ extern crate build_helper;
1818use std:: collections:: HashSet ;
1919use std:: env;
2020use std:: fmt;
21- use std:: fs;
21+ use std:: fs:: { self , File } ;
2222use std:: path:: { PathBuf , Path } ;
2323use std:: process:: Command ;
24+ use std:: io:: Read ;
2425
2526use build_helper:: output;
2627
@@ -328,24 +329,15 @@ pub fn docs(build: &Build, compiler: &Compiler) {
328329
329330 while let Some ( p) = stack. pop ( ) {
330331 if p. is_dir ( ) {
331- stack. extend ( t ! ( p. read_dir( ) ) . map ( |p| t ! ( p) . path ( ) ) ) ;
332+ stack. extend ( t ! ( p. read_dir( ) ) . map ( |p| t ! ( p) . path ( ) ) . filter ( |p| {
333+ p. extension ( ) . and_then ( |s| s. to_str ( ) ) == Some ( "md" ) &&
334+ // The nostarch directory in the book is for no starch, and so isn't guaranteed to
335+ // build. We don't care if it doesn't build, so skip it.
336+ p. to_str ( ) . map_or ( true , |p| !p. contains ( "nostarch" ) )
337+ } ) ) ;
332338 continue
333339 }
334340
335- if p. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "md" ) {
336- continue
337- }
338-
339- // The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
340- // we don't care if it doesn't build, so skip it.
341- use std:: ffi:: OsStr ;
342- let path: & OsStr = p. as_ref ( ) ;
343- if let Some ( path) = path. to_str ( ) {
344- if path. contains ( "nostarch" ) {
345- continue ;
346- }
347- }
348-
349341 println ! ( "doc tests for: {}" , p. display( ) ) ;
350342 markdown_test ( build, compiler, & p) ;
351343 }
@@ -376,6 +368,13 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
376368}
377369
378370fn markdown_test ( build : & Build , compiler : & Compiler , markdown : & Path ) {
371+ let mut file = t ! ( File :: open( markdown) ) ;
372+ let mut contents = String :: new ( ) ;
373+ t ! ( file. read_to_string( & mut contents) ) ;
374+ if !contents. contains ( "```" ) {
375+ return ;
376+ }
377+
379378 let mut cmd = Command :: new ( build. rustdoc ( compiler) ) ;
380379 build. add_rustc_lib_path ( compiler, & mut cmd) ;
381380 build. add_rust_test_threads ( & mut cmd) ;
0 commit comments