option_env!("RUSTC_LIB_PATH").unwrap().into()
}
-fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp {
+fn run_tests(mode: &str, path: &str, target: &str, mut flags: Vec<String>) {
+ // Some flags we always want.
+ flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
+ flags.push("--edition 2018".to_owned());
+ if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") {
+ flags.push(format!("--sysroot {}", sysroot));
+ }
+
+ // The rest of the configuration.
let mut config = compiletest::Config::default().tempdir();
config.mode = mode.parse().expect("Invalid mode");
config.rustc_path = miri_path();
}
config.filter = env::args().nth(1);
config.host = get_host();
- config
+ config.src_base = PathBuf::from(path);
+ config.target = target.to_owned();
+ config.target_rustcflags = Some(flags.join(" "));
+ compiletest::run_tests(&config);
}
fn compile_fail(path: &str, target: &str, opt: bool) {
).green().bold());
let mut flags = Vec::new();
- flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
- flags.push("--edition 2018".to_owned());
if opt {
// Optimizing too aggressivley makes UB detection harder, but test at least
// the default value.
flags.push("-Zmir-opt-level=1".to_owned());
}
- let mut config = mk_config("compile-fail");
- config.src_base = PathBuf::from(path);
- config.target = target.to_owned();
- config.target_rustcflags = Some(flags.join(" "));
- compiletest::run_tests(&config);
+ run_tests("compile-fail", path, target, flags);
}
fn miri_pass(path: &str, target: &str, opt: bool) {
).green().bold());
let mut flags = Vec::new();
- flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
- flags.push("--edition 2018".to_owned());
if opt {
flags.push("-Zmir-opt-level=3".to_owned());
}
- let mut config = mk_config("ui");
- config.src_base = PathBuf::from(path);
- config.target = target.to_owned();
- config.target_rustcflags = Some(flags.join(" "));
- compiletest::run_tests(&config);
-}
-
-/// Make sure the MIRI_SYSROOT env var is set
-fn set_sysroot() {
- if std::env::var("MIRI_SYSROOT").is_ok() {
- // Nothing to do
- return;
- }
- let sysroot = std::process::Command::new("rustc")
- .arg("--print")
- .arg("sysroot")
- .output()
- .expect("rustc not found")
- .stdout;
- let sysroot = String::from_utf8(sysroot).expect("sysroot is not utf8");
- std::env::set_var("MIRI_SYSROOT", sysroot.trim());
+ run_tests("ui", path, target, flags);
}
fn get_host() -> String {
}
fn get_target() -> String {
- std::env::var("MIRI_TARGET").unwrap_or_else(|_| get_host())
+ std::env::var("MIRI_TEST_TARGET").unwrap_or_else(|_| get_host())
}
fn run_pass_miri(opt: bool) {
}
fn test_runner(_tests: &[&()]) {
- set_sysroot();
-
run_pass_miri(false);
run_pass_miri(true);