]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
Use cargo's "PROFILE" envvar and set CLIPPY_DOGFOOD
[rust.git] / tests / dogfood.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #[test]
11 fn dogfood_runner() {
12     dogfood();
13     dogfood_tests();
14 }
15
16 fn dogfood() {
17     if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
18         return;
19     }
20     let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
21     let clippy_cmd = std::path::Path::new(&root_dir)
22         .join("target")
23         .join(env!("PROFILE"))
24         .join("cargo-clippy");
25
26     std::env::set_current_dir(root_dir).unwrap();
27     let output = std::process::Command::new(clippy_cmd)
28         .env("CLIPPY_DOGFOOD", "1")
29         .arg("clippy")
30         .arg("--all-targets")
31         .arg("--all-features")
32         .arg("--")
33         .args(&["-D", "clippy::all"])
34         .args(&["-D", "clippy::internal"])
35         .args(&["-D", "clippy::pedantic"])
36         .output()
37         .unwrap();
38     println!("status: {}", output.status);
39     println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
40     println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
41
42     assert!(output.status.success());
43 }
44
45 fn dogfood_tests() {
46     if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
47         return;
48     }
49     let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
50     let clippy_cmd = std::path::Path::new(&root_dir)
51         .join("target")
52         .join(env!("PROFILE"))
53         .join("cargo-clippy");
54
55     for d in &[
56         "clippy_workspace_tests",
57         "clippy_workspace_tests/src",
58         "clippy_workspace_tests/subcrate",
59         "clippy_workspace_tests/subcrate/src",
60         "clippy_dev",
61         "rustc_tools_util",
62     ] {
63         std::env::set_current_dir(root_dir.join(d)).unwrap();
64         let output = std::process::Command::new(&clippy_cmd)
65             .env("CLIPPY_DOGFOOD", "1")
66             .arg("clippy")
67             .arg("--")
68             .args(&["-D", "clippy::all"])
69             .args(&["-D", "clippy::pedantic"])
70             .output()
71             .unwrap();
72         println!("status: {}", output.status);
73         println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
74         println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
75
76         assert!(output.status.success());
77     }
78 }