]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
Auto merge of #5121 - lzutao:comptest, r=flip1995
[rust.git] / tests / dogfood.rs
1 use lazy_static::lazy_static;
2 use std::path::PathBuf;
3 use std::process::Command;
4
5 #[allow(dead_code)]
6 mod cargo;
7
8 lazy_static! {
9     static ref CLIPPY_PATH: PathBuf = {
10         let build_info = cargo::BuildInfo::new();
11         build_info.target_lib().join("cargo-clippy")
12     };
13 }
14
15 #[test]
16 fn dogfood_clippy() {
17     // run clippy on itself and fail the test if lint warnings are reported
18     if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
19         return;
20     }
21     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
22
23     let output = Command::new(&*CLIPPY_PATH)
24         .current_dir(root_dir)
25         .env("CLIPPY_DOGFOOD", "1")
26         .env("CARGO_INCREMENTAL", "0")
27         .arg("clippy-preview")
28         .arg("--all-targets")
29         .arg("--all-features")
30         .arg("--")
31         .args(&["-D", "clippy::all"])
32         .args(&["-D", "clippy::internal"])
33         .args(&["-D", "clippy::pedantic"])
34         .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
35         .output()
36         .unwrap();
37     println!("status: {}", output.status);
38     println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
39     println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
40
41     assert!(output.status.success());
42 }
43
44 #[test]
45 fn dogfood_subprojects() {
46     // run clippy on remaining subprojects and fail the test if lint warnings are reported
47     if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
48         return;
49     }
50     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
51
52     for d in &[
53         "clippy_workspace_tests",
54         "clippy_workspace_tests/src",
55         "clippy_workspace_tests/subcrate",
56         "clippy_workspace_tests/subcrate/src",
57         "clippy_dev",
58         "rustc_tools_util",
59     ] {
60         let output = Command::new(&*CLIPPY_PATH)
61             .current_dir(root_dir.join(d))
62             .env("CLIPPY_DOGFOOD", "1")
63             .env("CARGO_INCREMENTAL", "0")
64             .arg("clippy")
65             .arg("--")
66             .args(&["-D", "clippy::all"])
67             .args(&["-D", "clippy::pedantic"])
68             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
69             .output()
70             .unwrap();
71         println!("status: {}", output.status);
72         println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
73         println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
74
75         assert!(output.status.success());
76     }
77 }