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 output = Command::new(&*CLIPPY_PATH)
22 .current_dir(root_dir)
23 .env("CLIPPY_DOGFOOD", "1")
24 .env("CARGO_INCREMENTAL", "0")
25 .arg("clippy-preview")
27 .arg("--all-features")
29 .args(&["-D", "clippy::all"])
30 .args(&["-D", "clippy::internal"])
31 .args(&["-D", "clippy::pedantic"])
32 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
35 println!("status: {}", output.status);
36 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
37 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
39 assert!(output.status.success());
43 fn dogfood_subprojects() {
44 fn test_no_deps_ignores_path_deps_in_workspaces() {
45 fn clean(cwd: &Path, target_dir: &Path) {
48 .env("CARGO_TARGET_DIR", target_dir)
50 .args(&["-p", "subcrate"])
51 .args(&["-p", "path_dep"])
56 if cargo::is_rustc_test_suite() {
59 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
60 let target_dir = root.join("target").join("dogfood");
61 let cwd = root.join("clippy_workspace_tests");
63 // Make sure we start with a clean state
64 clean(&cwd, &target_dir);
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 // Make sure we start with a clean state
87 clean(&cwd, &target_dir);
89 // Test that without the `--no-deps` argument, `path_dep` is linted.
90 let output = Command::new(&*CLIPPY_PATH)
92 .env("CLIPPY_DOGFOOD", "1")
93 .env("CARGO_INCREMENTAL", "0")
95 .args(&["-p", "subcrate"])
97 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
98 .args(&["--cfg", r#"feature="primary_package_test""#])
101 println!("status: {}", output.status);
102 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
103 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
105 assert!(!output.status.success());
108 // run clippy on remaining subprojects and fail the test if lint warnings are reported
109 if cargo::is_rustc_test_suite() {
112 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
114 // NOTE: `path_dep` crate is omitted on purpose here
116 "clippy_workspace_tests",
117 "clippy_workspace_tests/src",
118 "clippy_workspace_tests/subcrate",
119 "clippy_workspace_tests/subcrate/src",
123 let output = Command::new(&*CLIPPY_PATH)
124 .current_dir(root_dir.join(d))
125 .env("CLIPPY_DOGFOOD", "1")
126 .env("CARGO_INCREMENTAL", "0")
129 .args(&["-D", "clippy::all"])
130 .args(&["-D", "clippy::pedantic"])
131 .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
134 println!("status: {}", output.status);
135 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
136 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
138 assert!(output.status.success());
141 // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
142 // same time, so we test this immediately after the dogfood for workspaces.
143 test_no_deps_ignores_path_deps_in_workspaces();