Skip to content

Commit 4aad9ab

Browse files
committed
Rename Mode to TestMode
It is *critical* that we maintain clear nomenclature in `compiletest`. We have many types of "modes" in `compiletest` -- pass modes, coverage modes, compare modes, you name it. `Mode` is also a *super* general term. Rename it to `TestMode` to leave no room for such ambiguity. As a follow-up, I also intend to introduce an enum for `TestSuite`, then rid of all usage of glob re-exported `TestMode::*` enum variants -- many test suites share the same name as the test mode.
1 parent b4dfd51 commit 4aad9ab

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use camino::{Utf8Path, Utf8PathBuf};
88
use semver::Version;
99
use serde::de::{Deserialize, Deserializer, Error as _};
1010

11-
pub use self::Mode::*;
11+
pub use self::TestMode::*;
1212
use crate::executor::{ColorConfig, OutputFormat};
1313
use crate::fatal;
1414
use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
1515

1616
string_enum! {
1717
#[derive(Clone, Copy, PartialEq, Debug)]
18-
pub enum Mode {
18+
pub enum TestMode {
1919
Pretty => "pretty",
2020
DebugInfo => "debuginfo",
2121
Codegen => "codegen",
@@ -34,7 +34,7 @@ string_enum! {
3434
}
3535
}
3636

37-
impl Mode {
37+
impl TestMode {
3838
pub fn aux_dir_disambiguator(self) -> &'static str {
3939
// Pretty-printing tests could run concurrently, and if they do,
4040
// they need to keep their output segregated.
@@ -147,7 +147,7 @@ pub enum Sanitizer {
147147
/// (for changed test detection).
148148
#[derive(Debug, Clone)]
149149
pub struct Config {
150-
/// Some test [`Mode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
150+
/// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
151151
/// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
152152
///
153153
/// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
@@ -269,20 +269,20 @@ pub struct Config {
269269
/// FIXME: reconsider this string; this is hashed for test build stamp.
270270
pub stage_id: String,
271271

272-
/// The test [`Mode`]. E.g. [`Mode::Ui`]. Each test mode can correspond to one or more test
272+
/// The [`TestMode`]. E.g. [`TestMode::Ui`]. Each test mode can correspond to one or more test
273273
/// suites.
274274
///
275275
/// FIXME: stop using stringly-typed test suites!
276-
pub mode: Mode,
276+
pub mode: TestMode,
277277

278278
/// The test suite.
279279
///
280-
/// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the [`Mode::Ui`]
281-
/// test *mode*.
280+
/// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the
281+
/// [`TestMode::Ui`] test *mode*.
282282
///
283283
/// Note that the same test directory (e.g. `tests/coverage/`) may correspond to multiple test
284-
/// modes, e.g. `tests/coverage/` can be run under both [`Mode::CoverageRun`] and
285-
/// [`Mode::CoverageMap`].
284+
/// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
285+
/// [`TestMode::CoverageMap`].
286286
///
287287
/// FIXME: stop using stringly-typed test suites!
288288
pub suite: String,
@@ -538,8 +538,8 @@ pub struct Config {
538538
// Configuration for various run-make tests frobbing things like C compilers or querying about
539539
// various LLVM component information.
540540
//
541-
// FIXME: this really should be better packaged together.
542-
// FIXME: these need better docs, e.g. for *host*, or for *target*?
541+
// FIXME: this really should be better packaged together. FIXME: these need better docs, e.g.
542+
// for *host*, or for *target*?
543543
pub cc: String,
544544
pub cxx: String,
545545
pub cflags: String,

src/tools/compiletest/src/directives.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use camino::{Utf8Path, Utf8PathBuf};
99
use semver::Version;
1010
use tracing::*;
1111

12-
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
12+
use crate::common::{Config, Debugger, FailMode, PassMode, TestMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
1414
use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
1515
use crate::directives::needs::CachedNeedsConditions;
@@ -328,7 +328,7 @@ impl TestProps {
328328
props.exec_env.push(("RUSTC".to_string(), config.rustc_path.to_string()));
329329

330330
match (props.pass_mode, props.fail_mode) {
331-
(None, None) if config.mode == Mode::Ui => props.fail_mode = Some(FailMode::Check),
331+
(None, None) if config.mode == TestMode::Ui => props.fail_mode = Some(FailMode::Check),
332332
(Some(_), Some(_)) => panic!("cannot use a *-fail and *-pass mode together"),
333333
_ => {}
334334
}
@@ -609,11 +609,11 @@ impl TestProps {
609609
self.failure_status = Some(101);
610610
}
611611

612-
if config.mode == Mode::Incremental {
612+
if config.mode == TestMode::Incremental {
613613
self.incremental = true;
614614
}
615615

616-
if config.mode == Mode::Crashes {
616+
if config.mode == TestMode::Crashes {
617617
// we don't want to pollute anything with backtrace-files
618618
// also turn off backtraces in order to save some execution
619619
// time on the tests; we only need to know IF it crashes
@@ -641,11 +641,11 @@ impl TestProps {
641641
fn update_fail_mode(&mut self, ln: &str, config: &Config) {
642642
let check_ui = |mode: &str| {
643643
// Mode::Crashes may need build-fail in order to trigger llvm errors or stack overflows
644-
if config.mode != Mode::Ui && config.mode != Mode::Crashes {
644+
if config.mode != TestMode::Ui && config.mode != TestMode::Crashes {
645645
panic!("`{}-fail` directive is only supported in UI tests", mode);
646646
}
647647
};
648-
if config.mode == Mode::Ui && config.parse_name_directive(ln, "compile-fail") {
648+
if config.mode == TestMode::Ui && config.parse_name_directive(ln, "compile-fail") {
649649
panic!("`compile-fail` directive is useless in UI tests");
650650
}
651651
let fail_mode = if config.parse_name_directive(ln, "check-fail") {
@@ -669,10 +669,10 @@ impl TestProps {
669669

670670
fn update_pass_mode(&mut self, ln: &str, revision: Option<&str>, config: &Config) {
671671
let check_no_run = |s| match (config.mode, s) {
672-
(Mode::Ui, _) => (),
673-
(Mode::Crashes, _) => (),
674-
(Mode::Codegen, "build-pass") => (),
675-
(Mode::Incremental, _) => {
672+
(TestMode::Ui, _) => (),
673+
(TestMode::Crashes, _) => (),
674+
(TestMode::Codegen, "build-pass") => (),
675+
(TestMode::Incremental, _) => {
676676
if revision.is_some() && !self.revisions.iter().all(|r| r.starts_with("cfail")) {
677677
panic!("`{s}` directive is only supported in `cfail` incremental tests")
678678
}
@@ -715,7 +715,7 @@ impl TestProps {
715715
pub fn update_add_core_stubs(&mut self, ln: &str, config: &Config) {
716716
let add_core_stubs = config.parse_name_directive(ln, directives::ADD_CORE_STUBS);
717717
if add_core_stubs {
718-
if !matches!(config.mode, Mode::Ui | Mode::Codegen | Mode::Assembly) {
718+
if !matches!(config.mode, TestMode::Ui | TestMode::Codegen | TestMode::Assembly) {
719719
panic!(
720720
"`add-core-stubs` is currently only supported for ui, codegen and assembly test modes"
721721
);
@@ -833,7 +833,7 @@ pub(crate) struct CheckDirectiveResult<'ln> {
833833

834834
pub(crate) fn check_directive<'a>(
835835
directive_ln: &'a str,
836-
mode: Mode,
836+
mode: TestMode,
837837
original_line: &str,
838838
) -> CheckDirectiveResult<'a> {
839839
let (directive_name, post) = directive_ln.split_once([':', ' ']).unwrap_or((directive_ln, ""));
@@ -842,11 +842,11 @@ pub(crate) fn check_directive<'a>(
842842
let is_known = |s: &str| {
843843
KNOWN_DIRECTIVE_NAMES.contains(&s)
844844
|| match mode {
845-
Mode::Rustdoc | Mode::RustdocJson => {
845+
TestMode::Rustdoc | TestMode::RustdocJson => {
846846
original_line.starts_with("//@")
847847
&& match mode {
848-
Mode::Rustdoc => KNOWN_HTMLDOCCK_DIRECTIVE_NAMES,
849-
Mode::RustdocJson => KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
848+
TestMode::Rustdoc => KNOWN_HTMLDOCCK_DIRECTIVE_NAMES,
849+
TestMode::RustdocJson => KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
850850
_ => unreachable!(),
851851
}
852852
.contains(&s)
@@ -868,7 +868,7 @@ pub(crate) fn check_directive<'a>(
868868
const COMPILETEST_DIRECTIVE_PREFIX: &str = "//@";
869869

870870
fn iter_directives(
871-
mode: Mode,
871+
mode: TestMode,
872872
_suite: &str,
873873
poisoned: &mut bool,
874874
testfile: &Utf8Path,
@@ -883,7 +883,7 @@ fn iter_directives(
883883
// specify them manually in every test file.
884884
//
885885
// FIXME(jieyouxu): I feel like there's a better way to do this, leaving for later.
886-
if mode == Mode::CoverageRun {
886+
if mode == TestMode::CoverageRun {
887887
let extra_directives: &[&str] = &[
888888
"needs-profiler-runtime",
889889
// FIXME(pietroalbini): this test currently does not work on cross-compiled targets
@@ -964,7 +964,7 @@ impl Config {
964964
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
965965

966966
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
967-
if self.mode == Mode::RunMake {
967+
if self.mode == TestMode::RunMake {
968968
panic!("`run-make` tests do not support revisions: {}", testfile);
969969
}
970970

@@ -981,7 +981,7 @@ impl Config {
981981
);
982982
}
983983

984-
if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
984+
if matches!(self.mode, TestMode::Assembly | TestMode::Codegen | TestMode::MirOpt)
985985
&& FILECHECK_FORBIDDEN_REVISION_NAMES.contains(&revision)
986986
{
987987
panic!(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{
77
DirectivesCache, EarlyProps, extract_llvm_version, extract_version_range, iter_directives,
88
parse_normalize_rule,
99
};
10-
use crate::common::{Config, Debugger, Mode};
10+
use crate::common::{Config, Debugger, TestMode};
1111
use crate::executor::{CollectedTestDesc, ShouldPanic};
1212

1313
fn make_test_description<R: Read>(
@@ -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(Mode::Ui, "ui", poisoned, path, rdr, &mut |_| {});
788+
iter_directives(TestMode::Ui, "ui", poisoned, path, rdr, &mut |_| {});
789789
}
790790

791791
#[test]

src/tools/compiletest/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ use walkdir::WalkDir;
3939

4040
use self::directives::{EarlyProps, make_test_description};
4141
use crate::common::{
42-
CompareMode, Config, Debugger, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path,
43-
output_base_dir, output_relative_path,
42+
CompareMode, Config, Debugger, PassMode, TestMode, TestPaths, UI_EXTENSIONS,
43+
expected_output_path, output_base_dir, output_relative_path,
4444
};
4545
use crate::directives::DirectivesCache;
4646
use crate::executor::{CollectedTest, ColorConfig, OutputFormat};
@@ -268,7 +268,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
268268
let with_rustc_debug_assertions = matches.opt_present("with-rustc-debug-assertions");
269269
let with_std_debug_assertions = matches.opt_present("with-std-debug-assertions");
270270
let mode = matches.opt_str("mode").unwrap().parse().expect("invalid mode");
271-
let has_html_tidy = if mode == Mode::Rustdoc {
271+
let has_html_tidy = if mode == TestMode::Rustdoc {
272272
Command::new("tidy")
273273
.arg("--version")
274274
.stdout(Stdio::null())
@@ -279,7 +279,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
279279
false
280280
};
281281
let has_enzyme = matches.opt_present("has-enzyme");
282-
let filters = if mode == Mode::RunMake {
282+
let filters = if mode == TestMode::RunMake {
283283
matches
284284
.free
285285
.iter()
@@ -545,7 +545,7 @@ pub fn run_tests(config: Arc<Config>) {
545545
unsafe { env::set_var("TARGET", &config.target) };
546546

547547
let mut configs = Vec::new();
548-
if let Mode::DebugInfo = config.mode {
548+
if let TestMode::DebugInfo = config.mode {
549549
// Debugging emscripten code doesn't make sense today
550550
if !config.target.contains("emscripten") {
551551
match config.debugger {
@@ -783,7 +783,7 @@ fn collect_tests_from_dir(
783783
}
784784

785785
// For run-make tests, a "test file" is actually a directory that contains an `rmake.rs`.
786-
if cx.config.mode == Mode::RunMake {
786+
if cx.config.mode == TestMode::RunMake {
787787
let mut collector = TestCollector::new();
788788
if dir.join("rmake.rs").exists() {
789789
let paths = TestPaths {
@@ -869,7 +869,7 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
869869
// For run-make tests, each "test file" is actually a _directory_ containing an `rmake.rs`. But
870870
// for the purposes of directive parsing, we want to look at that recipe file, not the directory
871871
// itself.
872-
let test_path = if cx.config.mode == Mode::RunMake {
872+
let test_path = if cx.config.mode == TestMode::RunMake {
873873
testpaths.file.join("rmake.rs")
874874
} else {
875875
testpaths.file.clone()
@@ -884,7 +884,7 @@ fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &Te
884884
// - Incremental tests inherently can't run their revisions in parallel, so
885885
// we treat them like non-revisioned tests here. Incremental revisions are
886886
// handled internally by `runtest::run` instead.
887-
let revisions = if early_props.revisions.is_empty() || cx.config.mode == Mode::Incremental {
887+
let revisions = if early_props.revisions.is_empty() || cx.config.mode == TestMode::Incremental {
888888
vec![None]
889889
} else {
890890
early_props.revisions.iter().map(|r| Some(r.as_str())).collect()
@@ -1116,11 +1116,11 @@ fn check_for_overlapping_test_paths(found_path_stems: &HashSet<Utf8PathBuf>) {
11161116
}
11171117

11181118
pub fn early_config_check(config: &Config) {
1119-
if !config.has_html_tidy && config.mode == Mode::Rustdoc {
1119+
if !config.has_html_tidy && config.mode == TestMode::Rustdoc {
11201120
warning!("`tidy` (html-tidy.org) is not installed; diffs will not be generated");
11211121
}
11221122

1123-
if !config.profiler_runtime && config.mode == Mode::CoverageRun {
1123+
if !config.profiler_runtime && config.mode == TestMode::CoverageRun {
11241124
let actioned = if config.bless { "blessed" } else { "checked" };
11251125
warning!("profiler runtime is not available, so `.coverage` files won't be {actioned}");
11261126
help!("try setting `profiler = true` in the `[build]` section of `bootstrap.toml`");

src/tools/compiletest/src/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl<'test> TestCx<'test> {
349349
if proc_res.status.success() {
350350
{
351351
self.error(&format!("{} test did not emit an error", self.config.mode));
352-
if self.config.mode == crate::common::Mode::Ui {
352+
if self.config.mode == crate::common::TestMode::Ui {
353353
println!("note: by default, ui tests are expected not to compile");
354354
}
355355
proc_res.fatal(None, || ());

src/tools/rustdoc-gui-test/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ If you want to install the `browser-ui-test` dependency, run `npm install browse
114114
if let Some(librs) = find_librs(entry.path()) {
115115
let compiletest_c = compiletest::common::Config {
116116
edition: None,
117-
mode: compiletest::common::Mode::Rustdoc,
117+
mode: compiletest::common::TestMode::Rustdoc,
118118
..Default::default()
119119
};
120120

0 commit comments

Comments
 (0)