@@ -19,6 +19,7 @@ use std::collections::HashSet;
19
19
use std:: env;
20
20
use std:: fmt;
21
21
use std:: fs;
22
+ use std:: io:: Read ;
22
23
use std:: path:: { PathBuf , Path } ;
23
24
use std:: process:: Command ;
24
25
@@ -316,6 +317,76 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
316
317
build. run ( & mut cmd) ;
317
318
}
318
319
320
+ pub fn markdown_test_output_check ( build : & Build , compiler : & Compiler ) {
321
+ let _time = util:: timeit ( ) ;
322
+ for entry in fs:: read_dir ( "src/test/rustdoc-test" )
323
+ . expect ( "markdown_test_output_check: read_dir failed" ) {
324
+ if let Ok ( entry) = entry {
325
+ if entry. path ( ) . extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "rs" ) {
326
+ continue
327
+ }
328
+ markdown_test_output_check_entry ( build, compiler, entry. path ( ) . as_path ( ) ) ;
329
+ }
330
+ }
331
+ }
332
+
333
+ fn markdown_test_output_check_entry ( build : & Build , compiler : & Compiler , path : & Path ) {
334
+ let mut file = fs:: File :: open ( path)
335
+ . expect ( "markdown_test_output_check_entry File::open failed" ) ;
336
+ let mut content = String :: new ( ) ;
337
+ file. read_to_string ( & mut content)
338
+ . expect ( "markdown_test_output_check_entry read_to_string failed" ) ;
339
+ let mut ignore = false ;
340
+ let mut v: Vec < usize > =
341
+ content. split ( "\n " )
342
+ . enumerate ( )
343
+ . filter_map ( |( line_nb, line) | {
344
+ let sline = line. split ( "///" ) . last ( ) . unwrap_or ( "" ) ;
345
+ let line = sline. trim_left ( ) ;
346
+ if line. starts_with ( "```" ) &&
347
+ !line. contains ( "ignore" ) {
348
+ if ignore {
349
+ ignore = false ;
350
+ None
351
+ } else {
352
+ ignore = true ;
353
+ Some ( line_nb + 1 )
354
+ }
355
+ } else {
356
+ None
357
+ }
358
+ } )
359
+ . collect ( ) ;
360
+ let mut cmd = Command :: new ( build. rustdoc ( compiler) ) ;
361
+ build. add_rustc_lib_path ( compiler, & mut cmd) ;
362
+ build. add_rust_test_threads ( & mut cmd) ;
363
+ cmd. arg ( "--test" ) ;
364
+ cmd. arg ( path) ;
365
+ cmd. env ( "RUSTC_BOOTSTRAP" , "1" ) ;
366
+
367
+ cmd. arg ( "--test-args" ) . arg ( build. flags . cmd . test_args ( ) . join ( " " ) ) ;
368
+
369
+ output ( & mut cmd) . split ( "\n " )
370
+ . filter ( |s| s. starts_with ( "test " ) )
371
+ . inspect ( |s| {
372
+ let tmp: Vec < & str > = s. split ( " - line " ) . collect ( ) ;
373
+ if tmp. len ( ) == 2 {
374
+ let line = usize:: from_str_radix ( tmp[ 1 ] . split ( " ..." )
375
+ . next ( )
376
+ . unwrap_or ( "0" ) , 10 )
377
+ . unwrap_or ( 0 ) ;
378
+ if let Ok ( pos) = v. binary_search ( & line) {
379
+ v. remove ( pos) ;
380
+ } else {
381
+ panic ! ( "Not found doc test: \" {}\" in {:?}" , s, v) ;
382
+ }
383
+ }
384
+ } ) . all ( |_| true ) ;
385
+ if v. len ( ) != 0 {
386
+ panic ! ( "Not found test at line{} {:?}" , if v. len( ) > 1 { "s" } else { "" } , v) ;
387
+ }
388
+ }
389
+
319
390
/// Run all unit tests plus documentation tests for an entire crate DAG defined
320
391
/// by a `Cargo.toml`
321
392
///
0 commit comments