Skip to content

Commit 20af4f1

Browse files
Only run tests/assembly-* and tests/codegen-* tests if they match the current codegen backend
1 parent 0665793 commit 20af4f1

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/tools/compiletest/src/common.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl TestMode {
5555

5656
// Note that coverage tests use the same test files for multiple test modes.
5757
string_enum! {
58+
no_from_str,
5859
#[derive(Clone, Copy, PartialEq, Debug)]
5960
pub enum TestSuite {
6061
Assembly => "assembly",
@@ -79,6 +80,42 @@ string_enum! {
7980
}
8081
}
8182

83+
impl ::std::str::FromStr for TestSuite {
84+
type Err = String;
85+
86+
fn from_str(s: &str) -> Result<Self, Self::Err> {
87+
Ok(match s {
88+
"codegen-units" => Self::CodegenUnits,
89+
"coverage" => Self::Coverage,
90+
"coverage-run-rustdoc" => Self::CoverageRunRustdoc,
91+
"crashes" => Self::Crashes,
92+
"debuginfo" => Self::Debuginfo,
93+
"incremental" => Self::Incremental,
94+
"mir-opt" => Self::MirOpt,
95+
"pretty" => Self::Pretty,
96+
"run-make" => Self::RunMake,
97+
"rustdoc" => Self::Rustdoc,
98+
"rustdoc-gui" => Self::RustdocGui,
99+
"rustdoc-js" => Self::RustdocJs,
100+
"rustdoc-js-std" => Self::RustdocJsStd,
101+
"rustdoc-json" => Self::RustdocJson,
102+
"rustdoc-ui" => Self::RustdocUi,
103+
"ui" => Self::Ui,
104+
"ui-fulldeps" => Self::UiFullDeps,
105+
s => {
106+
if let Some((test_suite @ ("assembly" | "codegen"), codegen_backend)) =
107+
s.split_once('-')
108+
&& CodegenBackend::try_from(codegen_backend).is_ok()
109+
{
110+
if test_suite == "assembly" { Self::Assembly } else { Self::Codegen }
111+
} else {
112+
return Err(format!("unknown `TestSuite` variant: `{s}`"));
113+
}
114+
}
115+
})
116+
}
117+
}
118+
82119
string_enum! {
83120
#[derive(Clone, Copy, PartialEq, Debug, Hash)]
84121
pub enum PassMode {

src/tools/compiletest/src/lib.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::time::SystemTime;
3131
use std::{env, fs, vec};
3232

3333
use build_helper::git::{get_git_modified_files, get_git_untracked_files};
34-
use camino::{Utf8Path, Utf8PathBuf};
34+
use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
3535
use getopts::Options;
3636
use rayon::iter::{ParallelBridge, ParallelIterator};
3737
use tracing::debug;
@@ -799,6 +799,23 @@ fn collect_tests_from_dir(
799799
return Ok(TestCollector::new());
800800
}
801801

802+
let mut components = dir.components().rev();
803+
if let Some(Utf8Component::Normal(last)) = components.next()
804+
&& let Some(("assembly" | "codegen", backend)) = last.split_once('-')
805+
&& let Some(Utf8Component::Normal(parent)) = components.next()
806+
&& parent == "tests"
807+
&& let Ok(backend) = CodegenBackend::try_from(backend)
808+
&& backend != cx.config.codegen_backend
809+
{
810+
// We ignore asm tests which don't match the current codegen backend.
811+
println!(
812+
"Ignoring tests in `{dir}` because they don't match the configured codegen \
813+
backend (`{}`)",
814+
cx.config.codegen_backend.as_str(),
815+
);
816+
return Ok(TestCollector::new());
817+
}
818+
802819
// For run-make tests, a "test file" is actually a directory that contains an `rmake.rs`.
803820
if cx.config.mode == TestMode::RunMake {
804821
let mut collector = TestCollector::new();

src/tools/compiletest/src/util.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ macro_rules! static_regex {
106106
pub(crate) use static_regex;
107107

108108
macro_rules! string_enum {
109-
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
109+
(no_from_str, $(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
110110
$(#[$meta])*
111111
$vis enum $name {
112112
$($variant,)*
@@ -128,6 +128,9 @@ macro_rules! string_enum {
128128
::std::fmt::Display::fmt(self.to_str(), f)
129129
}
130130
}
131+
};
132+
($(#[$meta:meta])* $vis:vis enum $name:ident { $($variant:ident => $repr:expr,)* }) => {
133+
$crate::util::string_enum!(no_from_str, $(#[$meta])* $vis enum $name { $($variant => $repr,)* });
131134

132135
impl ::std::str::FromStr for $name {
133136
type Err = String;

0 commit comments

Comments
 (0)