]> git.lizzy.rs Git - rust.git/blob - tests/compile-test.rs
Merge pull request #2199 from sinkuu/needless_pass_by_value_method
[rust.git] / tests / compile-test.rs
1 extern crate compiletest_rs as compiletest;
2
3 use std::path::PathBuf;
4 use std::env::{set_var, var};
5
6 fn clippy_driver_path() -> PathBuf {
7     if let Some(path) = option_env!("CLIPPY_DRIVER_PATH") {
8         PathBuf::from(path)
9     } else {
10         PathBuf::from(concat!("target/", env!("PROFILE"), "/clippy-driver"))
11     }
12 }
13
14 fn run_mode(dir: &'static str, mode: &'static str) {
15     let mut config = compiletest::Config::default();
16
17     let cfg_mode = mode.parse().expect("Invalid mode");
18     config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps -Dwarnings".to_owned());
19     if let Ok(name) = var::<&str>("TESTNAME") {
20         let s: String = name.to_owned();
21         config.filter = Some(s)
22     }
23
24     config.mode = cfg_mode;
25     config.build_base = PathBuf::from("target/debug/test_build_base");
26     config.src_base = PathBuf::from(format!("tests/{}", dir));
27     config.rustc_path = clippy_driver_path();
28
29     compiletest::run_tests(&config);
30 }
31
32 fn prepare_env() {
33     set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
34     set_var("CLIPPY_TESTS", "true");
35     set_var("RUST_BACKTRACE", "0");
36 }
37
38 #[test]
39 fn compile_test() {
40     prepare_env();
41     run_mode("run-pass", "run-pass");
42     run_mode("ui", "ui");
43 }