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());
50 fn dogfood_subprojects() {
51 fn test_no_deps_ignores_path_deps_in_workspaces() {
52 if cargo::is_rustc_test_suite() {
55 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
56 let target_dir = root.join("target").join("dogfood");
57 let cwd = root.join("clippy_workspace_tests");
59 // Make sure we start with a clean state
62 .env("CARGO_TARGET_DIR", &target_dir)
64 .args(&["-p", "subcrate"])
65 .args(&["-p", "path_dep"])
69 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
70 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
71 let output = Command::new(&*CLIPPY_PATH)
73 .env("CLIPPY_DOGFOOD", "1")
74 .env("CARGO_INCREMENTAL", "0")
76 .args(&["-p", "subcrate"])
79 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
80 .args(&["--cfg", r#"feature="primary_package_test""#])
83 println!("status: {}", output.status);
84 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
85 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
87 assert!(output.status.success());
89 let lint_path_dep = || {
90 // Test that without the `--no-deps` argument, `path_dep` is linted.
91 let output = Command::new(&*CLIPPY_PATH)
93 .env("CLIPPY_DOGFOOD", "1")
94 .env("CARGO_INCREMENTAL", "0")
96 .args(&["-p", "subcrate"])
98 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
99 .args(&["--cfg", r#"feature="primary_package_test""#])
102 println!("status: {}", output.status);
103 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
104 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
106 assert!(!output.status.success());
108 String::from_utf8(output.stderr)
110 .contains("error: empty `loop {}` wastes CPU cycles")
114 // Make sure Cargo is aware of the removal of `--no-deps`.
117 let successful_build = || {
118 let output = Command::new(&*CLIPPY_PATH)
120 .env("CLIPPY_DOGFOOD", "1")
121 .env("CARGO_INCREMENTAL", "0")
123 .args(&["-p", "subcrate"])
125 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
128 println!("status: {}", output.status);
129 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
130 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
132 assert!(output.status.success());
137 // Trigger a sucessful build, so Cargo would like to cache the build result.
140 // Make sure there's no spurious rebuild when nothing changes.
141 let stderr = String::from_utf8(successful_build().stderr).unwrap();
142 assert!(!stderr.contains("Compiling"));
143 assert!(!stderr.contains("Checking"));
144 assert!(stderr.contains("Finished"));
146 // Make sure Cargo is aware of the new `--cfg` flag.
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();