1 // Dogfood cannot run on Windows
5 use std::lazy::SyncLazy;
6 use std::path::PathBuf;
7 use std::process::Command;
11 static CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| cargo::TARGET_LIB.join("cargo-clippy"));
15 // run clippy on itself and fail the test if lint warnings are reported
16 if cargo::is_rustc_test_suite() {
19 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
21 let mut command = Command::new(&*CLIPPY_PATH);
23 .current_dir(root_dir)
24 .env("CLIPPY_DOGFOOD", "1")
25 .env("CARGO_INCREMENTAL", "0")
26 .arg("clippy-preview")
28 .arg("--all-features")
29 .args(&["-p", "clippy_lints", "-p", "clippy_utils", "-p", "rustc_tools_util"])
31 .args(&["-D", "clippy::all"])
32 .args(&["-D", "clippy::pedantic"])
33 .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
35 // internal lints only exist if we build with the internal-lints feature
36 if cfg!(feature = "internal-lints") {
37 command.args(&["-D", "clippy::internal"]);
40 let output = command.output().unwrap();
42 println!("status: {}", output.status);
43 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
44 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
46 assert!(output.status.success());
49 fn test_no_deps_ignores_path_deps_in_workspaces() {
50 if cargo::is_rustc_test_suite() {
53 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
54 let target_dir = root.join("target").join("dogfood");
55 let cwd = root.join("clippy_workspace_tests");
57 // Make sure we start with a clean state
60 .env("CARGO_TARGET_DIR", &target_dir)
62 .args(&["-p", "subcrate"])
63 .args(&["-p", "path_dep"])
67 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
68 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
69 let output = Command::new(&*CLIPPY_PATH)
71 .env("CLIPPY_DOGFOOD", "1")
72 .env("CARGO_INCREMENTAL", "0")
74 .args(&["-p", "subcrate"])
77 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
78 .args(&["--cfg", r#"feature="primary_package_test""#])
81 println!("status: {}", output.status);
82 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
83 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
85 assert!(output.status.success());
87 let lint_path_dep = || {
88 // Test that without the `--no-deps` argument, `path_dep` is linted.
89 let output = Command::new(&*CLIPPY_PATH)
91 .env("CLIPPY_DOGFOOD", "1")
92 .env("CARGO_INCREMENTAL", "0")
94 .args(&["-p", "subcrate"])
96 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
97 .args(&["--cfg", r#"feature="primary_package_test""#])
100 println!("status: {}", output.status);
101 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
102 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
104 assert!(!output.status.success());
106 String::from_utf8(output.stderr)
108 .contains("error: empty `loop {}` wastes CPU cycles")
112 // Make sure Cargo is aware of the removal of `--no-deps`.
115 let successful_build = || {
116 let output = Command::new(&*CLIPPY_PATH)
118 .env("CLIPPY_DOGFOOD", "1")
119 .env("CARGO_INCREMENTAL", "0")
121 .args(&["-p", "subcrate"])
123 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
126 println!("status: {}", output.status);
127 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
128 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
130 assert!(output.status.success());
135 // Trigger a sucessful build, so Cargo would like to cache the build result.
138 // Make sure there's no spurious rebuild when nothing changes.
139 let stderr = String::from_utf8(successful_build().stderr).unwrap();
140 assert!(!stderr.contains("Compiling"));
141 assert!(!stderr.contains("Checking"));
142 assert!(stderr.contains("Finished"));
144 // Make sure Cargo is aware of the new `--cfg` flag.
149 fn dogfood_subprojects() {
150 // run clippy on remaining subprojects and fail the test if lint warnings are reported
151 if cargo::is_rustc_test_suite() {
154 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
156 // NOTE: `path_dep` crate is omitted on purpose here
158 "clippy_workspace_tests",
159 "clippy_workspace_tests/src",
160 "clippy_workspace_tests/subcrate",
161 "clippy_workspace_tests/subcrate/src",
165 let output = Command::new(&*CLIPPY_PATH)
166 .current_dir(root_dir.join(d))
167 .env("CLIPPY_DOGFOOD", "1")
168 .env("CARGO_INCREMENTAL", "0")
171 .args(&["-D", "clippy::all"])
172 .args(&["-D", "clippy::pedantic"])
173 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
176 println!("status: {}", output.status);
177 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
178 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
180 assert!(output.status.success());
183 // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
184 // same time, so we test this immediately after the dogfood for workspaces.
185 test_no_deps_ignores_path_deps_in_workspaces();