Skip to content

Commit 22d2ffd

Browse files
authored
Rollup merge of #143232 - jieyouxu:compiletest-maintenance-3, r=Kobzol
[COMPILETEST-UNTANGLE 3/N] Use "directives" consistently within compiletest Instead of using *both* "headers" and "directives" within compiletest to refer to the same thing. This of course induces some churn, but it's been bugging me for a while, and I rather do the self-consistency changes now than later. The first commit tries to be mostly move-only to help per-file git history. I intend to revisit rustc-dev-guide's testing docs, but I don't want to do it on rust-lang/rust side because it would need syncing and might conflict.
2 parents 406e339 + 0346895 commit 22d2ffd

File tree

15 files changed

+43
-44
lines changed

15 files changed

+43
-44
lines changed

src/tools/compiletest/src/directive-list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// This was originally generated by collecting directives from ui tests and then extracting their
22
/// directive names. This is **not** an exhaustive list of all possible directives. Instead, this is
3-
/// a best-effort approximation for diagnostics. Add new headers to this list when needed.
3+
/// a best-effort approximation for diagnostics. Add new directives to this list when needed.
44
const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
55
// tidy-alphabetical-start
66
"add-core-stubs",

src/tools/compiletest/src/header.rs renamed to src/tools/compiletest/src/directives.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use tracing::*;
1111

1212
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
14+
use crate::directives::auxiliary::{AuxProps, parse_and_update_aux};
15+
use crate::directives::needs::CachedNeedsConditions;
1416
use crate::errors::ErrorKind;
1517
use crate::executor::{CollectedTestDesc, ShouldPanic};
16-
use crate::header::auxiliary::{AuxProps, parse_and_update_aux};
17-
use crate::header::needs::CachedNeedsConditions;
1818
use crate::help;
1919
use crate::util::static_regex;
2020

@@ -24,11 +24,11 @@ mod needs;
2424
#[cfg(test)]
2525
mod tests;
2626

