Skip to content

Commit 4e2a982

Browse files
committed
include pretty reason why ignore-FOO matched
1 parent 123cc41 commit 4e2a982

File tree

2 files changed

+141
-73
lines changed

2 files changed

+141
-73
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub enum Debugger {
159159
}
160160

161161
impl Debugger {
162-
fn to_str(&self) -> &'static str {
162+
pub(crate) fn to_str(&self) -> &'static str {
163163
match self {
164164
Debugger::Cdb => "cdb",
165165
Debugger::Gdb => "gdb",
@@ -396,7 +396,7 @@ impl Config {
396396
})
397397
}
398398

399-
fn target_cfg(&self) -> &TargetCfg {
399+
pub fn target_cfg(&self) -> &TargetCfg {
400400
self.target_cfg.borrow_with(|| TargetCfg::new(self))
401401
}
402402

@@ -451,12 +451,12 @@ impl Config {
451451

452452
#[derive(Clone, Debug)]
453453
pub struct TargetCfg {
454-
arch: String,
455-
os: String,
456-
env: String,
457-
abi: String,
458-
families: Vec<String>,
459-
pointer_width: u32,
454+
pub(crate) arch: String,
455+
pub(crate) os: String,
456+
pub(crate) env: String,
457+
pub(crate) abi: String,
458+
pub(crate) families: Vec<String>,
459+
pub(crate) pointer_width: u32,
460460
endian: Endian,
461461
panic: PanicStrategy,
462462
}

src/tools/compiletest/src/header.rs

Lines changed: 133 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::process::Command;
88

99
use tracing::*;
1010

11-
use crate::common::{CompareMode, Config, Debugger, FailMode, Mode, PassMode};
11+
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
1212
use crate::util;
1313
use crate::{extract_cdb_version, extract_gdb_version};
1414

@@ -17,14 +17,16 @@ mod tests;
1717

1818
/// The result of parse_cfg_name_directive.
1919
#[derive(Clone, PartialEq, Debug)]
20-
struct ParsedNameDirective {
21-
comment: Option<String>,
20+
struct ParsedNameDirective<'a> {
21+
name: Option<&'a str>,
22+
pretty_reason: Option<String>,
23+
comment: Option<&'a str>,
2224
outcome: MatchOutcome,
2325
}
2426

25-
impl ParsedNameDirective {
27+
impl ParsedNameDirective<'_> {
2628
fn invalid() -> Self {
27-
Self { comment: None, outcome: MatchOutcome::NoMatch }
29+
Self { name: None, pretty_reason: None, comment: None, outcome: MatchOutcome::NoMatch }
2830
}
2931
}
3032

@@ -678,7 +680,7 @@ impl Config {
678680

679681
/// Parses a name-value directive which contains config-specific information, e.g., `ignore-x86`
680682
/// or `normalize-stderr-32bit`.
681-
fn parse_cfg_name_directive(&self, line: &str, prefix: &str) -> ParsedNameDirective {
683+
fn parse_cfg_name_directive<'a>(&self, line: &'a str, prefix: &str) -> ParsedNameDirective<'a> {
682684
if !line.as_bytes().starts_with(prefix.as_bytes()) {
683685
return ParsedNameDirective::invalid();
684686
}
@@ -690,56 +692,124 @@ impl Config {
690692
let (name, comment) =
691693
line.split_once(&[':', ' ']).map(|(l, c)| (l, Some(c))).unwrap_or((line, None));
692694

693-
let matches_pointer_width = || {
694-
name.strip_suffix("bit")
695-
.and_then(|width| width.parse::<u32>().ok())
696-
.map(|width| self.get_pointer_width() == width)
697-
.unwrap_or(false)
698-
};
695+
let mut is_match = None;
696+
697+
macro_rules! maybe_condition {
698+
(name: $name:expr, $(condition: $condition:expr,)? message: $($message:tt)*) => {
699+
if let Some(expected) = $name {
700+
if name == expected $(&& $condition)? {
701+
is_match = Some(format!($($message)*));
702+
}
703+
}
704+
};
705+
}
706+
macro_rules! condition {
707+
(name: $name:expr, $(condition: $condition:expr,)? message: $($message:tt)*) => {
708+
maybe_condition! {
709+
name: Some($name),
710+
$(condition: $condition,)*
711+
message: $($message)*
712+
}
713+
};
714+
}
715+
716+
condition! {
717+
name: "test",
718+
message: "always"
719+
}
720+
condition! {
721+
name: &self.target,
722+
message: "when the target is {name}"
723+
}
724+
725+
let target_cfg = self.target_cfg();
726+
condition! {
727+
name: &target_cfg.os,
728+
message: "when the operative system is {name}"
729+
}
730+
condition! {
731+
name: &target_cfg.env,
732+
message: "when the target environment is {name}"
733+
}
734+
condition! {
735+
name: &target_cfg.abi,
736+
message: "when the ABI is {name}"
737+
}
738+
condition! {
739+
name: &target_cfg.arch,
740+
message: "when the architecture is {name}"
741+
}
742+
condition! {
743+
name: format!("{}bit", target_cfg.pointer_width),
744+
message: "when the pointer width is {name}"
745+
}
746+
for family in &target_cfg.families {
747+
condition! {
748+
name: family,
749+
message: "when the target family is {name}"
750+
}
751+
}
699752

700753
// If something is ignored for emscripten, it likely also needs to be
701754
// ignored for wasm32-unknown-unknown.
702755
// `wasm32-bare` is an alias to refer to just wasm32-unknown-unknown
703756
// (in contrast to `wasm32` which also matches non-bare targets like
704757
// asmjs-unknown-emscripten).
705-
let matches_wasm32_alias = || {
706-
self.target == "wasm32-unknown-unknown" && matches!(name, "emscripten" | "wasm32-bare")
707-
};
758+
condition! {
759+
name: "emscripten",
760+
condition: self.target == "wasm32-unknown-unknown",
761+
message: "when the target is WASM",
762+
}
763+
condition! {
764+
name: "wasm32-bare",
765+
condition: self.target == "wasm32-unknown-unknown",
766+
message: "when the target is WASM"
767+
}
708768

709-
let is_match = name == "test" ||
710-
self.target == name || // triple
711-
self.matches_os(name) ||
712-
self.matches_env(name) ||
713-
self.matches_abi(name) ||
714-
self.matches_family(name) ||
715-
self.target.ends_with(name) || // target and env
716-
self.matches_arch(name) ||
717-
matches_wasm32_alias() ||
718-
matches_pointer_width() ||
719-
name == self.stage_id.split('-').next().unwrap() || // stage
720-
name == self.channel || // channel
721-
(self.target != self.host && name == "cross-compile") ||
722-
(name == "endian-big" && self.is_big_endian()) ||
723-
(self.remote_test_client.is_some() && name == "remote") ||
724-
match self.compare_mode {
725-
Some(CompareMode::Polonius) => name == "compare-mode-polonius",
726-
Some(CompareMode::Chalk) => name == "compare-mode-chalk",
727-
Some(CompareMode::NextSolver) => name == "compare-mode-next-solver",
728-
Some(CompareMode::SplitDwarf) => name == "compare-mode-split-dwarf",
729-
Some(CompareMode::SplitDwarfSingle) => name == "compare-mode-split-dwarf-single",
730-
None => false,
731-
} ||
732-
(cfg!(debug_assertions) && name == "debug") ||
733-
match self.debugger {
734-
Some(Debugger::Cdb) => name == "cdb",
735-
Some(Debugger::Gdb) => name == "gdb",
736-
Some(Debugger::Lldb) => name == "lldb",
737-
None => false,
738-
};
769+
condition! {
770+
name: &self.channel,
771+
message: "when the release channel is {name}",
772+
}
773+
condition! {
774+
name: "cross-compile",
775+
condition: self.target != self.host,
776+
message: "when cross-compiling"
777+
}
778+
condition! {
779+
name: "endian-big",
780+
condition: self.is_big_endian(),
781+
message: "on big-endian targets",
782+
}
783+
condition! {
784+
name: self.stage_id.split('-').next().unwrap(),
785+
message: "when the bootstrapping stage is {name}",
786+
}
787+
condition! {
788+
name: "remote",
789+
condition: self.remote_test_client.is_some(),
790+
message: "when running tests remotely",
791+
}
792+
condition! {
793+
name: "debug",
794+
condition: cfg!(debug_assertions),
795+
message: "when building with debug assertions",
796+
}
797+
maybe_condition! {
798+
name: self.debugger.as_ref().map(|d| d.to_str()),
799+
message: "when the debugger is {name}",
800+
}
801+
maybe_condition! {
802+
name: self.compare_mode
803+
.as_ref()
804+
.map(|d| format!("compare-mode-{}", d.to_str())),
805+
message: "when comparing with {name}",
806+
}
739807

740808
ParsedNameDirective {
741-
comment: comment.map(|c| c.trim().trim_start_matches('-').trim().to_string()),
742-
outcome: if is_match { MatchOutcome::Match } else { MatchOutcome::NoMatch },
809+
name: Some(name),
810+
comment: comment.map(|c| c.trim().trim_start_matches('-').trim()),
811+
outcome: if is_match.is_some() { MatchOutcome::Match } else { MatchOutcome::NoMatch },
812+
pretty_reason: is_match,
743813
}
744814
}
745815

@@ -1014,15 +1084,14 @@ pub fn make_test_description<R: Read>(
10141084
let parsed = config.parse_cfg_name_directive(ln, "ignore");
10151085
ignore = match parsed.outcome {
10161086
MatchOutcome::Match => {
1017-
ignore_message = Some(match parsed.comment {
1018-
// The ignore reason must be a &'static str, so we have to leak memory to
1019-
// create it. This is fine, as the header is parsed only at the start of
1020-
// compiletest so it won't grow indefinitely.
1021-
Some(comment) => Box::leak(Box::<str>::from(format!(
1022-
"cfg -> ignore => Match ({comment})"
1023-
))),
1024-
None => "cfg -> ignore => Match",
1025-
});
1087+
let reason = parsed.pretty_reason.unwrap();
1088+
// The ignore reason must be a &'static str, so we have to leak memory to
1089+
// create it. This is fine, as the header is parsed only at the start of
1090+
// compiletest so it won't grow indefinitely.
1091+
ignore_message = Some(Box::leak(Box::<str>::from(match parsed.comment {
1092+
Some(comment) => format!("ignored {reason} ({comment})"),
1093+
None => format!("ignored {reason}"),
1094+
})) as &str);
10261095
true
10271096
}
10281097
MatchOutcome::NoMatch => ignore,
@@ -1034,15 +1103,14 @@ pub fn make_test_description<R: Read>(
10341103
ignore = match parsed.outcome {
10351104
MatchOutcome::Match => ignore,
10361105
MatchOutcome::NoMatch => {
1037-
ignore_message = Some(match parsed.comment {
1038-
// The ignore reason must be a &'static str, so we have to leak memory to
1039-
// create it. This is fine, as the header is parsed only at the start of
1040-
// compiletest so it won't grow indefinitely.
1041-
Some(comment) => Box::leak(Box::<str>::from(format!(
1042-
"cfg -> only => NoMatch ({comment})"
1043-
))),
1044-
None => "cfg -> only => NoMatch",
1045-
});
1106+
let name = parsed.name.unwrap();
1107+
// The ignore reason must be a &'static str, so we have to leak memory to
1108+
// create it. This is fine, as the header is parsed only at the start of
1109+
// compiletest so it won't grow indefinitely.
1110+
ignore_message = Some(Box::leak(Box::<str>::from(match parsed.comment {
1111+
Some(comment) => format!("did not match only-{name} ({comment})"),
1112+
None => format!("did not match only-{name}"),
1113+
})) as &str);
10461114
true
10471115
}
10481116
};

0 commit comments

Comments
 (0)