@@ -382,6 +382,7 @@ fn run_test(
382
382
mut lang_string : LangString ,
383
383
edition : Edition ,
384
384
report_unused_externs : impl Fn ( UnusedExterns ) ,
385
+ no_run : bool ,
385
386
) -> Result < ( ) , TestFailure > {
386
387
// Make sure we emit well-formed executable names for our target.
387
388
let rust_out = add_exe_suffix ( "rust_out" . to_owned ( ) , & rustdoc_options. target ) ;
@@ -418,8 +419,7 @@ fn run_test(
418
419
compiler. arg ( "-Z" ) . arg ( "unstable-options" ) ;
419
420
}
420
421
421
- if lang_string. no_run && !lang_string. compile_fail && rustdoc_options. persist_doctests . is_none ( )
422
- {
422
+ if no_run && !lang_string. compile_fail && rustdoc_options. persist_doctests . is_none ( ) {
423
423
compiler. arg ( "--emit=metadata" ) ;
424
424
}
425
425
compiler. arg ( "--target" ) . arg ( match rustdoc_options. target {
@@ -459,7 +459,7 @@ fn run_test(
459
459
let stdin = child. stdin . as_mut ( ) . expect ( "Failed to open stdin" ) ;
460
460
stdin. write_all ( test. as_bytes ( ) ) . expect ( "could write out test sources" ) ;
461
461
}
462
- let output = if is_multiple_tests {
462
+ let output = if ! is_multiple_tests {
463
463
let status = child. wait ( ) . expect ( "Failed to wait" ) ;
464
464
process:: Output { status, stdout : Vec :: new ( ) , stderr : Vec :: new ( ) }
465
465
} else {
@@ -515,7 +515,7 @@ fn run_test(
515
515
}
516
516
}
517
517
518
- if lang_string . no_run {
518
+ if no_run {
519
519
return Ok ( ( ) ) ;
520
520
}
521
521
@@ -714,7 +714,9 @@ impl DocTest {
714
714
) -> TestDescAndFn {
715
715
let ( code, line_offset) =
716
716
self . generate_unique_doctest ( self . lang_string . test_harness , opts, Some ( & self . test_id ) ) ;
717
- let Self { supports_color, rustdoc_test_options, lang_string, outdir, path, .. } = self ;
717
+ let Self {
718
+ supports_color, rustdoc_test_options, lang_string, outdir, path, no_run, ..
719
+ } = self ;
718
720
TestDescAndFn {
719
721
desc : test:: TestDesc {
720
722
name : test:: DynTestName ( std:: mem:: replace ( & mut self . name , String :: new ( ) ) ) ,
@@ -728,7 +730,7 @@ impl DocTest {
728
730
// compiler failures are test failures
729
731
should_panic : test:: ShouldPanic :: No ,
730
732
compile_fail : lang_string. compile_fail ,
731
- no_run : lang_string . no_run ,
733
+ no_run,
732
734
test_type : test:: TestType :: DocTest ,
733
735
} ,
734
736
testfn : test:: DynTestFn ( Box :: new ( move || {
@@ -745,6 +747,7 @@ impl DocTest {
745
747
lang_string,
746
748
edition,
747
749
report_unused_externs,
750
+ no_run,
748
751
) ;
749
752
750
753
if let Err ( err) = res {
@@ -808,7 +811,9 @@ impl DocTest {
808
811
809
812
writeln ! ( output, "mod {test_id} {{\n {}" , self . crates) . unwrap ( ) ;
810
813
811
- if self . main_fn_span . is_some ( ) {
814
+ if self . ignore {
815
+ // We generate nothing.
816
+ } else if self . main_fn_span . is_some ( ) {
812
817
output. push_str ( & self . everything_else ) ;
813
818
} else {
814
819
let returns_result = if self . everything_else . trim_end ( ) . ends_with ( "(())" ) {
@@ -855,10 +860,11 @@ pub const TEST: test::TestDescAndFn = test::TestDescAndFn {{
855
860
ignore = self . ignore,
856
861
file = self . file,
857
862
line = self . line,
858
- should_panic = if self . lang_string. should_panic { "Yes" } else { "No" } ,
863
+ should_panic = if ! self . no_run && self . lang_string. should_panic { "Yes" } else { "No" } ,
859
864
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
860
865
// don't give it the function to run.
861
- runner = if self . no_run { "Ok::<(), String>(())" } else { "self::main()" } ,
866
+ runner =
867
+ if self . no_run || self . ignore { "Ok::<(), String>(())" } else { "self::main()" } ,
862
868
)
863
869
. unwrap ( ) ;
864
870
test_id
@@ -936,10 +942,11 @@ pub(crate) fn make_test(
936
942
Ok ( p) => p,
937
943
Err ( errs) => {
938
944
errs. into_iter ( ) . for_each ( |err| err. cancel ( ) ) ;
939
- return ( found_main, found_extern_crate, found_macro) ;
945
+ return ( found_main, found_extern_crate, found_macro, true ) ;
940
946
}
941
947
} ;
942
948
949
+ let mut has_errors = false ;
943
950
loop {
944
951
match parser. parse_item ( ForceCollect :: No ) {
945
952
Ok ( Some ( item) ) => {
@@ -970,6 +977,7 @@ pub(crate) fn make_test(
970
977
Ok ( None ) => break ,
971
978
Err ( e) => {
972
979
e. cancel ( ) ;
980
+ has_errors = true ;
973
981
break ;
974
982
}
975
983
}
@@ -979,13 +987,14 @@ pub(crate) fn make_test(
979
987
parser. maybe_consume_incorrect_semicolon ( & [ ] ) ;
980
988
}
981
989
990
+ has_errors = has_errors || psess. dcx . has_errors_or_delayed_bugs ( ) . is_some ( ) ;
982
991
// Reset errors so that they won't be reported as compiler bugs when dropping the
983
992
// dcx. Any errors in the tests will be reported when the test file is compiled,
984
993
// Note that we still need to cancel the errors above otherwise `Diag` will panic on
985
994
// drop.
986
995
psess. dcx . reset_err_count ( ) ;
987
996
988
- ( found_main, found_extern_crate, found_macro)
997
+ ( found_main, found_extern_crate, found_macro, has_errors )
989
998
} )
990
999
} ) ;
991
1000
@@ -994,7 +1003,7 @@ pub(crate) fn make_test(
994
1003
Ignore :: None => false ,
995
1004
Ignore :: Some ( ref ignores) => ignores. iter ( ) . any ( |s| target_str. contains ( s) ) ,
996
1005
} ;
997
- let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro) ) = result else {
1006
+ let Ok ( ( mut main_fn_span, already_has_extern_crate, found_macro, has_errors ) ) = result else {
998
1007
// If the parser panicked due to a fatal error, pass the test code through unchanged.
999
1008
// The error will be reported during compilation.
1000
1009
return DocTest {
@@ -1050,7 +1059,7 @@ pub(crate) fn make_test(
1050
1059
lang_string,
1051
1060
line,
1052
1061
file,
1053
- failed_ast : false ,
1062
+ failed_ast : has_errors ,
1054
1063
rustdoc_test_options,
1055
1064
outdir,
1056
1065
test_id,
@@ -1197,7 +1206,6 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) {
1197
1206
( before, after. trim ( ) . to_owned ( ) , crates)
1198
1207
}
1199
1208
1200
- #[ derive( Clone ) ]
1201
1209
pub ( crate ) struct IndividualTestOptions {
1202
1210
test_builder : Option < PathBuf > ,
1203
1211
test_builder_wrappers : Vec < PathBuf > ,
@@ -1275,7 +1283,6 @@ impl DocTestKinds {
1275
1283
if doctest. failed_ast
1276
1284
|| doctest. lang_string . compile_fail
1277
1285
|| doctest. lang_string . test_harness
1278
- || doctest. ignore
1279
1286
|| doctest. crate_attrs . contains ( "#![no_std]" )
1280
1287
{
1281
1288
self . standalone . push ( doctest. generate_test_desc_and_fn (
@@ -1300,6 +1307,7 @@ impl DocTestKinds {
1300
1307
test_args. push ( "--nocapture" . to_string ( ) ) ;
1301
1308
}
1302
1309
let Self { mut standalone, others } = self ;
1310
+ let mut ran_edition_tests = 0 ;
1303
1311
1304
1312
for ( edition, mut doctests) in others {
1305
1313
doctests. sort_by ( |a, b| a. name . cmp ( & b. name ) ) ;
@@ -1323,17 +1331,18 @@ impl DocTestKinds {
1323
1331
if !ids. is_empty ( ) {
1324
1332
ids. push ( ',' ) ;
1325
1333
}
1326
- ids. push_str ( & format ! ( "& {}::TEST" , doctest. generate_test_desc( pos, & mut output) ) ) ;
1334
+ ids. push_str ( & format ! ( "{}::TEST" , doctest. generate_test_desc( pos, & mut output) ) ) ;
1327
1335
supports_color &= doctest. supports_color ;
1328
1336
}
1337
+ let test_args =
1338
+ test_args. iter ( ) . map ( |arg| format ! ( "{arg:?}.to_string()," ) ) . collect :: < String > ( ) ;
1329
1339
write ! (
1330
1340
output,
1331
1341
"\
1332
1342
#[rustc_main]
1333
1343
#[coverage(off)]
1334
1344
fn main() {{
1335
- test::test_main_static(&[{ids}]);
1336
- panic!(\" fuck\" );
1345
+ test::test_main(&[{test_args}], vec![{ids}], None);
1337
1346
}}" ,
1338
1347
)
1339
1348
. unwrap ( ) ;
@@ -1347,6 +1356,7 @@ fn main() {{
1347
1356
LangString :: empty_for_test ( ) ,
1348
1357
edition,
1349
1358
|_: UnusedExterns | { } ,
1359
+ false ,
1350
1360
) {
1351
1361
// We failed to compile all compatible tests as one so we push them into the
1352
1362
// "standalone" doctests.
@@ -1358,10 +1368,12 @@ fn main() {{
1358
1368
Arc :: clone ( unused_externs) ,
1359
1369
) ) ;
1360
1370
}
1371
+ } else {
1372
+ ran_edition_tests += 1 ;
1361
1373
}
1362
1374
}
1363
1375
1364
- if !standalone. is_empty ( ) {
1376
+ if ran_edition_tests == 0 || !standalone. is_empty ( ) {
1365
1377
standalone. sort_by ( |a, b| a. desc . name . as_slice ( ) . cmp ( & b. desc . name . as_slice ( ) ) ) ;
1366
1378
test:: test_main ( & test_args, standalone, None ) ;
1367
1379
}
0 commit comments