#![feature(test)]
use compiletest_rs as compiletest;
-extern crate test;
+extern crate tester as test;
use std::env::{set_var, var};
use std::ffi::OsStr;
use std::io;
use std::path::{Path, PathBuf};
+#[must_use]
fn clippy_driver_path() -> PathBuf {
if let Some(path) = option_env!("CLIPPY_DRIVER_PATH") {
PathBuf::from(path)
}
}
+#[must_use]
fn host_libs() -> PathBuf {
if let Some(path) = option_env!("HOST_LIBS") {
PathBuf::from(path)
}
}
+#[must_use]
+fn target_libs() -> Option<PathBuf> {
+ option_env!("TARGET_LIBS").map(PathBuf::from)
+}
+
+#[must_use]
fn rustc_test_suite() -> Option<PathBuf> {
option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
}
+#[must_use]
fn rustc_lib_path() -> PathBuf {
option_env!("RUSTC_LIB_PATH").unwrap().into()
}
let cfg_mode = mode.parse().expect("Invalid mode");
if let Ok(name) = var::<&str>("TESTNAME") {
- let s: String = name.to_owned();
- config.filter = Some(s)
+ config.filter = Some(name)
}
if rustc_test_suite().is_some() {
// as we'll get a duplicate matching versions. Instead, disambiguate with
// `--extern dep=path`.
// See https://github.com/rust-lang/rust-clippy/issues/4015.
- let needs_disambiguation = ["serde"];
+ let needs_disambiguation = ["serde", "regex", "clippy_lints"];
// This assumes that deps are compiled (they are for Cargo integration tests).
- let deps = std::fs::read_dir(host_libs().join("deps")).unwrap();
+ let deps = fs::read_dir(target_libs().unwrap_or_else(host_libs).join("deps")).unwrap();
let disambiguated = deps
.filter_map(|dep| {
let path = dep.ok()?.path();
// NOTE: This only handles a single dep
// https://github.com/laumann/compiletest-rs/issues/101
needs_disambiguation.iter().find_map(|dep| {
- if name.starts_with(&format!("lib{}-", dep)) {
+ if name.starts_with(&format!("lib{}-", dep)) && name.ends_with(".rlib") {
Some(format!("--extern {}={}", dep, path.display()))
} else {
None
.collect::<Vec<_>>();
config.target_rustcflags = Some(format!(
- "-L {0} -L {0}/deps -Dwarnings -Zui-testing {1}",
+ "-L {0} -L {0}/deps {1} -Dwarnings -Zui-testing {2}",
host_libs().display(),
+ target_libs().map_or_else(String::new, |path| format!("-L {0} -L {0}/deps", path.display())),
disambiguated.join(" ")
));
fn run_mode(mode: &str, dir: PathBuf) {
let cfg = config(mode, dir);
- // clean rmeta data, otherwise "cargo check; cargo test" fails (#2896)
- cfg.clean_rmeta();
compiletest::run_tests(&cfg);
}