@@ -287,6 +287,7 @@ pub fn compute_stamp_hash(config: &Config) -> String {
287
287
format ! ( "{:x}" , hash. finish( ) )
288
288
}
289
289
290
+ #[ derive( Copy , Clone ) ]
290
291
struct TestCx < ' test > {
291
292
config : & ' test Config ,
292
293
props : & ' test TestProps ,
@@ -2208,7 +2209,12 @@ impl<'test> TestCx<'test> {
2208
2209
2209
2210
fn fatal_proc_rec ( & self , err : & str , proc_res : & ProcRes ) -> ! {
2210
2211
self . error ( err) ;
2211
- proc_res. fatal ( None ) ;
2212
+ proc_res. fatal ( None , || ( ) ) ;
2213
+ }
2214
+
2215
+ fn fatal_proc_rec_with_ctx ( & self , err : & str , proc_res : & ProcRes , ctx : impl FnOnce ( Self ) ) -> ! {
2216
+ self . error ( err) ;
2217
+ proc_res. fatal ( None , || ctx ( * self ) ) ;
2212
2218
}
2213
2219
2214
2220
// codegen tests (using FileCheck)
@@ -2325,15 +2331,72 @@ impl<'test> TestCx<'test> {
2325
2331
let res = self . cmd2procres (
2326
2332
Command :: new ( & self . config . docck_python )
2327
2333
. arg ( root. join ( "src/etc/htmldocck.py" ) )
2328
- . arg ( out_dir)
2334
+ . arg ( & out_dir)
2329
2335
. arg ( & self . testpaths . file ) ,
2330
2336
) ;
2331
2337
if !res. status . success ( ) {
2332
- self . fatal_proc_rec ( "htmldocck failed!" , & res) ;
2338
+ self . fatal_proc_rec_with_ctx ( "htmldocck failed!" , & res, |mut this| {
2339
+ this. compare_to_default_rustdoc ( & out_dir)
2340
+ } ) ;
2333
2341
}
2334
2342
}
2335
2343
}
2336
2344
2345
+ fn compare_to_default_rustdoc ( & mut self , out_dir : & Path ) {
2346
+ println ! ( "info: generating a diff against nightly rustdoc" ) ;
2347
+
2348
+ let suffix =
2349
+ self . safe_revision ( ) . map_or ( "nightly" . into ( ) , |path| path. to_owned ( ) + "-nightly" ) ;
2350
+ let compare_dir = output_base_dir ( self . config , self . testpaths , Some ( & suffix) ) ;
2351
+ let _ = fs:: remove_dir_all ( & compare_dir) ;
2352
+ create_dir_all ( & compare_dir) . unwrap ( ) ;
2353
+
2354
+ // We need to create a new struct for the lifetimes on `config` to work.
2355
+ let new_rustdoc = TestCx {
2356
+ config : & Config {
2357
+ // FIXME: use beta or a user-specified rustdoc instead of hardcoding
2358
+ // the default toolchain
2359
+ rustdoc_path : Some ( "rustdoc" . into ( ) ) ,
2360
+ ..self . config . clone ( )
2361
+ } ,
2362
+ ..* self
2363
+ } ;
2364
+ let proc_res = new_rustdoc. document ( & compare_dir) ;
2365
+ if !proc_res. status . success ( ) {
2366
+ proc_res. fatal ( Some ( "failed to run nightly rustdoc" ) , || ( ) ) ;
2367
+ }
2368
+
2369
+ // NOTE: this is fine since compiletest never runs out-of-tree
2370
+ let tidy = concat ! ( env!( "CARGO_MANIFEST_DIR" ) , "/tidy-rustdoc.sh" ) ;
2371
+ // FIXME: this overwrites `out_dir` in place, maybe we should make a copy?
2372
+ let status = Command :: new ( tidy)
2373
+ . arg ( out_dir)
2374
+ . spawn ( )
2375
+ . expect ( "tidy-rustdoc not found" )
2376
+ . wait ( )
2377
+ . unwrap ( ) ;
2378
+ if !status. success ( ) {
2379
+ self . fatal ( "failed to run tidy - is installed?" ) ;
2380
+ }
2381
+ let status = Command :: new ( tidy) . arg ( & compare_dir) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
2382
+ if !status. success ( ) {
2383
+ self . fatal ( "failed to run tidy" ) ;
2384
+ }
2385
+
2386
+ let diff_pid = Command :: new ( "diff" )
2387
+ . args ( & [ "-u" , "-r" ] )
2388
+ . args ( & [ out_dir, & compare_dir] )
2389
+ . stdout ( Stdio :: piped ( ) )
2390
+ . spawn ( )
2391
+ . expect ( "failed to run `diff`" ) ;
2392
+ Command :: new ( "delta" )
2393
+ . stdin ( diff_pid. stdout . unwrap ( ) )
2394
+ . spawn ( )
2395
+ . expect ( "delta not found" )
2396
+ . wait ( )
2397
+ . unwrap ( ) ;
2398
+ }
2399
+
2337
2400
fn get_lines < P : AsRef < Path > > (
2338
2401
& self ,
2339
2402
path : & P ,
@@ -3590,7 +3653,7 @@ pub struct ProcRes {
3590
3653
}
3591
3654
3592
3655
impl ProcRes {
3593
- pub fn fatal ( & self , err : Option < & str > ) -> ! {
3656
+ pub fn fatal ( & self , err : Option < & str > , ctx : impl FnOnce ( ) ) -> ! {
3594
3657
if let Some ( e) = err {
3595
3658
println ! ( "\n error: {}" , e) ;
3596
3659
}
@@ -3612,6 +3675,7 @@ impl ProcRes {
3612
3675
json:: extract_rendered( & self . stdout) ,
3613
3676
json:: extract_rendered( & self . stderr) ,
3614
3677
) ;
3678
+ ctx ( ) ;
3615
3679
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
3616
3680
// compiletest, which is unnecessary noise.
3617
3681
std:: panic:: resume_unwind ( Box :: new ( ( ) ) ) ;
0 commit comments