@@ -1289,9 +1289,9 @@ macro_rules! test_definitions {
1289
1289
/// Adapted from [`test_definitions`].
1290
1290
macro_rules! coverage_test_alias {
1291
1291
( $name: ident {
1292
- alias_and_mode: $alias_and_mode: expr,
1293
- default : $default: expr,
1294
- only_hosts: $only_hosts: expr $( , ) ?
1292
+ alias_and_mode: $alias_and_mode: expr, // &'static str
1293
+ default : $default: expr, // bool
1294
+ only_hosts: $only_hosts: expr $( , ) ? // bool
1295
1295
} ) => {
1296
1296
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1297
1297
pub struct $name {
@@ -1309,6 +1309,8 @@ macro_rules! coverage_test_alias {
1309
1309
const ONLY_HOSTS : bool = $only_hosts;
1310
1310
1311
1311
fn should_run( run: ShouldRun <' _>) -> ShouldRun <' _> {
1312
+ // Register the mode name as a command-line alias.
1313
+ // This allows `x test coverage-map` and `x test coverage-run`.
1312
1314
run. alias( $alias_and_mode)
1313
1315
}
1314
1316
@@ -1319,8 +1321,7 @@ macro_rules! coverage_test_alias {
1319
1321
}
1320
1322
1321
1323
fn run( self , builder: & Builder <' _>) {
1322
- Coverage { compiler: self . compiler, target: self . target }
1323
- . run_unified_suite( builder, Self :: MODE )
1324
+ Coverage :: run_coverage_tests( builder, self . compiler, self . target, Self :: MODE ) ;
1324
1325
}
1325
1326
}
1326
1327
} ;
@@ -1449,11 +1450,20 @@ host_test!(RunMakeFullDeps {
1449
1450
1450
1451
default_test ! ( Assembly { path: "tests/assembly" , mode: "assembly" , suite: "assembly" } ) ;
1451
1452
1452
- /// Custom test step that is responsible for running the coverage tests
1453
- /// in multiple different modes.
1453
+ /// Coverage tests are a bit more complicated than other test suites, because
1454
+ /// we want to run the same set of test files in multiple different modes,
1455
+ /// in a way that's convenient and flexible when invoked manually.
1456
+ ///
1457
+ /// This combined step runs the specified tests (or all of `tests/coverage`)
1458
+ /// in both "coverage-map" and "coverage-run" modes.
1459
+ ///
1460
+ /// Used by:
1461
+ /// - `x test coverage`
1462
+ /// - `x test tests/coverage`
1463
+ /// - `x test tests/coverage/trivial.rs` (etc)
1454
1464
///
1455
- /// Each individual mode also has its own alias that will run the tests in
1456
- /// just that mode.
1465
+ /// ( Each individual mode also has its own step that will run the tests in
1466
+ /// just that mode.)
1457
1467
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1458
1468
pub struct Coverage {
1459
1469
pub compiler : Compiler ,
@@ -1464,24 +1474,41 @@ impl Coverage {
1464
1474
const PATH : & ' static str = "tests/coverage" ;
1465
1475
const SUITE : & ' static str = "coverage" ;
1466
1476
1467
- fn run_unified_suite ( & self , builder : & Builder < ' _ > , mode : & ' static str ) {
1477
+ /// Runs the coverage test suite (or a user-specified subset) in one mode.
1478
+ ///
1479
+ /// This same function is used by the multi-mode step ([`Coverage`]) and by
1480
+ /// the single-mode steps ([`CoverageMap`] and [`CoverageRun`]), to help
1481
+ /// ensure that they all behave consistently with each other, regardless of
1482
+ /// how the coverage tests have been invoked.
1483
+ fn run_coverage_tests (
1484
+ builder : & Builder < ' _ > ,
1485
+ compiler : Compiler ,
1486
+ target : TargetSelection ,
1487
+ mode : & ' static str ,
1488
+ ) {
1489
+ // Like many other test steps, we delegate to a `Compiletest` step to
1490
+ // actually run the tests. (See `test_definitions!`.)
1468
1491
builder. ensure ( Compiletest {
1469
- compiler : self . compiler ,
1470
- target : self . target ,
1492
+ compiler,
1493
+ target,
1471
1494
mode,
1472
1495
suite : Self :: SUITE ,
1473
1496
path : Self :: PATH ,
1474
1497
compare_mode : None ,
1475
- } )
1498
+ } ) ;
1476
1499
}
1477
1500
}
1478
1501
1479
1502
impl Step for Coverage {
1480
1503
type Output = ( ) ;
1504
+ // We rely on the individual CoverageMap/CoverageRun steps to run themselves.
1481
1505
const DEFAULT : bool = false ;
1506
+ // When manually invoked, try to run as much as possible.
1507
+ // Compiletest will automatically skip the "coverage-run" tests if necessary.
1482
1508
const ONLY_HOSTS : bool = false ;
1483
1509
1484
1510
fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1511
+ // Take responsibility for command-line paths within `tests/coverage`.
1485
1512
run. suite_path ( Self :: PATH )
1486
1513
}
1487
1514
@@ -1492,20 +1519,26 @@ impl Step for Coverage {
1492
1519
}
1493
1520
1494
1521
fn run ( self , builder : & Builder < ' _ > ) {
1495
- self . run_unified_suite ( builder, CoverageMap :: MODE ) ;
1496
- self . run_unified_suite ( builder, CoverageRun :: MODE ) ;
1522
+ // Run the specified coverage tests (possibly all of them) in both modes.
1523
+ Self :: run_coverage_tests ( builder, self . compiler , self . target , CoverageMap :: MODE ) ;
1524
+ Self :: run_coverage_tests ( builder, self . compiler , self . target , CoverageRun :: MODE ) ;
1497
1525
}
1498
1526
}
1499
1527
1500
- // Aliases for running the coverage tests in only one mode.
1528
+ // Runs `tests/coverage` in "coverage-map" mode only.
1529
+ // Used by `x test` and `x test coverage-map`.
1501
1530
coverage_test_alias ! ( CoverageMap {
1502
1531
alias_and_mode: "coverage-map" ,
1503
1532
default : true ,
1504
1533
only_hosts: false ,
1505
1534
} ) ;
1535
+ // Runs `tests/coverage` in "coverage-run" mode only.
1536
+ // Used by `x test` and `x test coverage-run`.
1506
1537
coverage_test_alias ! ( CoverageRun {
1507
1538
alias_and_mode: "coverage-run" ,
1508
1539
default : true ,
1540
+ // Compiletest knows how to automatically skip these tests when cross-compiling,
1541
+ // but skipping the whole step here makes it clearer that they haven't run at all.
1509
1542
only_hosts: true ,
1510
1543
} ) ;
1511
1544
0 commit comments