Skip to content

Commit 33ff32c

Browse files
committed
Get the test suite working inside the rustc test suite
1 parent 63c4843 commit 33ff32c

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

tests/compiletest.rs

+35-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ macro_rules! eprintln {
1313
}
1414
}
1515

16-
const MIRI_PATH: &'static str = concat!("target/", env!("PROFILE"), "/miri");
16+
fn miri_path() -> PathBuf {
17+
if rustc_test_suite().is_some() {
18+
PathBuf::from(option_env!("MIRI_PATH").unwrap())
19+
} else {
20+
PathBuf::from(concat!("target/", env!("PROFILE"), "/miri"))
21+
}
22+
}
23+
24+
fn rustc_test_suite() -> Option<PathBuf> {
25+
option_env!("RUSTC_TEST_SUITE").map(PathBuf::from)
26+
}
27+
28+
fn rustc_lib_path() -> PathBuf {
29+
option_env!("RUSTC_LIB_PATH").unwrap().into()
30+
}
1731

1832
fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: bool) {
1933
eprintln!(
@@ -23,9 +37,14 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: b
2337
);
2438
let mut config = compiletest::default_config();
2539
config.mode = "compile-fail".parse().expect("Invalid mode");
26-
config.rustc_path = MIRI_PATH.into();
40+
config.rustc_path = miri_path();
2741
let mut flags = Vec::new();
28-
if fullmir {
42+
if rustc_test_suite().is_some() {
43+
config.run_lib_path = rustc_lib_path();
44+
config.compile_lib_path = rustc_lib_path();
45+
}
46+
// if we are building as part of the rustc test suite, we already have fullmir for everything
47+
if fullmir && rustc_test_suite().is_none() {
2948
if host != target {
3049
// skip fullmir on nonhost
3150
return;
@@ -50,7 +69,12 @@ fn run_pass(path: &str) {
5069
let mut config = compiletest::default_config();
5170
config.mode = "run-pass".parse().expect("Invalid mode");
5271
config.src_base = PathBuf::from(path);
53-
config.target_rustcflags = Some("-Dwarnings".to_string());
72+
if let Some(rustc_path) = rustc_test_suite() {
73+
config.rustc_path = rustc_path;
74+
config.run_lib_path = rustc_lib_path();
75+
config.compile_lib_path = rustc_lib_path();
76+
}
77+
config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", get_sysroot().display()));
5478
config.host_rustcflags = Some("-Dwarnings".to_string());
5579
compiletest::run_tests(&config);
5680
}
@@ -68,9 +92,14 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) {
6892
config.src_base = PathBuf::from(path);
6993
config.target = target.to_owned();
7094
config.host = host.to_owned();
71-
config.rustc_path = MIRI_PATH.into();
95+
config.rustc_path = miri_path();
96+
if rustc_test_suite().is_some() {
97+
config.run_lib_path = rustc_lib_path();
98+
config.compile_lib_path = rustc_lib_path();
99+
}
72100
let mut flags = Vec::new();
73-
if fullmir {
101+
// if we are building as part of the rustc test suite, we already have fullmir for everything
102+
if fullmir && rustc_test_suite().is_none() {
74103
if host != target {
75104
// skip fullmir on nonhost
76105
return;

0 commit comments

Comments
 (0)