1 // Dogfood cannot run on Windows
5 use std::lazy::SyncLazy;
6 use std::path::{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 fn clean(cwd: &Path, target_dir: &Path) {
55 .env("CARGO_TARGET_DIR", target_dir)
57 .args(&["-p", "subcrate"])
58 .args(&["-p", "path_dep"])
63 if cargo::is_rustc_test_suite() {
66 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
67 let target_dir = root.join("target").join("dogfood");
68 let cwd = root.join("clippy_workspace_tests");
70 // Make sure we start with a clean state
71 clean(&cwd, &target_dir);
73 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
74 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
75 let output = Command::new(&*CLIPPY_PATH)
77 .env("CLIPPY_DOGFOOD", "1")
78 .env("CARGO_INCREMENTAL", "0")
80 .args(&["-p", "subcrate"])
83 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
84 .args(&["--cfg", r#"feature="primary_package_test""#])
87 println!("status: {}", output.status);
88 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
89 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
91 assert!(output.status.success());
93 // Make sure we start with a clean state
94 clean(&cwd, &target_dir);
96 // Test that without the `--no-deps` argument, `path_dep` is linted.
97 let output = Command::new(&*CLIPPY_PATH)
99 .env("CLIPPY_DOGFOOD", "1")
100 .env("CARGO_INCREMENTAL", "0")
102 .args(&["-p", "subcrate"])
104 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
105 .args(&["--cfg", r#"feature="primary_package_test""#])
108 println!("status: {}", output.status);
109 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
110 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
112 assert!(!output.status.success());
115 // run clippy on remaining subprojects and fail the test if lint warnings are reported
116 if cargo::is_rustc_test_suite() {
119 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
121 // NOTE: `path_dep` crate is omitted on purpose here
123 "clippy_workspace_tests",
124 "clippy_workspace_tests/src",
125 "clippy_workspace_tests/subcrate",
126 "clippy_workspace_tests/subcrate/src",
130 let output = Command::new(&*CLIPPY_PATH)
131 .current_dir(root_dir.join(d))
132 .env("CLIPPY_DOGFOOD", "1")
133 .env("CARGO_INCREMENTAL", "0")
136 .args(&["-D", "clippy::all"])
137 .args(&["-D", "clippy::pedantic"])
138 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
141 println!("status: {}", output.status);
142 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
143 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
145 assert!(output.status.success());
148 // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
149 // same time, so we test this immediately after the dogfood for workspaces.
150 test_no_deps_ignores_path_deps_in_workspaces();