Skip to content

Commit d4e26fb

Browse files
committedMay 4, 2024
compiletest: add enable-by-default check-cfg
1 parent 5173741 commit d4e26fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+114
-63
lines changed
 

‎src/tools/compiletest/src/runtest.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,12 +1028,31 @@ impl<'test> TestCx<'test> {
10281028
}
10291029

10301030
fn set_revision_flags(&self, cmd: &mut Command) {
1031+
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1032+
// Otherwise the `--cfg` flag is not valid.
1033+
let normalize_revision = |revision: &str| revision.to_lowercase().replace("-", "_");
1034+
10311035
if let Some(revision) = self.revision {
1032-
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1033-
// Otherwise the `--cfg` flag is not valid.
1034-
let normalized_revision = revision.to_lowercase().replace("-", "_");
1036+
let normalized_revision = normalize_revision(revision);
10351037
cmd.args(&["--cfg", &normalized_revision]);
10361038
}
1039+
1040+
if !self.props.no_auto_check_cfg {
1041+
let mut check_cfg = String::with_capacity(25);
1042+
1043+
// Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions)
1044+
//
1045+
// For compatibility reason we consider the `FALSE` cfg to be expected
1046+
// since it is extensively used in the testsuite.
1047+
check_cfg.push_str("cfg(FALSE");
1048+
for revision in &self.props.revisions {
1049+
check_cfg.push_str(",");
1050+
check_cfg.push_str(&normalize_revision(&revision));
1051+
}
1052+
check_cfg.push_str(")");
1053+
1054+
cmd.args(&["--check-cfg", &check_cfg]);
1055+
}
10371056
}
10381057

10391058
fn typecheck_source(&self, src: String) -> ProcRes {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Check to see if we can get parameters from an @argsfile file
22
//
33
//@ check-pass
4-
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
4+
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
5+
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args
56

67
#[cfg(not(cmdline_set))]
78
compile_error!("cmdline_set not set");
89

910
#[cfg(not(unbroken))]
1011
compile_error!("unbroken not set");
1112

12-
fn main() {
13-
}
13+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.