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")
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());
49 fn dogfood_subprojects() {
50 fn test_no_deps_ignores_path_deps_in_workspaces() {
51 fn clean(cwd: &Path, target_dir: &Path) {
54 .env("CARGO_TARGET_DIR", target_dir)
56 .args(&["-p", "subcrate"])
57 .args(&["-p", "path_dep"])
62 if cargo::is_rustc_test_suite() {
65 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
66 let target_dir = root.join("target").join("dogfood");
67 let cwd = root.join("clippy_workspace_tests");
69 // Make sure we start with a clean state
70 clean(&cwd, &target_dir);
72 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
73 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
74 let output = Command::new(&*CLIPPY_PATH)
76 .env("CLIPPY_DOGFOOD", "1")
77 .env("CARGO_INCREMENTAL", "0")
79 .args(&["-p", "subcrate"])
82 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
83 .args(&["--cfg", r#"feature="primary_package_test""#])
86 println!("status: {}", output.status);
87 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
88 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
90 assert!(output.status.success());
92 // Make sure we start with a clean state
93 clean(&cwd, &target_dir);
95 // Test that without the `--no-deps` argument, `path_dep` is linted.
96 let output = Command::new(&*CLIPPY_PATH)
98 .env("CLIPPY_DOGFOOD", "1")
99 .env("CARGO_INCREMENTAL", "0")
101 .args(&["-p", "subcrate"])
103 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
104 .args(&["--cfg", r#"feature="primary_package_test""#])
107 println!("status: {}", output.status);
108 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
109 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
111 assert!(!output.status.success());
114 // run clippy on remaining subprojects and fail the test if lint warnings are reported
115 if cargo::is_rustc_test_suite() {
118 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
120 // NOTE: `path_dep` crate is omitted on purpose here
122 "clippy_workspace_tests",
123 "clippy_workspace_tests/src",
124 "clippy_workspace_tests/subcrate",
125 "clippy_workspace_tests/subcrate/src",
131 let mut command = Command::new(&*CLIPPY_PATH);
133 .current_dir(root_dir.join(d))
134 .env("CLIPPY_DOGFOOD", "1")
135 .env("CARGO_INCREMENTAL", "0")
137 .arg("--all-targets")
138 .arg("--all-features")
140 .args(&["-D", "clippy::all"])
141 .args(&["-D", "clippy::pedantic"])
142 .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
144 // internal lints only exist if we build with the internal-lints feature
145 if cfg!(feature = "internal-lints") {
146 command.args(&["-D", "clippy::internal"]);
149 let output = command.output().unwrap();
151 println!("status: {}", output.status);
152 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
153 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
155 assert!(output.status.success());
158 // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
159 // same time, so we test this immediately after the dogfood for workspaces.
160 test_no_deps_ignores_path_deps_in_workspaces();