Allow tests to ignore individual test modes

Normally, each test in `tests/coverage` is automatically run in both
`coverage-map` mode and `coverage-run` mode.

This new family of directives allows an individual test to specify that it
should not be run in a particular mode.
This commit is contained in:
Zalathar 2023-11-30 17:45:03 +11:00
parent f9df1ad4f2
commit aa4bf0bbf0
6 changed files with 54 additions and 3 deletions

View File

@ -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 @@ pub(super) fn parse_cfg_name_directive<'a>(
},
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.

View File

@ -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<R: Read>(
@ -55,6 +56,7 @@ fn test_parse_normalization_string() {
#[derive(Default)]
struct ConfigBuilder {
mode: Option<String>,
channel: Option<String>,
host: Option<String>,
target: Option<String>,
@ -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 @@ impl ConfigBuilder {
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}")));
}
}

View File

@ -0,0 +1,4 @@
LL| |// ignore-mode-coverage-map
LL| |
LL| 1|fn main() {}

View File

@ -0,0 +1,3 @@
// ignore-mode-coverage-map
fn main() {}

View File

@ -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)

View File

@ -0,0 +1,3 @@
// ignore-mode-coverage-run
fn main() {}