Skip to content

Commit f223ade

Browse files
authored
Rollup merge of #143823 - jieyouxu:compiletest-maintenance-5, r=Kobzol
[COMPILETEST-UNTANGLE 5/N] Test mode adjustments and other assorted cleanups This is part of a patch series to untangle `compiletest` to hopefully nudge it towards being more maintainable. This PR should contain no functional changes modulo the removed debugger version warning. - Commit 1: Removes a very outdated debugger version warning. - Commit 2: Moves `string_enum` out of `common` into `util` module. - Commit 3: Remove `#[derive(Default)` for `Mode` and `Config`. It is very important for correctness that we *don't* `#[derive(Default)]`, because there are no sensible defaults, so stop pretending there is. - Commit 4: Rename `Mode` -> `TestMode`, because I would like to introduce a `TestSuite` enum to stop using stringly-typed test suite names where test mode names can be the same as test suite names, and we also have a bunch of other "modes" in compiletest. Make this as unambiguous as possible. A corollary is that now it's more natural to reference via intra-doc links as ``[`TestMode`]``. - Commit 5: Ditto on `TestSuite`, stop glob-reexporting `TestMode::*` variants, and always use `EnumName::VariantName` form. - Commit 6: Apparently, `src/tools/rustdoc-gui-test/` depends on `compiletest` for `//@ {compile,run}-paths` directive parsing and extraction, which involves creating a dummy `compiletest` config (hence the existence of the default impls removed in Commit 3). Make this a specific associated function with a FIXME pointing to #143827 as I think this setup is quite questionable. Commits {4, 5} are also intended to help improve the self-consistency in nomenclature used within compiletest. Best reviewed commit-by-commit.
2 parents 3aad16b + 6f8a7f0 commit f223ade

File tree

9 files changed

+253
-168
lines changed

9 files changed

+253
-168
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 117 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,20 @@
11
use std::collections::{BTreeSet, HashMap, HashSet};
2+
use std::iter;
23
use std::process::Command;
3-
use std::str::FromStr;
44
use std::sync::OnceLock;
5-
use std::{fmt, iter};
65

76
use build_helper::git::GitConfig;
87
use camino::{Utf8Path, Utf8PathBuf};
98
use semver::Version;
109
use serde::de::{Deserialize, Deserializer, Error as _};
1110

12-
pub use self::Mode::*;
1311
use crate::executor::{ColorConfig, OutputFormat};
1412
use crate::fatal;
15-
use crate::util::{Utf8PathBufExt, add_dylib_path};
16-
17-
macro_rules! string_enum {
18-
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
19-
$(#[$meta])*
20-
$vis enum $name {
21-
$($variant,)*
22-
}
23-
24-
impl $name {
25-
$vis const VARIANTS: &'static [Self] = &[$(Self::$variant,)*];
26-
$vis const STR_VARIANTS: &'static [&'static str] = &[$(Self::$variant.to_str(),)*];
27-
28-
$vis const fn to_str(&self) -> &'static str {
29-
match self {
30-
$(Self::$variant => $repr,)*
31-
}
32-
}
33-
}
34-
35-
impl fmt::Display for $name {
36-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37-
fmt::Display::fmt(self.to_str(), f)
38-
}
39-
}
40-
41-
impl FromStr for $name {
42-
type Err = String;
43-
44-
fn from_str(s: &str) -> Result<Self, Self::Err> {
45-
match s {
46-
$($repr => Ok(Self::$variant),)*
47-
_ => Err(format!(concat!("unknown `", stringify!($name), "` variant: `{}`"), s)),
48-
}
49-
}
50-
}
51-
}
52-
}
53-
54-
// Make the macro visible outside of this module, for tests.
55-
#[cfg(test)]
56-
pub(crate) use string_enum;
13+
use crate::util::{Utf8PathBufExt, add_dylib_path, string_enum};
5714

