@@ -1289,9 +1289,9 @@ macro_rules! test_definitions {
12891289/// Adapted from [`test_definitions`].
12901290macro_rules! coverage_test_alias {
12911291 ( $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
12951295 } ) => {
12961296 #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
12971297 pub struct $name {
@@ -1309,6 +1309,8 @@ macro_rules! coverage_test_alias {
13091309 const ONLY_HOSTS : bool = $only_hosts;
13101310
13111311 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`.
13121314 run. alias( $alias_and_mode)
13131315 }
13141316
@@ -1319,8 +1321,7 @@ macro_rules! coverage_test_alias {
13191321 }
13201322
13211323 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 ) ;
13241325 }
13251326 }
13261327 } ;
@@ -1449,11 +1450,15 @@ host_test!(RunMakeFullDeps {
14491450
14501451default_test ! ( Assembly { path: "tests/assembly" , mode: "assembly" , suite: "assembly" } ) ;
14511452
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. Used by `x test coverage`.
14541459///
1455- /// Each individual mode also has its own alias that will run the tests in
1456- /// just that mode.
1460+ /// ( Each individual mode also has its own step that will run the tests in
1461+ /// just that mode.)
14571462#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
14581463pub struct Coverage {
14591464 pub compiler : Compiler ,
@@ -1464,24 +1469,41 @@ impl Coverage {
14641469 const PATH : & ' static str = "tests/coverage" ;
14651470 const SUITE : & ' static str = "coverage" ;
14661471
1467- fn run_unified_suite ( & self , builder : & Builder < ' _ > , mode : & ' static str ) {
1472+ /// Runs the coverage test suite (or a user-specified subset) in one mode.
1473+ ///
1474+ /// This same function is used by the multi-mode step ([`Coverage`]) and by
1475+ /// the single-mode steps ([`CoverageMap`] and [`CoverageRun`]), to help
1476+ /// ensure that they all behave consistently with each other, regardless of
1477+ /// how the coverage tests have been invoked.
1478+ fn run_coverage_tests (
1479+ builder : & Builder < ' _ > ,
1480+ compiler : Compiler ,
1481+ target : TargetSelection ,
1482+ mode : & ' static str ,
1483+ ) {
1484+ // Like many other test steps, we delegate to a `Compiletest` step to
1485+ // actually run the tests. (See `test_definitions!`.)
14681486 builder. ensure ( Compiletest {
1469- compiler : self . compiler ,
1470- target : self . target ,
1487+ compiler,
1488+ target,
14711489 mode,
14721490 suite : Self :: SUITE ,
14731491 path : Self :: PATH ,
14741492 compare_mode : None ,
1475- } )
1493+ } ) ;
14761494 }
14771495}
14781496
14791497impl Step for Coverage {
14801498 type Output = ( ) ;
1499+ // We rely on the individual CoverageMap/CoverageRun steps to run themselves.
14811500 const DEFAULT : bool = false ;
1501+ // When manually invoked, try to run as much as possible.
1502+ // Compiletest will automatically skip the "coverage-run" tests if necessary.
14821503 const ONLY_HOSTS : bool = false ;
14831504
14841505 fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1506+ // Take responsibility for command-line paths within `tests/coverage`.
14851507 run. suite_path ( Self :: PATH )
14861508 }
14871509
@@ -1492,20 +1514,27 @@ impl Step for Coverage {
14921514 }
14931515
14941516 fn run ( self , builder : & Builder < ' _ > ) {
1495- self . run_unified_suite ( builder, CoverageMap :: MODE ) ;
1496- self . run_unified_suite ( builder, CoverageRun :: MODE ) ;
1517+ // Run the specified coverage tests (possibly all of them) in both modes.
1518+ for mode in [ CoverageMap :: MODE , CoverageRun :: MODE ] {
1519+ Self :: run_coverage_tests ( builder, self . compiler , self . target , mode) ;
1520+ }
14971521 }
14981522}
14991523
1500- // Aliases for running the coverage tests in only one mode.
1524+ // Runs `tests/coverage` in "coverage-map" mode only.
1525+ // Used by `x test` and `x test coverage-map`.
15011526coverage_test_alias ! ( CoverageMap {
15021527 alias_and_mode: "coverage-map" ,
15031528 default : true ,
15041529 only_hosts: false ,
15051530} ) ;
1531+ // Runs `tests/coverage` in "coverage-run" mode only.
1532+ // Used by `x test` and `x test coverage-run`.
15061533coverage_test_alias ! ( CoverageRun {
15071534 alias_and_mode: "coverage-run" ,
15081535 default : true ,
1536+ // Compiletest knows how to automatically skip these tests when cross-compiling,
1537+ // but skipping the whole step here makes it clearer that they haven't run at all.
15091538 only_hosts: true ,
15101539} ) ;
15111540
0 commit comments