Skip to content

Commit c38aeb0

Browse files
committed
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.
1 parent 3813fe1 commit c38aeb0

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

src/tools/compiletest/src/header/cfg.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::common::{CompareMode, Config, Debugger};
1+
use crate::common::{CompareMode, Config, Debugger, Mode};
22
use crate::header::IgnoreDecision;
33
use std::collections::HashSet;
44

@@ -208,6 +208,17 @@ pub(super) fn parse_cfg_name_directive<'a>(
208208
},
209209
message: "when comparing with {name}",
210210
}
211+
// Coverage tests run the same test file in multiple modes.
212+
// If a particular test should not be run in one of the modes, ignore it
213+
// with "ignore-mode-coverage-map" or "ignore-mode-coverage-run".
214+
condition! {
215+
name: format!("mode-{}", config.mode.to_str()),
216+
allowed_names: ContainsPrefixed {
217+
prefix: "mode-",
218+
inner: Mode::STR_VARIANTS,
219+
},
220+
message: "when the test mode is {name}",
221+
}
211222

212223
if prefix == "ignore" && outcome == MatchOutcome::Invalid {
213224
// Don't error out for ignore-tidy-* diretives, as those are not handled by compiletest.

src/tools/compiletest/src/header/tests.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::io::Read;
22
use std::path::Path;
3+
use std::str::FromStr;
34

4-
use crate::common::{Config, Debugger};
5+
use crate::common::{Config, Debugger, Mode};
56
use crate::header::{parse_normalization_string, EarlyProps, HeadersCache};
67

78
fn make_test_description<R: Read>(
@@ -55,6 +56,7 @@ fn test_parse_normalization_string() {
5556

5657
#[derive(Default)]
5758
struct ConfigBuilder {
59+
mode: Option<String>,
5860
channel: Option<String>,
5961
host: Option<String>,
6062
target: Option<String>,
@@ -66,6 +68,11 @@ struct ConfigBuilder {
6668
}
6769

6870
impl ConfigBuilder {
71+
fn mode(&mut self, s: &str) -> &mut Self {
72+
self.mode = Some(s.to_owned());
73+
self
74+
}
75+
6976
fn channel(&mut self, s: &str) -> &mut Self {
7077
self.channel = Some(s.to_owned());
7178
self
@@ -109,7 +116,8 @@ impl ConfigBuilder {
109116
fn build(&mut self) -> Config {
110117
let args = &[
111118
"compiletest",
112-
"--mode=ui",
119+
"--mode",
120+
self.mode.as_deref().unwrap_or("ui"),
113121
"--suite=ui",
114122
"--compile-lib-path=",
115123
"--run-lib-path=",
@@ -548,3 +556,17 @@ fn families() {
548556
assert!(!check_ignore(&config, &format!("// ignore-{other}")));
549557
}
550558
}
559+
560+
#[test]
561+
fn ignore_mode() {
562+
for &mode in Mode::STR_VARIANTS {
563+
// Indicate profiler support so that "coverage-run" tests aren't skipped.
564+
let config: Config = cfg().mode(mode).profiler_support(true).build();
565+
let other = if mode == "coverage-run" { "coverage-map" } else { "coverage-run" };
566+
assert_ne!(mode, other);
567+
assert_eq!(config.mode, Mode::from_str(mode).unwrap());
568+
assert_ne!(config.mode, Mode::from_str(other).unwrap());
569+
assert!(check_ignore(&config, &format!("// ignore-mode-{mode}")));
570+
assert!(!check_ignore(&config, &format!("// ignore-mode-{other}")));
571+
}
572+
}

tests/coverage/ignore_map.coverage

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LL| |// ignore-mode-coverage-map
2+
LL| |
3+
LL| 1|fn main() {}
4+

tests/coverage/ignore_map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// ignore-mode-coverage-map
2+
3+
fn main() {}

tests/coverage/ignore_run.cov-map

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Function name: ignore_run::main
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 03, 01, 00, 0d]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 13)
8+

tests/coverage/ignore_run.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// ignore-mode-coverage-run
2+
3+
fn main() {}

0 commit comments

Comments
 (0)