Skip to content

Commit dca1be6

Browse files
authored
Merge pull request #300 from oli-obk/rustc_tests
Get the test suite working inside the rustc test suite
2 parents 63c4843 + 8019deb commit dca1be6

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tests/compiletest.rs

+37-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,14 @@ 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+
config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", get_sysroot().display()));
77+
} else {
78+
config.target_rustcflags = Some("-Dwarnings".to_owned());
79+
}
5480
config.host_rustcflags = Some("-Dwarnings".to_string());
5581
compiletest::run_tests(&config);
5682
}
@@ -68,9 +94,14 @@ fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) {
6894
config.src_base = PathBuf::from(path);
6995
config.target = target.to_owned();
7096
config.host = host.to_owned();
71-
config.rustc_path = MIRI_PATH.into();
97+
config.rustc_path = miri_path();
98+
if rustc_test_suite().is_some() {
99+
config.run_lib_path = rustc_lib_path();
100+
config.compile_lib_path = rustc_lib_path();
101+
}
72102
let mut flags = Vec::new();
73-
if fullmir {
103+
// if we are building as part of the rustc test suite, we already have fullmir for everything
104+
if fullmir && rustc_test_suite().is_none() {
74105
if host != target {
75106
// skip fullmir on nonhost
76107
return;

0 commit comments

Comments
 (0)