3 extern crate compiletest_rs as compiletest;
6 use std::path::{PathBuf, Path};
7 use std::env::{set_var, var};
9 fn clippy_driver_path() -> PathBuf {
10 if let Some(path) = option_env!("CLIPPY_DRIVER_PATH") {
13 PathBuf::from(concat!("target/", env!("PROFILE"), "/clippy-driver"))
17 fn host_libs() -> PathBuf {
18 if let Some(path) = option_env!("HOST_LIBS") {
21 Path::new("target").join(env!("PROFILE"))
25 fn rustc_test_suite() -> Option<PathBuf> {
26 option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
29 fn rustc_lib_path() -> PathBuf {
30 option_env!("RUSTC_LIB_PATH").unwrap().into()
33 fn config(dir: &'static str, mode: &'static str) -> compiletest::Config {
34 let mut config = compiletest::Config::default();
36 let cfg_mode = mode.parse().expect("Invalid mode");
37 if let Ok(name) = var::<&str>("TESTNAME") {
38 let s: String = name.to_owned();
39 config.filter = Some(s)
42 if rustc_test_suite().is_some() {
43 config.run_lib_path = rustc_lib_path();
44 config.compile_lib_path = rustc_lib_path();
46 config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
48 config.mode = cfg_mode;
50 let mut path = std::env::current_dir().unwrap();
51 path.push("target/debug/test_build_base");
54 config.src_base = PathBuf::from(format!("tests/{}", dir));
55 config.rustc_path = clippy_driver_path();
59 fn run_mode(dir: &'static str, mode: &'static str) {
60 compiletest::run_tests(&config(dir, mode));
64 set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
65 set_var("CLIPPY_TESTS", "true");
66 set_var("RUST_BACKTRACE", "0");
72 run_mode("run-pass", "run-pass");
79 let files = ["src/main.rs", "src/driver.rs", "src/lib.rs", "clippy_lints/src/lib.rs"];
80 let mut config = config("dogfood", "ui");
81 config.target_rustcflags = config.target_rustcflags.map(|flags| format!("{} -Dclippy -Dclippy_pedantic -Dclippy_internal", flags));
84 let paths = test::TestPaths {
86 file: PathBuf::from(file),
87 relative_dir: PathBuf::new(),
90 compiletest::runtest::run(config.clone(), &paths);