diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index e2a04b7e558..df8c8047050 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -1,4 +1,4 @@ -use crate::common::{CompareMode, Config, Debugger}; +use crate::common::{CompareMode, Config, Debugger, Mode}; use crate::header::IgnoreDecision; use std::collections::HashSet; @@ -208,6 +208,17 @@ macro_rules! condition { }, message: "when comparing with {name}", } + // Coverage tests run the same test file in multiple modes. + // If a particular test should not be run in one of the modes, ignore it + // with "ignore-mode-coverage-map" or "ignore-mode-coverage-run". + condition! { + name: format!("mode-{}", config.mode.to_str()), + allowed_names: ContainsPrefixed { + prefix: "mode-", + inner: Mode::STR_VARIANTS, + }, + message: "when the test mode is {name}", + } if prefix == "ignore" && outcome == MatchOutcome::Invalid { // Don't error out for ignore-tidy-* diretives, as those are not handled by compiletest. diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index c6d63f7419f..8882f1582ac 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -1,7 +1,8 @@ use std::io::Read; use std::path::Path; +use std::str::FromStr; -use crate::common::{Config, Debugger}; +use crate::common::{Config, Debugger, Mode}; use crate::header::{parse_normalization_string, EarlyProps, HeadersCache}; fn make_test_description( @@ -55,6 +56,7 @@ fn test_parse_normalization_string() { #[derive(Default)] struct ConfigBuilder { + mode: Option, channel: Option, host: Option, target: Option, @@ -66,6 +68,11 @@ struct ConfigBuilder { } impl ConfigBuilder { + fn mode(&mut self, s: &str) -> &mut Self { + self.mode = Some(s.to_owned()); + self + } + fn channel(&mut self, s: &str) -> &mut Self { self.channel = Some(s.to_owned()); self @@ -109,7 +116,8 @@ fn profiler_support(&mut self, s: bool) -> &mut Self { fn build(&mut self) -> Config { let args = &[ "compiletest", - "--mode=ui", + "--mode", + self.mode.as_deref().unwrap_or("ui"), "--suite=ui", "--compile-lib-path=", "--run-lib-path=", @@ -548,3 +556,17 @@ fn families() { assert!(!check_ignore(&config, &format!("// ignore-{other}"))); } } + +#[test] +fn ignore_mode() { + for &mode in Mode::STR_VARIANTS { + // Indicate profiler support so that "coverage-run" tests aren't skipped. + let config: Config = cfg().mode(mode).profiler_support(true).build(); + let other = if mode == "coverage-run" { "coverage-map" } else { "coverage-run" }; + assert_ne!(mode, other); + assert_eq!(config.mode, Mode::from_str(mode).unwrap()); + assert_ne!(config.mode, Mode::from_str(other).unwrap()); + assert!(check_ignore(&config, &format!("// ignore-mode-{mode}"))); + assert!(!check_ignore(&config, &format!("// ignore-mode-{other}"))); + } +} diff --git a/tests/coverage/ignore_map.coverage b/tests/coverage/ignore_map.coverage new file mode 100644 index 00000000000..04bcb5bec6e --- /dev/null +++ b/tests/coverage/ignore_map.coverage @@ -0,0 +1,4 @@ + LL| |// ignore-mode-coverage-map + LL| | + LL| 1|fn main() {} + diff --git a/tests/coverage/ignore_map.rs b/tests/coverage/ignore_map.rs new file mode 100644 index 00000000000..71b82e8fc9d --- /dev/null +++ b/tests/coverage/ignore_map.rs @@ -0,0 +1,3 @@ +// ignore-mode-coverage-map + +fn main() {} diff --git a/tests/coverage/ignore_run.cov-map b/tests/coverage/ignore_run.cov-map new file mode 100644 index 00000000000..9865efae0a1 --- /dev/null +++ b/tests/coverage/ignore_run.cov-map @@ -0,0 +1,8 @@ +Function name: ignore_run::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 01, 00, 0d] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 13) + diff --git a/tests/coverage/ignore_run.rs b/tests/coverage/ignore_run.rs new file mode 100644 index 00000000000..87108867a05 --- /dev/null +++ b/tests/coverage/ignore_run.rs @@ -0,0 +1,3 @@ +// ignore-mode-coverage-run + +fn main() {}