clamp down on hacks in compiletest
This commit is contained in:
parent
1f40819315
commit
2f51310a80
@ -3,9 +3,9 @@ extern crate compiletest_rs as compiletest;
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::io::Write;
|
||||
|
||||
fn compile_fail(sysroot: &str) {
|
||||
let flags = format!("--sysroot {} -Dwarnings", sysroot);
|
||||
for_all_targets(sysroot, |target| {
|
||||
fn compile_fail(sysroot: &Path) {
|
||||
let flags = format!("--sysroot {} -Dwarnings", sysroot.to_str().expect("non utf8 path"));
|
||||
for_all_targets(&sysroot, |target| {
|
||||
let mut config = compiletest::default_config();
|
||||
config.host_rustcflags = Some(flags.clone());
|
||||
config.mode = "compile-fail".parse().expect("Invalid mode");
|
||||
@ -49,8 +49,10 @@ fn is_target_dir<P: Into<PathBuf>>(path: P) -> bool {
|
||||
path.metadata().map(|m| m.is_dir()).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
|
||||
for entry in std::fs::read_dir(format!("{}/lib/rustlib/", sysroot)).unwrap() {
|
||||
fn for_all_targets<F: FnMut(String)>(sysroot: &Path, mut f: F) {
|
||||
let target_dir = sysroot.join("lib").join("rustlib");
|
||||
println!("target dir: {}", target_dir.to_str().unwrap());
|
||||
for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") {
|
||||
let entry = entry.unwrap();
|
||||
if !is_target_dir(entry.path()) { continue; }
|
||||
let target = entry.file_name().into_string().unwrap();
|
||||
@ -62,24 +64,23 @@ fn for_all_targets<F: FnMut(String)>(sysroot: &str, mut f: F) {
|
||||
|
||||
#[test]
|
||||
fn compile_test() {
|
||||
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
|
||||
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
||||
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
||||
let sysroot = match (home, toolchain) {
|
||||
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
|
||||
_ => option_env!("RUST_SYSROOT")
|
||||
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
|
||||
.to_owned(),
|
||||
};
|
||||
let sysroot = std::process::Command::new("rustc")
|
||||
.arg("--print")
|
||||
.arg("sysroot")
|
||||
.output()
|
||||
.expect("rustc not found")
|
||||
.stdout;
|
||||
let sysroot = std::str::from_utf8(&sysroot).expect("sysroot is not utf8").trim();
|
||||
let sysroot = &Path::new(&sysroot);
|
||||
let host = std::process::Command::new("rustc")
|
||||
.arg("-vV")
|
||||
.output()
|
||||
.expect("rustc not found for -vV")
|
||||
.stdout;
|
||||
let host = std::str::from_utf8(&host).expect("sysroot is not utf8");
|
||||
let host = host.split("\nhost: ").skip(1).next().expect("no host: part in rustc -vV");
|
||||
let host = host.split("\n").next().expect("no \n after host");
|
||||
run_pass();
|
||||
let host = Path::new(&sysroot).file_name()
|
||||
.expect("sysroot has no last par")
|
||||
.to_str()
|
||||
.expect("sysroot contains non utf8")
|
||||
.splitn(2, '-')
|
||||
.skip(1)
|
||||
.next()
|
||||
.expect("target dir not prefixed");
|
||||
for_all_targets(&sysroot, |target| {
|
||||
miri_pass("tests/run-pass", &target, host);
|
||||
if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user