@@ -366,17 +366,21 @@ fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Com
366
366
command
367
367
}
368
368
369
+ pub ( crate ) struct DocTestInfo {
370
+ line_offset : usize ,
371
+ line : usize ,
372
+ path : PathBuf ,
373
+ }
374
+
369
375
fn run_test (
370
376
test : String ,
371
377
supports_color : bool ,
372
- line_offset : usize ,
373
- line : usize ,
378
+ test_info : Option < DocTestInfo > ,
374
379
rustdoc_options : Arc < IndividualTestOptions > ,
375
380
is_multiple_tests : bool ,
376
381
outdir : Arc < DirState > ,
377
382
mut lang_string : LangString ,
378
383
edition : Edition ,
379
- path : PathBuf ,
380
384
report_unused_externs : impl Fn ( UnusedExterns ) ,
381
385
) -> Result < ( ) , TestFailure > {
382
386
// Make sure we emit well-formed executable names for our target.
@@ -396,8 +400,13 @@ fn run_test(
396
400
}
397
401
398
402
compiler. arg ( "--edition" ) . arg ( & edition. to_string ( ) ) ;
399
- compiler. env ( "UNSTABLE_RUSTDOC_TEST_PATH" , path) ;
400
- compiler. env ( "UNSTABLE_RUSTDOC_TEST_LINE" , format ! ( "{}" , line as isize - line_offset as isize ) ) ;
403
+ if let Some ( test_info) = test_info {
404
+ compiler. env ( "UNSTABLE_RUSTDOC_TEST_PATH" , test_info. path ) ;
405
+ compiler. env (
406
+ "UNSTABLE_RUSTDOC_TEST_LINE" ,
407
+ format ! ( "{}" , test_info. line as isize - test_info. line_offset as isize ) ,
408
+ ) ;
409
+ }
401
410
compiler. arg ( "-o" ) . arg ( & output_file) ;
402
411
if lang_string. test_harness {
403
412
compiler. arg ( "--test" ) ;
@@ -576,11 +585,14 @@ pub(crate) struct DocTest {
576
585
name : String ,
577
586
lang_string : LangString ,
578
587
line : usize ,
588
+ // Path that will be displayed if the test failed to compile.
589
+ path : PathBuf ,
579
590
file : String ,
580
591
failed_ast : bool ,
581
592
test_id : String ,
582
593
outdir : Arc < DirState > ,
583
594
rustdoc_test_options : Arc < IndividualTestOptions > ,
595
+ no_run : bool ,
584
596
}
585
597
586
598
impl DocTest {
@@ -698,12 +710,11 @@ impl DocTest {
698
710
mut self ,
699
711
opts : & GlobalTestOptions ,
700
712
edition : Edition ,
701
- path : PathBuf ,
702
713
unused_externs : Arc < Mutex < Vec < UnusedExterns > > > ,
703
714
) -> TestDescAndFn {
704
715
let ( code, line_offset) =
705
716
self . generate_unique_doctest ( self . lang_string . test_harness , opts, Some ( & self . test_id ) ) ;
706
- let Self { supports_color, rustdoc_test_options, lang_string, outdir, .. } = self ;
717
+ let Self { supports_color, rustdoc_test_options, lang_string, outdir, path , .. } = self ;
707
718
TestDescAndFn {
708
719
desc : test:: TestDesc {
709
720
name : test:: DynTestName ( std:: mem:: replace ( & mut self . name , String :: new ( ) ) ) ,
@@ -727,14 +738,12 @@ impl DocTest {
727
738
let res = run_test (
728
739
code,
729
740
supports_color,
730
- line_offset,
731
- self . line ,
741
+ Some ( DocTestInfo { line_offset, line : self . line , path } ) ,
732
742
rustdoc_test_options,
733
743
false ,
734
744
outdir,
735
745
lang_string,
736
746
edition,
737
- path,
738
747
report_unused_externs,
739
748
) ;
740
749
@@ -849,7 +858,7 @@ pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
849
858
should_panic = if self . lang_string. should_panic { "Yes" } else { "No" } ,
850
859
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
851
860
// don't give it the function to run.
852
- runner = if self . lang_string . no_run { "Ok::<(), String>(())" } else { "self::main()" } ,
861
+ runner = if self . no_run { "Ok::<(), String>(())" } else { "self::main()" } ,
853
862
)
854
863
. unwrap ( ) ;
855
864
test_id
@@ -869,6 +878,8 @@ pub(crate) fn make_test(
869
878
rustdoc_test_options : Arc < IndividualTestOptions > ,
870
879
test_id : String ,
871
880
target_str : & str ,
881
+ path : PathBuf ,
882
+ no_run : bool ,
872
883
) -> DocTest {
873
884
let outdir = Arc :: new ( if let Some ( ref path) = rustdoc_test_options. persist_doctests {
874
885
let mut path = path. clone ( ) ;
@@ -1004,6 +1015,8 @@ pub(crate) fn make_test(
1004
1015
rustdoc_test_options,
1005
1016
outdir,
1006
1017
test_id,
1018
+ path,
1019
+ no_run,
1007
1020
} ;
1008
1021
} ;
1009
1022
@@ -1041,6 +1054,8 @@ pub(crate) fn make_test(
1041
1054
rustdoc_test_options,
1042
1055
outdir,
1043
1056
test_id,
1057
+ path,
1058
+ no_run,
1044
1059
}
1045
1060
}
1046
1061
@@ -1255,7 +1270,6 @@ impl DocTestKinds {
1255
1270
doctest : DocTest ,
1256
1271
opts : & GlobalTestOptions ,
1257
1272
edition : Edition ,
1258
- path : PathBuf ,
1259
1273
unused_externs : & Arc < Mutex < Vec < UnusedExterns > > > ,
1260
1274
) {
1261
1275
if doctest. failed_ast
@@ -1267,7 +1281,6 @@ impl DocTestKinds {
1267
1281
self . standalone . push ( doctest. generate_test_desc_and_fn (
1268
1282
opts,
1269
1283
edition,
1270
- path,
1271
1284
Arc :: clone ( unused_externs) ,
1272
1285
) ) ;
1273
1286
} else {
@@ -1327,32 +1340,31 @@ fn main() {{
1327
1340
if let Err ( TestFailure :: CompileError ) = run_test (
1328
1341
output,
1329
1342
supports_color,
1330
- 0 ,
1331
- 0 ,
1343
+ None ,
1332
1344
rustdoc_test_options,
1333
1345
true ,
1334
1346
outdir,
1335
1347
LangString :: empty_for_test ( ) ,
1336
1348
edition,
1337
- PathBuf :: from ( format ! ( "doctest_edition_{edition}.rs" ) ) ,
1338
1349
|_: UnusedExterns | { } ,
1339
1350
) {
1340
1351
// We failed to compile all compatible tests as one so we push them into the
1341
1352
// "standalone" doctests.
1342
1353
debug ! ( "Failed to compile compatible doctests for edition {edition} all at once" ) ;
1343
- for ( pos , doctest) in doctests. into_iter ( ) . enumerate ( ) {
1354
+ for doctest in doctests {
1344
1355
standalone. push ( doctest. generate_test_desc_and_fn (
1345
1356
& opts,
1346
1357
edition,
1347
- format ! ( "doctest_{edition}_{pos}" ) . into ( ) ,
1348
1358
Arc :: clone ( unused_externs) ,
1349
1359
) ) ;
1350
1360
}
1351
1361
}
1352
1362
}
1353
1363
1354
- standalone. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( & b. desc . name . as_slice ( ) ) ) ;
1355
- test:: test_main ( & test_args, standalone, None ) ;
1364
+ if !standalone. is_empty ( ) {
1365
+ standalone. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( & b. desc . name . as_slice ( ) ) ) ;
1366
+ test:: test_main ( & test_args, standalone, None ) ;
1367
+ }
1356
1368
}
1357
1369
}
1358
1370
@@ -1465,7 +1477,7 @@ impl Tester for Collector {
1465
1477
let opts = self . opts . clone ( ) ;
1466
1478
let edition = config. edition . unwrap_or ( self . rustdoc_options . edition ) ;
1467
1479
let target_str = self . rustdoc_options . target . to_string ( ) ;
1468
- // let no_run = config.no_run || self.rustdoc_options.no_run;
1480
+ let no_run = config. no_run || self . rustdoc_options . no_run ;
1469
1481
if !config. compile_fail {
1470
1482
self . compiling_test_count . fetch_add ( 1 , Ordering :: SeqCst ) ;
1471
1483
}
@@ -1510,8 +1522,10 @@ impl Tester for Collector {
1510
1522
Arc :: clone ( & self . rustdoc_test_options ) ,
1511
1523
test_id,
1512
1524
& target_str,
1525
+ path,
1526
+ no_run,
1513
1527
) ;
1514
- self . tests . add_doctest ( doctest, & opts, edition, path , & self . unused_extern_reports ) ;
1528
+ self . tests . add_doctest ( doctest, & opts, edition, & self . unused_extern_reports ) ;
1515
1529
}
1516
1530
1517
1531
fn get_line ( & self ) -> usize {
0 commit comments