Skip to content

Commit 342a31a

Browse files
committed
Use TestSuite enum instead of stringly-typed test suites
1 parent f71f8ea commit 342a31a

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ impl TestMode {
5353
}
5454
}
5555

56+
// Note that coverage tests use the same test files for multiple test modes.
57+
string_enum! {
58+
#[derive(Clone, Copy, PartialEq, Debug)]
59+
pub enum TestSuite {
60+
Assembly => "assembly",
61+
Codegen => "codegen",
62+
CodegenUnits => "codegen-units",
63+
Coverage => "coverage",
64+
CoverageRunRustdoc => "coverage-run-rustdoc",
65+
Crashes => "crashes",
66+
Debuginfo => "debuginfo",
67+
Incremental => "incremental",
68+
MirOpt => "mir-opt",
69+
Pretty => "pretty",
70+
RunMake => "run-make",
71+
Rustdoc => "rustdoc",
72+
RustdocGui => "rustdoc-gui",
73+
RustdocJs => "rustdoc-js",
74+
RustdocJsStd=> "rustdoc-js-std",
75+
RustdocJson => "rustdoc-json",
76+
RustdocUi => "rustdoc-ui",
77+
Ui => "ui",
78+
UiFullDeps => "ui-fulldeps",
79+
}
80+
}
81+
5682
string_enum! {
5783
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
5884
pub enum PassMode {
@@ -276,15 +302,13 @@ pub struct Config {
276302

277303
/// The test suite.
278304
///
279-
/// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the
305+
/// Example: `tests/ui/` is [`TestSuite::Ui`] test *suite*, which happens to also be of the
280306
/// [`TestMode::Ui`] test *mode*.
281307
///
282-
/// Note that the same test directory (e.g. `tests/coverage/`) may correspond to multiple test
308+
/// Note that the same test suite (e.g. `tests/coverage/`) may correspond to multiple test
283309
/// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
284310
/// [`TestMode::CoverageMap`].
285-
///
286-
/// FIXME: stop using stringly-typed test suites!
287-
pub suite: String,
311+
pub suite: TestSuite,
288312

289313
/// When specified, **only** the specified [`Debugger`] will be used to run against the
290314
/// `tests/debuginfo` test suite. When unspecified, `compiletest` will attempt to find all three
@@ -537,8 +561,8 @@ pub struct Config {
537561
// Configuration for various run-make tests frobbing things like C compilers or querying about
538562
// various LLVM component information.
539563
//
540-
// FIXME: this really should be better packaged together. FIXME: these need better docs, e.g.
541-
// for *host*, or for *target*?
564+
// FIXME: this really should be better packaged together.
565+
// FIXME: these need better docs, e.g. for *host*, or for *target*?
542566
pub cc: String,
543567
pub cxx: String,
544568
pub cflags: String,

src/tools/compiletest/src/directives.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ impl EarlyProps {
5656
let mut poisoned = false;
5757
iter_directives(
5858
config.mode,
59-
&config.suite,
6059
&mut poisoned,
6160
testfile,
6261
rdr,
@@ -349,7 +348,6 @@ impl TestProps {
349348

350349
iter_directives(
351350
config.mode,
352-
&config.suite,
353351
&mut poisoned,
354352
testfile,
355353
file,
@@ -869,7 +867,6 @@ const COMPILETEST_DIRECTIVE_PREFIX: &str = "//@";
869867

870868
fn iter_directives(
871869
mode: TestMode,
872-
_suite: &str,
873870
poisoned: &mut bool,
874871
testfile: &Utf8Path,
875872
rdr: impl Read,
@@ -1388,7 +1385,6 @@ pub(crate) fn make_test_description<R: Read>(
13881385
// Scan through the test file to handle `ignore-*`, `only-*`, and `needs-*` directives.
13891386
iter_directives(
13901387
config.mode,
1391-
&config.suite,
13921388
&mut local_poisoned,
13931389
path,
13941390
src,

src/tools/compiletest/src/directives/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ fn threads_support() {
785785

786786
fn run_path(poisoned: &mut bool, path: &Utf8Path, buf: &[u8]) {
787787
let rdr = std::io::Cursor::new(&buf);
788-
iter_directives(TestMode::Ui, "ui", poisoned, path, rdr, &mut |_| {});
788+
iter_directives(TestMode::Ui, poisoned, path, rdr, &mut |_| {});
789789
}
790790

791791
#[test]

src/tools/compiletest/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
360360
stage_id: matches.opt_str("stage-id").unwrap(),
361361

362362
mode,
363-
suite: matches.opt_str("suite").unwrap(),
363+
suite: matches.opt_str("suite").unwrap().parse().expect("invalid suite"),
364364
debugger: matches.opt_str("debugger").map(|debugger| {
365365
debugger
366366
.parse::<Debugger>()

src/tools/compiletest/src/runtest.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use regex::{Captures, Regex};
1616
use tracing::*;
1717

1818
use crate::common::{
19-
CompareMode, Config, Debugger, FailMode, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
20-
UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT, UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG,
21-
expected_output_path, incremental_dir, output_base_dir, output_base_name,
19+
CompareMode, Config, Debugger, FailMode, PassMode, TestMode, TestPaths, TestSuite,
20+
UI_EXTENSIONS, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT, UI_STDERR, UI_STDOUT, UI_SVG,
21+
UI_WINDOWS_SVG, expected_output_path, incremental_dir, output_base_dir, output_base_name,
2222
output_testname_unique,
2323
};
2424
use crate::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
@@ -1494,7 +1494,10 @@ impl<'test> TestCx<'test> {
14941494
}
14951495

14961496
fn is_rustdoc(&self) -> bool {
1497-
matches!(self.config.suite.as_str(), "rustdoc-ui" | "rustdoc-js" | "rustdoc-json")
1497+
matches!(
1498+
self.config.suite,
1499+
TestSuite::RustdocUi | TestSuite::RustdocJs | TestSuite::RustdocJson
1500+
)
14981501
}
14991502

15001503
fn make_compile_args(

src/tools/compiletest/src/runtest/coverage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::process::Command;
66
use camino::{Utf8Path, Utf8PathBuf};
77
use glob::glob;
88

9-
use crate::common::{UI_COVERAGE, UI_COVERAGE_MAP};
9+
use crate::common::{TestSuite, UI_COVERAGE, UI_COVERAGE_MAP};
1010
use crate::runtest::{Emit, ProcRes, TestCx, WillExecute};
1111
use crate::util::static_regex;
1212

@@ -91,7 +91,7 @@ impl<'test> TestCx<'test> {
9191
let mut profraw_paths = vec![profraw_path];
9292
let mut bin_paths = vec![self.make_exe_name()];
9393

94-
if self.config.suite == "coverage-run-rustdoc" {
94+
if self.config.suite == TestSuite::CoverageRunRustdoc {
9595
self.run_doctests_for_coverage(&mut profraw_paths, &mut bin_paths);
9696
}
9797

0 commit comments

Comments
 (0)