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")
28 .arg("--all-features")
30 .args(&["-D", "clippy::all"])
31 .args(&["-D", "clippy::pedantic"])
32 .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
34 // internal lints only exist if we build with the internal-lints feature
35 if cfg!(feature = "internal-lints") {
36 command.args(&["-D", "clippy::internal"]);
39 let output = command.output().unwrap();
41 println!("status: {}", output.status);
42 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
43 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
45 assert!(output.status.success());
48 fn test_no_deps_ignores_path_deps_in_workspaces() {
49 if cargo::is_rustc_test_suite() {
52 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
53 let target_dir = root.join("target").join("dogfood");
54 let cwd = root.join("clippy_workspace_tests");
56 // Make sure we start with a clean state
59 .env("CARGO_TARGET_DIR", &target_dir)
61 .args(&["-p", "subcrate"])
62 .args(&["-p", "path_dep"])
66 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
67 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
68 let output = Command::new(&*CLIPPY_PATH)
70 .env("CLIPPY_DOGFOOD", "1")
71 .env("CARGO_INCREMENTAL", "0")
73 .args(&["-p", "subcrate"])
76 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
77 .args(&["--cfg", r#"feature="primary_package_test""#])
80 println!("status: {}", output.status);
81 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
82 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
84 assert!(output.status.success());
86 let lint_path_dep = || {
87 // Test that without the `--no-deps` argument, `path_dep` is linted.
88 let output = Command::new(&*CLIPPY_PATH)
90 .env("CLIPPY_DOGFOOD", "1")
91 .env("CARGO_INCREMENTAL", "0")
93 .args(&["-p", "subcrate"])
95 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
96 .args(&["--cfg", r#"feature="primary_package_test""#])
99 println!("status: {}", output.status);
100 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
101 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
103 assert!(!output.status.success());
105 String::from_utf8(output.stderr)
107 .contains("error: empty `loop {}` wastes CPU cycles")
111 // Make sure Cargo is aware of the removal of `--no-deps`.
114 let successful_build = || {
115 let output = Command::new(&*CLIPPY_PATH)
117 .env("CLIPPY_DOGFOOD", "1")
118 .env("CARGO_INCREMENTAL", "0")
120 .args(&["-p", "subcrate"])
122 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
125 println!("status: {}", output.status);
126 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
127 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
129 assert!(output.status.success());
134 // Trigger a sucessful build, so Cargo would like to cache the build result.
137 // Make sure there's no spurious rebuild when nothing changes.
138 let stderr = String::from_utf8(successful_build().stderr).unwrap();
139 assert!(!stderr.contains("Compiling"));
140 assert!(!stderr.contains("Checking"));
141 assert!(stderr.contains("Finished"));
143 // Make sure Cargo is aware of the new `--cfg` flag.
148 fn dogfood_subprojects() {
149 // run clippy on remaining subprojects and fail the test if lint warnings are reported
150 if cargo::is_rustc_test_suite() {
153 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
155 // NOTE: `path_dep` crate is omitted on purpose here
157 "clippy_workspace_tests",
158 "clippy_workspace_tests/src",
159 "clippy_workspace_tests/subcrate",
160 "clippy_workspace_tests/subcrate/src",
166 let mut command = Command::new(&*CLIPPY_PATH);
168 .current_dir(root_dir.join(d))
169 .env("CLIPPY_DOGFOOD", "1")
170 .env("CARGO_INCREMENTAL", "0")
172 .arg("--all-targets")
173 .arg("--all-features")
175 .args(&["-D", "clippy::all"])
176 .args(&["-D", "clippy::pedantic"])
177 .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
179 // internal lints only exist if we build with the internal-lints feature
180 if cfg!(feature = "internal-lints") {
181 command.args(&["-D", "clippy::internal"]);
184 let output = command.output().unwrap();
186 println!("status: {}", output.status);
187 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
188 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
190 assert!(output.status.success());
193 // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
194 // same time, so we test this immediately after the dogfood for workspaces.
195 test_no_deps_ignores_path_deps_in_workspaces();