]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
add internal-lints feature to enable clippys internal lints (off by default)
[rust.git] / tests / dogfood.rs
1 // Dogfood cannot run on Windows
2 #![cfg(not(windows))]
3 #![feature(once_cell)]
4
5 use std::lazy::SyncLazy;
6 use std::path::PathBuf;
7 use std::process::Command;
8
9 mod cargo;
10
11 static CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| cargo::TARGET_LIB.join("cargo-clippy"));
12
13 #[test]
14 fn dogfood_clippy() {
15     // run clippy on itself and fail the test if lint warnings are reported
16     if cargo::is_rustc_test_suite() {
17         return;
18     }
19     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
20
21     let output = if cfg!(feature = "internal-lints") {
22         // with internal lints and internal warnings
23         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             .args(&["--features", "internal-lints"])
31             .arg("--")
32             .args(&["-D", "clippy::all"])
33             .args(&["-D", "clippy::pedantic"])
34             .args(&["-D", "clippy::internal"])
35             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
36             .output()
37             .unwrap()
38     } else {
39         // without internal lints or warnings
40         Command::new(&*CLIPPY_PATH)
41             .current_dir(root_dir)
42             .env("CLIPPY_DOGFOOD", "1")
43             .env("CARGO_INCREMENTAL", "0")
44             .arg("clippy-preview")
45             .arg("--all-targets")
46             .arg("--all-features")
47             .arg("--")
48             .args(&["-D", "clippy::all"])
49             .args(&["-D", "clippy::pedantic"])
50             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
51             .output()
52             .unwrap()
53     };
54     println!("status: {}", output.status);
55     println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
56     println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
57
58     assert!(output.status.success());
59 }
60
61 #[test]
62 fn dogfood_subprojects() {
63     // run clippy on remaining subprojects and fail the test if lint warnings are reported
64     if cargo::is_rustc_test_suite() {
65         return;
66     }
67     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
68
69     for d in &[
70         "clippy_workspace_tests",
71         "clippy_workspace_tests/src",
72         "clippy_workspace_tests/subcrate",
73         "clippy_workspace_tests/subcrate/src",
74         "clippy_dev",
75         "rustc_tools_util",
76     ] {
77         let output = Command::new(&*CLIPPY_PATH)
78             .current_dir(root_dir.join(d))
79             .env("CLIPPY_DOGFOOD", "1")
80             .env("CARGO_INCREMENTAL", "0")
81             .arg("clippy")
82             .arg("--")
83             .args(&["-D", "clippy::all"])
84             .args(&["-D", "clippy::pedantic"])
85             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
86             .output()
87             .unwrap();
88         println!("status: {}", output.status);
89         println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
90         println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
91
92         assert!(output.status.success());
93     }
94 }