Skip to content
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

Expose compiletest as a library for use in Clippy #103266

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
cmd.arg("--rust-demangler-path").arg(rust_demangler);
}

cmd.arg("--source-root").arg(&builder.src);
cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
Expand Down
10 changes: 0 additions & 10 deletions src/test/ui/closures/closure-immutable-outer-variable.rs.fixed

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/ui/const-generics/unused_braces.full.fixed

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/ui/const-generics/unused_braces.min.fixed

This file was deleted.

3 changes: 3 additions & 0 deletions src/tools/compiletest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "compiletest"
version = "0.0.0"
edition = "2021"

[lib]
doctest = false

[dependencies]
colored = "2"
diff = "0.1.10"
Expand Down
27 changes: 26 additions & 1 deletion src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use std::iter;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use std::sync::Arc;

use crate::util::{add_dylib_path, PathBufExt};
use lazycell::LazyCell;
use test::ColorConfig;
pub use test::ColorConfig;

#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Mode {
Expand Down Expand Up @@ -177,6 +178,21 @@ pub enum PanicStrategy {
Abort,
}

#[derive(Clone, Default)]
pub struct Hooks {
/// Return `true` to exclude a given [Path] from being considered a test file
pub exclude_file: Option<Arc<dyn Fn(&Path) -> bool + Send + Sync>>,

/// Modify a compiler [`Command`] just before it's executed
pub modify_compiler_command: Option<Arc<dyn Fn(&Path, &mut Command) + Send + Sync>>,
}

impl fmt::Debug for Hooks {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.debug_struct("Hooks").finish_non_exhaustive()
}
}

/// Configuration for compiletest
#[derive(Debug, Clone)]
pub struct Config {
Expand Down Expand Up @@ -224,6 +240,9 @@ pub struct Config {
/// `None` then these tests will be ignored.
pub run_clang_based_tests_with: Option<String>,

/// The project root directory
pub source_root: PathBuf,

/// The directory containing the tests to run
pub src_base: PathBuf,

Expand All @@ -236,6 +255,9 @@ pub struct Config {
/// The test mode, e.g. ui or debuginfo.
pub mode: Mode,

/// Don't require compile-fail or build-fail tests to contain `//~ ERROR` style comments
pub no_expected_comments: bool,

/// The test suite (essentially which directory is running, but without the
/// directory prefix such as src/test)
pub suite: String,
Expand Down Expand Up @@ -375,6 +397,9 @@ pub struct Config {
pub force_rerun: bool,

pub target_cfg: LazyCell<TargetCfg>,

/// Contains callbacks to be invoked at certain points in the test, used by Clippy
pub hooks: Hooks,
}

impl Config {
Expand Down
13 changes: 3 additions & 10 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,10 @@ impl Config {
}
}

pub fn find_rust_src_root(&self) -> Option<PathBuf> {
let mut path = self.src_base.clone();
let path_postfix = Path::new("src/etc/lldb_batchmode.py");
pub fn find_rust_src_root(&self) -> &Path {
assert!(self.source_root.join("x.py").exists(), "Not running in Rust source root");

while path.pop() {
if path.join(&path_postfix).is_file() {
return Some(path);
}
}

None
&self.source_root
}

fn parse_edition(&self, line: &str) -> Option<String> {
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn config() -> Config {
"--run-lib-path=",
"--python=",
"--jsondocck-path=",
"--source-root=",
"--src-base=",
"--build-base=",
"--stage-id=stage2",
Expand Down