@@ -44,7 +44,7 @@ use crate::utils::helpers::{
4444 up_to_date,
4545} ;
4646use crate :: utils:: render_tests:: { add_flags_and_try_run_tests, try_run_tests} ;
47- use crate :: { CLang , CodegenBackendKind , GitRepo , Mode , PathSet , TestTarget , envify, exit} ;
47+ use crate :: { CLang , CodegenBackendKind , GitRepo , Mode , TestTarget , envify, exit} ;
4848
4949mod compiletest;
5050pub mod failed_tests;
@@ -1974,72 +1974,41 @@ impl Coverage {
19741974 const SUITE : & ' static str = "coverage" ;
19751975 const ALL_MODES : & [ CompiletestMode ] =
19761976 & [ CompiletestMode :: CoverageMap , CompiletestMode :: CoverageRun ] ;
1977+
1978+ fn new ( run : & RunConfig < ' _ > , mode : CompiletestMode ) -> Self {
1979+ let compiler = run. builder . compiler ( run. builder . top_stage , run. build_triple ( ) ) ;
1980+ let target = run. target ;
1981+ Coverage { compiler, target, mode }
1982+ }
19771983}
19781984
19791985impl CommandLineStep for Coverage {
19801986 type Output = ( ) ;
19811987 /// Compiletest will automatically skip the "coverage-run" tests if necessary.
19821988 const IS_HOST : bool = false ;
19831989
1984- fn should_run ( mut run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1985- // Support various invocation styles, including:
1990+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
1991+ // Handle these invocation styles:
1992+ // - `./x test` (including coverage tests)
19861993 // - `./x test coverage`
1994+ // - `./x test tests/coverage`
19871995 // - `./x test tests/coverage/trivial.rs`
1988- // - `./x test coverage-map`
1989- // - `./x test coverage-run -- tests/coverage/trivial.rs`
1990- run = run. suite_path ( Self :: PATH ) ;
1991- for mode in Self :: ALL_MODES {
1992- run = run. alias ( mode. as_str ( ) ) ;
1993- }
1994-
1995- // Allow `./x test --skip=tests` to properly skip the coverage tests,
1996- // by not treating the `coverage-map` and `coverage-run` aliases as
1997- // implied command-line arguments.
1998- run = run. default_to_suites_only ( ) ;
1999-
2000- run
1996+ // - `./x test tests/coverage/trivial.rs --skip=coverage-run`
1997+ run. suite_path ( Coverage :: PATH )
20011998 }
20021999
20032000 fn is_default_step ( _builder : & Builder < ' _ > ) -> bool {
20042001 true
20052002 }
20062003
20072004 fn make_run ( run : RunConfig < ' _ > ) {
2008- let compiler = run. builder . compiler ( run. builder . top_stage , run. build_triple ( ) ) ;
2009- let target = run. target ;
2010-
2011- // List of (coverage) test modes that the coverage test suite will be
2012- // run in. It's OK for this to contain duplicates, because the call to
2013- // `Builder::ensure` below will take care of deduplication.
2014- let mut modes = vec ! [ ] ;
2015-
2016- // From the pathsets that were selected on the command-line (or by default),
2017- // determine which modes to run in.
2018- for path in & run. paths {
2019- match path {
2020- PathSet :: Set ( _) => {
2021- for & mode in Self :: ALL_MODES {
2022- if path. assert_single_path ( ) . path == Path :: new ( mode. as_str ( ) ) {
2023- modes. push ( mode) ;
2024- break ;
2025- }
2026- }
2027- }
2028- PathSet :: Suite ( _) => {
2029- modes. extend_from_slice ( Self :: ALL_MODES ) ;
2030- break ;
2031- }
2032- }
2033- }
2034-
2035- // Skip any modes that were explicitly skipped/excluded on the command-line.
2005+ // Run the tests in all coverage-test modes, but skip any modes that
2006+ // were explicitly skipped on the command-line (e.g. `--skip=coverage-run`).
20362007 // FIXME(Zalathar): Integrate this into central skip handling somehow?
2037- modes. retain ( |mode| {
2038- !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode. as_str ( ) ) )
2039- } ) ;
2040-
2041- for mode in modes {
2042- run. builder . ensure ( Coverage { compiler, target, mode } ) ;
2008+ for & mode in Coverage :: ALL_MODES {
2009+ if !run. builder . config . skip . iter ( ) . any ( |skip| skip == Path :: new ( mode. as_str ( ) ) ) {
2010+ run. builder . ensure ( Coverage :: new ( & run, mode) ) ;
2011+ }
20432012 }
20442013 }
20452014
@@ -2058,6 +2027,49 @@ impl CommandLineStep for Coverage {
20582027 }
20592028}
20602029
2030+ /// Registers the `coverage-map` and `coverage-run` aliases, which are then
2031+ /// forwarded to the [`Coverage`] step.
2032+ ///
2033+ /// If the aliases were registered by [`Coverage`] directly, they would also
2034+ /// be treated as implied command-line arguments when run by default.
2035+ /// That would cause things like `./x test --skip=tests` to still run coverage
2036+ /// tests, which is undesirable.
2037+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2038+ pub enum CoverageModeAlias { }
2039+
2040+ impl CommandLineStep for CoverageModeAlias {
2041+ type Output = ( ) ;
2042+
2043+ fn should_run ( run : ShouldRun < ' _ > ) -> ShouldRun < ' _ > {
2044+ // Register the aliases "coverage-map" and "coverage-run", to handle
2045+ // these invocation styles:
2046+ // - `./x test coverage-map`
2047+ // - `./x test coverage-run -- tests/coverage/trivial.rs`
2048+ Coverage :: ALL_MODES . iter ( ) . fold ( run, |run, mode| run. alias ( mode. as_str ( ) ) )
2049+ }
2050+
2051+ fn is_default_step ( _builder : & Builder < ' _ > ) -> bool {
2052+ false
2053+ }
2054+
2055+ fn make_run ( run : RunConfig < ' _ > ) {
2056+ for path in & run. paths {
2057+ let single_path = & path. assert_single_path ( ) . path ;
2058+ for & mode in Coverage :: ALL_MODES {
2059+ if single_path == Path :: new ( mode. as_str ( ) ) {
2060+ // Instead of creating an intermediate `CoverageModeAlias`
2061+ // step instance, delegate straight to `Coverage`.
2062+ run. builder . ensure ( Coverage :: new ( & run, mode) ) ;
2063+ }
2064+ }
2065+ }
2066+ }
2067+
2068+ fn run ( self , _builder : & Builder < ' _ > ) {
2069+ unreachable ! ( "never instantiated; `make_run` creates a Coverage step instead" ) ;
2070+ }
2071+ }
2072+
20612073test ! ( CoverageRunRustdoc {
20622074 path: "tests/coverage-run-rustdoc" ,
20632075 mode: CompiletestMode :: CoverageRun ,
0 commit comments