]> git.lizzy.rs Git - rust.git/blob - tests/compiletest.rs
7ce9636fc05f07037bf28cb353dcc19fd3621136
[rust.git] / tests / compiletest.rs
1 extern crate compiletest_rs as compiletest;
2
3 use std::path::PathBuf;
4
5 fn run_mode(mode: &'static str) {
6     // Disable rustc's new error fomatting. It breaks these tests.
7     std::env::remove_var("RUST_NEW_ERROR_FORMAT");
8
9     // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
10     let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
11     let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
12     let sysroot = match (home, toolchain) {
13         (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
14         _ => option_env!("RUST_SYSROOT")
15             .expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
16             .to_owned(),
17     };
18     let flags = format!("--sysroot {} -Dwarnings", sysroot);
19
20     // FIXME: read directories in sysroot/lib/rustlib and generate the test targets from that
21     let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"];
22
23     for &target in targets {
24         use std::io::Write;
25         let stderr = std::io::stderr();
26         write!(stderr.lock(), "running tests for target {}", target).unwrap();
27         let mut config = compiletest::default_config();
28         config.host_rustcflags = Some(flags.clone());
29         config.mode = mode.parse().expect("Invalid mode");
30         config.run_lib_path = format!("{}/lib/rustlib/{}/lib", sysroot, target);
31         config.rustc_path = "target/debug/miri".into();
32         config.src_base = PathBuf::from(format!("tests/{}", mode));
33         config.target = target.to_owned();
34         config.target_rustcflags = Some(flags.clone());
35         compiletest::run_tests(&config);
36     }
37 }
38
39 #[test]
40 fn compile_test() {
41     run_mode("compile-fail");
42     run_mode("run-pass");
43 }