27-
pub struct HeadersCache {
27+
pub struct DirectivesCache {
2828
needs: CachedNeedsConditions,
2929
}
3030

31-
impl HeadersCache {
31+
impl DirectivesCache {
3232
pub fn load(config: &Config) -> Self {
3333
Self { needs: CachedNeedsConditions::load(config) }
3434
}
@@ -54,7 +54,7 @@ impl EarlyProps {
5454
pub fn from_reader<R: Read>(config: &Config, testfile: &Utf8Path, rdr: R) -> Self {
5555
let mut props = EarlyProps::default();
5656
let mut poisoned = false;
57-
iter_header(
57+
iter_directives(
5858
config.mode,
5959
&config.suite,
6060
&mut poisoned,
@@ -138,12 +138,12 @@ pub struct TestProps {
138138
pub incremental_dir: Option<Utf8PathBuf>,
139139
// If `true`, this test will use incremental compilation.
140140
//
141-
// This can be set manually with the `incremental` header, or implicitly
141+
// This can be set manually with the `incremental` directive, or implicitly
142142
// by being a part of an incremental mode test. Using the `incremental`
143-
// header should be avoided if possible; using an incremental mode test is
143+
// directive should be avoided if possible; using an incremental mode test is
144144
// preferred. Incremental mode tests support multiple passes, which can
145145
// verify that the incremental cache can be loaded properly after being
146-
// created. Just setting the header will only verify the behavior with
146+
// created. Just setting the directive will only verify the behavior with
147147
// creating an incremental cache, but doesn't check that it is created
148148
// correctly.
149149
//
@@ -347,7 +347,7 @@ impl TestProps {
347347

348348
let mut poisoned = false;
349349

350-
iter_header(
350+
iter_directives(
351351
config.mode,
352352
&config.suite,
353353
&mut poisoned,
@@ -642,11 +642,11 @@ impl TestProps {
642642
let check_ui = |mode: &str| {
643643
// Mode::Crashes may need build-fail in order to trigger llvm errors or stack overflows
644644
if config.mode != Mode::Ui && config.mode != Mode::Crashes {
645-
panic!("`{}-fail` header is only supported in UI tests", mode);
645+
panic!("`{}-fail` directive is only supported in UI tests", mode);
646646
}
647647
};
648648
if config.mode == Mode::Ui && config.parse_name_directive(ln, "compile-fail") {
649-
panic!("`compile-fail` header is useless in UI tests");
649+
panic!("`compile-fail` directive is useless in UI tests");
650650
}
651651
let fail_mode = if config.parse_name_directive(ln, "check-fail") {
652652
check_ui("check");
@@ -662,7 +662,7 @@ impl TestProps {
662662
};
663663
match (self.fail_mode, fail_mode) {
664664
(None, Some(_)) => self.fail_mode = fail_mode,
665-
(Some(_), Some(_)) => panic!("multiple `*-fail` headers in a single test"),
665+
(Some(_), Some(_)) => panic!("multiple `*-fail` directives in a single test"),
666666
(_, None) => {}
667667
}
668668
}
@@ -674,10 +674,10 @@ impl TestProps {
674674
(Mode::Codegen, "build-pass") => (),
675675
(Mode::Incremental, _) => {
676676
if revision.is_some() && !self.revisions.iter().all(|r| r.starts_with("cfail")) {
677-
panic!("`{s}` header is only supported in `cfail` incremental tests")
677+
panic!("`{s}` directive is only supported in `cfail` incremental tests")
678678
}
679679
}
680-
(mode, _) => panic!("`{s}` header is not supported in `{mode}` tests"),
680+
(mode, _) => panic!("`{s}` directive is not supported in `{mode}` tests"),
681681
};
682682
let pass_mode = if config.parse_name_directive(ln, "check-pass") {
683683
check_no_run("check-pass");
@@ -693,7 +693,7 @@ impl TestProps {
693693
};
694694
match (self.pass_mode, pass_mode) {
695695
(None, Some(_)) => self.pass_mode = pass_mode,
696-
(Some(_), Some(_)) => panic!("multiple `*-pass` headers in a single test"),
696+
(Some(_), Some(_)) => panic!("multiple `*-pass` directives in a single test"),
697697
(_, None) => {}
698698
}
699699
}
@@ -794,7 +794,7 @@ const KNOWN_JSONDOCCK_DIRECTIVE_NAMES: &[&str] =
794794
&["count", "!count", "has", "!has", "is", "!is", "ismany", "!ismany", "set", "!set"];
795795

796796
/// The (partly) broken-down contents of a line containing a test directive,
797-
/// which [`iter_header`] passes to its callback function.
797+
/// which [`iter_directives`] passes to its callback function.
798798
///
799799
/// For example:
800800
///
@@ -867,7 +867,7 @@ pub(crate) fn check_directive<'a>(
867867

868868
const COMPILETEST_DIRECTIVE_PREFIX: &str = "//@";
869869

870-
fn iter_header(
870+
fn iter_directives(
871871
mode: Mode,
872872
_suite: &str,
873873
poisoned: &mut bool,
@@ -1163,8 +1163,7 @@ enum NormalizeKind {
11631163
Stderr64bit,
11641164
}
11651165

1166-
/// Parses the regex and replacement values of a `//@ normalize-*` header,
1167-
/// in the format:
1166+
/// Parses the regex and replacement values of a `//@ normalize-*` directive, in the format:
11681167
/// ```text
11691168
/// "REGEX" -> "REPLACEMENT"
11701169
/// ```
@@ -1373,7 +1372,7 @@ where
13731372

13741373
pub(crate) fn make_test_description<R: Read>(
13751374
config: &Config,
1376-
cache: &HeadersCache,
1375+
cache: &DirectivesCache,
13771376
name: String,
13781377
path: &Utf8Path,
13791378
src: R,
@@ -1387,7 +1386,7 @@ pub(crate) fn make_test_description<R: Read>(
13871386
let mut local_poisoned = false;
13881387

13891388
// Scan through the test file to handle `ignore-*`, `only-*`, and `needs-*` directives.
1390-
iter_header(
1389+
iter_directives(
13911390
config.mode,
13921391
&config.suite,
13931392
&mut local_poisoned,

src/tools/compiletest/src/header/auxiliary.rs renamed to src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
use std::iter;
55

6+
use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
67
use crate::common::Config;
7-
use crate::header::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
88

99
/// Properties parsed from `aux-*` test directives.
1010
#[derive(Clone, Debug, Default)]

src/tools/compiletest/src/header/cfg.rs renamed to src/tools/compiletest/src/directives/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashSet;
22

33
use crate::common::{CompareMode, Config, Debugger};
4-
use crate::header::IgnoreDecision;
4+
use crate::directives::IgnoreDecision;
55

66
const EXTRA_ARCHS: &[&str] = &["spirv"];
77

src/tools/compiletest/src/header/needs.rs renamed to src/tools/compiletest/src/directives/needs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::common::{Config, KNOWN_CRATE_TYPES, KNOWN_TARGET_HAS_ATOMIC_WIDTHS, Sanitizer};
2-
use crate::header::{IgnoreDecision, llvm_has_libzstd};
2+
use crate::directives::{IgnoreDecision, llvm_has_libzstd};
33

44
pub(super) fn handle_needs(
55
cache: &CachedNeedsConditions,

src/tools/compiletest/src/header/tests.rs renamed to src/tools/compiletest/src/directives/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use camino::Utf8Path;
44
use semver::Version;
55

66
use super::{
7-
EarlyProps, HeadersCache, extract_llvm_version, extract_version_range, iter_header,
7+
DirectivesCache, EarlyProps, extract_llvm_version, extract_version_range, iter_directives,
88
parse_normalize_rule,
99
};
1010
use crate::common::{Config, Debugger, Mode};
@@ -17,9 +17,9 @@ fn make_test_description<R: Read>(
1717
src: R,
1818
revision: Option<&str>,
1919
) -> CollectedTestDesc {
20-
let cache = HeadersCache::load(config);
20+
let cache = DirectivesCache::load(config);
2121
let mut poisoned = false;
22-
let test = crate::header::make_test_description(
22+
let test = crate::directives::make_test_description(
2323
config,
2424
&cache,
2525
name,
@@ -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_header(Mode::Ui, "ui", poisoned, path, rdr, &mut |_| {});
788+
iter_directives(Mode::Ui, "ui", poisoned, path, rdr, &mut |_| {});
789789
}
790790

791791
#[test]

src/tools/compiletest/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub mod common;
1212
pub mod compute_diff;
1313
mod debuggers;
1414
pub mod diagnostics;
15+
pub mod directives;
1516
pub mod errors;
1617
mod executor;
17-
pub mod header;
1818
mod json;
1919
mod raise_fd_limit;
2020
mod read2;
@@ -37,13 +37,13 @@ use rayon::iter::{ParallelBridge, ParallelIterator};
3737
use tracing::debug;
3838
use walkdir::WalkDir;
3939

40-
use self::header::{EarlyProps, make_test_description};
40+
use self::directives::{EarlyProps, make_test_description};
4141
use crate::common::{
4242
CompareMode, Config, Debugger, Mode, PassMode, TestPaths, UI_EXTENSIONS, expected_output_path,
4343
output_base_dir, output_relative_path,
4444
};
45+
use crate::directives::DirectivesCache;
4546
use crate::executor::{CollectedTest, ColorConfig, OutputFormat};
46-
use crate::header::HeadersCache;
4747
use crate::util::logv;
4848

4949
/// Creates the `Config` instance for this invocation of compiletest.
@@ -254,8 +254,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
254254
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
255255
};
256256
let llvm_version =
257-
matches.opt_str("llvm-version").as_deref().map(header::extract_llvm_version).or_else(
258-
|| header::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
257+
matches.opt_str("llvm-version").as_deref().map(directives::extract_llvm_version).or_else(
258+
|| directives::extract_llvm_version_from_binary(&matches.opt_str("llvm-filecheck")?),
259259
);
260260

261261
let run_ignored = matches.opt_present("ignored");
@@ -618,7 +618,7 @@ pub fn run_tests(config: Arc<Config>) {
618618
/// Read-only context data used during test collection.
619619
struct TestCollectorCx {
620620
config: Arc<Config>,
621-
cache: HeadersCache,
621+
cache: DirectivesCache,
622622
common_inputs_stamp: Stamp,
623623
modified_tests: Vec<Utf8PathBuf>,
624624
}
@@ -654,7 +654,7 @@ pub(crate) fn collect_and_make_tests(config: Arc<Config>) -> Vec<CollectedTest>
654654
modified_tests(&config, &config.src_test_suite_root).unwrap_or_else(|err| {
655655
fatal!("modified_tests: {}: {err}", config.src_test_suite_root);
656656
});
657-
let cache = HeadersCache::load(&config);
657+
let cache = DirectivesCache::load(&config);
658658

659659
let cx = TestCollectorCx { config, cache, common_inputs_stamp, modified_tests };
660660
let collector = collect_tests_from_dir(&cx, &cx.config.src_test_suite_root, Utf8Path::new(""))

src/tools/compiletest/src/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::common::{
2323
output_base_dir, output_base_name, output_testname_unique,
2424
};
2525
use crate::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
26+
use crate::directives::TestProps;
2627
use crate::errors::{Error, ErrorKind, load_errors};
27-
use crate::header::TestProps;
2828
use crate::read2::{Truncated, read2_abbreviated};
2929
use crate::util::{Utf8PathBufExt, add_dylib_path, logv, static_regex};
3030
use crate::{ColorConfig, help, json, stamp_file_path, warning};
@@ -2039,7 +2039,7 @@ impl<'test> TestCx<'test> {
20392039
// Provide more context on failures.
20402040
filecheck.args(&["--dump-input-context", "100"]);
20412041

2042-
// Add custom flags supplied by the `filecheck-flags:` test header.
2042+
// Add custom flags supplied by the `filecheck-flags:` test directive.
20432043
filecheck.args(&self.props.filecheck_flags);
20442044

20452045
// FIXME(jieyouxu): don't pass an empty Path

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl TestCx<'_> {
4949
std::fs::remove_file(pdb_file).unwrap();
5050
}
5151

52-
// compile test file (it should have 'compile-flags:-g' in the header)
52+
// compile test file (it should have 'compile-flags:-g' in the directive)
5353
let should_run = self.run_if_enabled();
5454
let compile_result = self.compile_test(should_run, Emit::None);
5555
if !compile_result.status.success() {
@@ -135,7 +135,7 @@ impl TestCx<'_> {
135135
.unwrap_or_else(|e| self.fatal(&e));
136136
let mut cmds = dbg_cmds.commands.join("\n");
137137

138-
// compile test file (it should have 'compile-flags:-g' in the header)
138+
// compile test file (it should have 'compile-flags:-g' in the directive)
139139
let should_run = self.run_if_enabled();
140140
let compiler_run_result = self.compile_test(should_run, Emit::None);
141141
if !compiler_run_result.status.success() {
@@ -359,7 +359,7 @@ impl TestCx<'_> {
359359
}
360360

361361
fn run_debuginfo_lldb_test_no_opt(&self) {
362-
// compile test file (it should have 'compile-flags:-g' in the header)
362+
// compile test file (it should have 'compile-flags:-g' in the directive)
363363
let should_run = self.run_if_enabled();
364364
let compile_result = self.compile_test(should_run, Emit::None);
365365
if !compile_result.status.success() {

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ impl TestCx<'_> {
5252
// don't test rustfix with nll right now
5353
} else if self.config.rustfix_coverage {
5454
// Find out which tests have `MachineApplicable` suggestions but are missing
55-
// `run-rustfix` or `run-rustfix-only-machine-applicable` headers.
55+
// `run-rustfix` or `run-rustfix-only-machine-applicable` directives.
5656
//
5757
// This will return an empty `Vec` in case the executed test file has a
58-
// `compile-flags: --error-format=xxxx` header with a value other than `json`.
58+
// `compile-flags: --error-format=xxxx` directive with a value other than `json`.
5959
let suggestions = get_suggestions_from_json(
6060
&rustfix_input,
6161
&HashSet::new(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::sync::Arc;
44
use std::{env, fs};
55

66
use build_helper::util::try_run;
7-
use compiletest::header::TestProps;
7+
use compiletest::directives::TestProps;
88
use config::Config;
99

1010
mod config;

0 commit comments

Comments
 (0)