5815
string_enum! {
5916
#[derive(Clone, Copy, PartialEq, Debug)]
60-
pub enum Mode {
17+
pub enum TestMode {
6118
Pretty => "pretty",
6219
DebugInfo => "debuginfo",
6320
Codegen => "codegen",
@@ -76,18 +33,12 @@ string_enum! {
7633
}
7734
}
7835

79-
impl Default for Mode {
80-
fn default() -> Self {
81-
Mode::Ui
82-
}
83-
}
84-
85-
impl Mode {
36+
impl TestMode {
8637
pub fn aux_dir_disambiguator(self) -> &'static str {
8738
// Pretty-printing tests could run concurrently, and if they do,
8839
// they need to keep their output segregated.
8940
match self {
90-
Pretty => ".pretty",
41+
TestMode::Pretty => ".pretty",
9142
_ => "",
9243
}
9344
}
@@ -96,7 +47,7 @@ impl Mode {
9647
// Coverage tests use the same test files for multiple test modes,
9748
// so each mode should have a separate output directory.
9849
match self {
99-
CoverageMap | CoverageRun => self.to_str(),
50+
TestMode::CoverageMap | TestMode::CoverageRun => self.to_str(),
10051
_ => "",
10152
}
10253
}
@@ -193,9 +144,9 @@ pub enum Sanitizer {
193144
///
194145
/// FIXME: audit these options to make sure we are not hashing less than necessary for build stamp
195146
/// (for changed test detection).
196-
#[derive(Debug, Default, Clone)]
147+
#[derive(Debug, Clone)]
197148
pub struct Config {
198-
/// Some test [`Mode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
149+
/// Some [`TestMode`]s support [snapshot testing], where a *reference snapshot* of outputs (of
199150
/// `stdout`, `stderr`, or other form of artifacts) can be compared to the *actual output*.
200151
///
201152
/// This option can be set to `true` to update the *reference snapshots* in-place, otherwise
@@ -317,20 +268,20 @@ pub struct Config {
317268
/// FIXME: reconsider this string; this is hashed for test build stamp.
318269
pub stage_id: String,
319270

320-
/// The test [`Mode`]. E.g. [`Mode::Ui`]. Each test mode can correspond to one or more test
271+
/// The [`TestMode`]. E.g. [`TestMode::Ui`]. Each test mode can correspond to one or more test
321272
/// suites.
322273
///
323274
/// FIXME: stop using stringly-typed test suites!
324-
pub mode: Mode,
275+
pub mode: TestMode,
325276

326277
/// The test suite.
327278
///
328-
/// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the [`Mode::Ui`]
329-
/// test *mode*.
279+
/// Example: `tests/ui/` is the "UI" test *suite*, which happens to also be of the
280+
/// [`TestMode::Ui`] test *mode*.
330281
///
331282
/// Note that the same test directory (e.g. `tests/coverage/`) may correspond to multiple test
332-
/// modes, e.g. `tests/coverage/` can be run under both [`Mode::CoverageRun`] and
333-
/// [`Mode::CoverageMap`].
283+
/// modes, e.g. `tests/coverage/` can be run under both [`TestMode::CoverageRun`] and
284+
/// [`TestMode::CoverageMap`].
334285
///
335286
/// FIXME: stop using stringly-typed test suites!
336287
pub suite: String,
@@ -586,8 +537,8 @@ pub struct Config {
586537
// Configuration for various run-make tests frobbing things like C compilers or querying about
587538
// various LLVM component information.
588539
//
589-
// FIXME: this really should be better packaged together.
590-
// FIXME: these need better docs, e.g. for *host*, or for *target*?
540+
// FIXME: this really should be better packaged together. FIXME: these need better docs, e.g.
541+
// for *host*, or for *target*?
591542
pub cc: String,
592543
pub cxx: String,
593544
pub cflags: String,
@@ -653,6 +604,107 @@ pub struct Config {
653604
}
654605

655606
impl Config {
607+
/// Incomplete config intended for `src/tools/rustdoc-gui-test` **only** as
608+
/// `src/tools/rustdoc-gui-test` wants to reuse `compiletest`'s directive -> test property
609+
/// handling for `//@ {compile,run}-flags`, do not use for any other purpose.
610+
///
611+
/// FIXME(#143827): this setup feels very hacky. It so happens that `tests/rustdoc-gui/`
612+
/// **only** uses `//@ {compile,run}-flags` for now and not any directives that actually rely on
613+
/// info that is assumed available in a fully populated [`Config`].
614+
pub fn incomplete_for_rustdoc_gui_test() -> Config {
615+
// FIXME(#143827): spelling this out intentionally, because this is questionable.
616+
//
617+
// For instance, `//@ ignore-stage1` will not work at all.
618+
Config {
619+
mode: TestMode::Rustdoc,
620+
621+
// Dummy values.
622+
edition: Default::default(),
623+
bless: Default::default(),
624+
fail_fast: Default::default(),
625+
compile_lib_path: Utf8PathBuf::default(),
626+
run_lib_path: Utf8PathBuf::default(),
627+
rustc_path: Utf8PathBuf::default(),
628+
cargo_path: Default::default(),
629+
stage0_rustc_path: Default::default(),
630+
rustdoc_path: Default::default(),
631+
coverage_dump_path: Default::default(),
632+
python: Default::default(),
633+
jsondocck_path: Default::default(),
634+
jsondoclint_path: Default::default(),
635+
llvm_filecheck: Default::default(),
636+
llvm_bin_dir: Default::default(),
637+
run_clang_based_tests_with: Default::default(),
638+
src_root: Utf8PathBuf::default(),
639+
src_test_suite_root: Utf8PathBuf::default(),
640+
build_root: Utf8PathBuf::default(),
641+
build_test_suite_root: Utf8PathBuf::default(),
642+
sysroot_base: Utf8PathBuf::default(),
643+
stage: Default::default(),
644+
stage_id: String::default(),
645+
suite: Default::default(),
646+
debugger: Default::default(),
647+
run_ignored: Default::default(),
648+
with_rustc_debug_assertions: Default::default(),
649+
with_std_debug_assertions: Default::default(),
650+
filters: Default::default(),
651+
skip: Default::default(),
652+
filter_exact: Default::default(),
653+
force_pass_mode: Default::default(),
654+
run: Default::default(),
655+
runner: Default::default(),
656+
host_rustcflags: Default::default(),
657+
target_rustcflags: Default::default(),
658+
rust_randomized_layout: Default::default(),
659+
optimize_tests: Default::default(),
660+
target: Default::default(),
661+
host: Default::default(),
662+
cdb: Default::default(),
663+
cdb_version: Default::default(),
664+
gdb: Default::default(),
665+
gdb_version: Default::default(),
666+
lldb_version: Default::default(),
667+
llvm_version: Default::default(),
668+
system_llvm: Default::default(),
669+
android_cross_path: Default::default(),
670+
adb_path: Default::default(),
671+
adb_test_dir: Default::default(),
672+
adb_device_status: Default::default(),
673+
lldb_python_dir: Default::default(),
674+
verbose: Default::default(),
675+
format: Default::default(),
676+
color: Default::default(),
677+
remote_test_client: Default::default(),
678+
compare_mode: Default::default(),
679+
rustfix_coverage: Default::default(),
680+
has_html_tidy: Default::default(),
681+
has_enzyme: Default::default(),
682+
channel: Default::default(),
683+
git_hash: Default::default(),
684+
cc: Default::default(),
685+
cxx: Default::default(),
686+
cflags: Default::default(),
687+
cxxflags: Default::default(),
688+
ar: Default::default(),
689+
target_linker: Default::default(),
690+
host_linker: Default::default(),
691+
llvm_components: Default::default(),
692+
nodejs: Default::default(),
693+
npm: Default::default(),
694+
force_rerun: Default::default(),
695+
only_modified: Default::default(),
696+
target_cfgs: Default::default(),
697+
builtin_cfg_names: Default::default(),
698+
supported_crate_types: Default::default(),
699+
nocapture: Default::default(),
700+
nightly_branch: Default::default(),
701+
git_merge_commit_email: Default::default(),
702+
profiler_runtime: Default::default(),
703+
diff_command: Default::default(),
704+
minicore_path: Default::default(),
705+
}
706+
}
707+
656708
/// FIXME: this run scheme is... confusing.
657709
pub fn run_enabled(&self) -> bool {
658710
self.run.unwrap_or_else(|| {

src/tools/compiletest/src/debuggers.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ pub(crate) fn configure_gdb(config: &Config) -> Option<Arc<Config>> {
5151
pub(crate) fn configure_lldb(config: &Config) -> Option<Arc<Config>> {
5252
config.lldb_python_dir.as_ref()?;
5353

54-
// FIXME: this is super old
55-
if let Some(350) = config.lldb_version {
56-
println!(
57-
"WARNING: The used version of LLDB (350) has a \
58-
known issue that breaks debuginfo tests. See \
59-
issue #32520 for more information. Skipping all \
60-
LLDB-based tests!",
61-
);
62-
return None;
63-
}
64-
6554
Some(Arc::new(Config { debugger: Some(Debugger::Lldb), ..config.clone() }))
6655
}
6756

0 commit comments

Comments
 (0)