Skip to content

Add support for excluding tests via config.toml #135538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@
# What custom diff tool to use for displaying compiletest tests.
#compiletest-diff-tool = <none>

# List of tests or directories to exclude from the test suite. For example, exclude = ["tests/assembly", "tests/codegen"];
#exclude = []

# Indicates whether ccache is used when building certain artifacts (e.g. LLVM).
# Set to `true` to use the first `ccache` in PATH, or set an absolute path to use
# a specific version.
Expand Down
28 changes: 23 additions & 5 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@ impl PathSet {

fn has(&self, needle: &Path, module: Kind) -> bool {
match self {
PathSet::Set(set) => set.iter().any(|p| Self::check(p, needle, module)),
PathSet::Suite(suite) => Self::check(suite, needle, module),
PathSet::Set(set) => {
set.iter().any(|p| p.path == needle && Self::check(p, needle, module))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels suspicious. I think we already have a mechanism for skipping things (--exclude on the CLI) so I'd expect that any config.toml mechanism matches the behavior of that. Why do you need to change anything except plumbing through the new config.toml field to match the behavior of --exclude?

}
PathSet::Suite(suite) => suite.path == needle && Self::check(suite, needle, module),
}
}

Expand Down Expand Up @@ -426,13 +428,28 @@ impl StepDescription {
}

fn is_excluded(&self, builder: &Builder<'_>, pathset: &PathSet) -> bool {
if builder.config.skip.iter().any(|e| pathset.has(e, builder.kind)) {
// Helper function to determine if a path is explicitly excluded
let is_path_excluded = |exclude: &PathBuf| {
let exclude_path: &Path = exclude.as_path();
pathset.has(exclude_path, builder.kind)
};
// Check if the path is excluded by the --exclude flags
if builder.config.skip.iter().any(is_path_excluded) {
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
println!("Skipping {pathset:?} because it is excluded");
println!("Skipping {pathset:?} because it is excluded by --exclude flag");
}
return true;
}

// Check if the path is excluded by the exclude field in config.toml
if let Some(ref excludes) = builder.config.exclude {
if excludes.iter().any(is_path_excluded) {
if !matches!(builder.config.dry_run, DryRun::SelfCheck) {
println!("Skipping {pathset:?} because it is excluded by config.toml");
}
return true;
}
}
// Verbose logging if not excluded
if !builder.config.skip.is_empty() && !matches!(builder.config.dry_run, DryRun::SelfCheck) {
builder.verbose(|| {
println!(
Expand All @@ -441,6 +458,7 @@ impl StepDescription {
)
});
}

false
}

Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ pub struct Config {

/// Command for visual diff display, e.g. `diff-tool --color=always`.
pub compiletest_diff_tool: Option<String>,

// For excluding tests from the test suite
pub exclude: Option<Vec<PathBuf>>,
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -935,6 +938,7 @@ define_config! {
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
jobs: Option<u32> = "jobs",
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
exclude: Option<Vec<String>> = "exclude",
ccache: Option<StringOrBool> = "ccache",
}
}
Expand Down Expand Up @@ -1624,6 +1628,7 @@ impl Config {
optimized_compiler_builtins,
jobs,
compiletest_diff_tool,
exclude,
mut ccache,
} = toml.build.unwrap_or_default();

Expand Down Expand Up @@ -2315,6 +2320,7 @@ impl Config {
config.optimized_compiler_builtins =
optimized_compiler_builtins.unwrap_or(config.channel != "dev");
config.compiletest_diff_tool = compiletest_diff_tool;
config.exclude = exclude.map(|excludes| excludes.into_iter().map(PathBuf::from).collect());

let download_rustc = config.download_rustc_commit.is_some();
// See https://github.com/rust-lang/compiler-team/issues/326
Expand Down
Loading