1 //! This test is a part of quality control and makes clippy eat what it produces. Awesome lints and
2 //! long error messages
4 //! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
7 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
8 #![warn(rust_2018_idioms, unused_lifetimes)]
10 use std::path::PathBuf;
11 use std::process::Command;
12 use test_utils::IS_RUSTC_TEST_SUITE;
18 if IS_RUSTC_TEST_SUITE {
22 // "" is the root package
23 for package in &["", "clippy_dev", "clippy_lints", "clippy_utils", "rustc_tools_util"] {
24 run_clippy_for_package(package, &["-D", "clippy::all", "-D", "clippy::pedantic"]);
30 #[cfg(feature = "internal")]
31 fn run_metadata_collection_lint() {
33 use std::time::SystemTime;
35 // Setup for validation
36 let metadata_output_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("util/gh-pages/lints.json");
37 let start_time = SystemTime::now();
39 // Run collection as is
40 std::env::set_var("ENABLE_METADATA_COLLECTION", "1");
41 run_clippy_for_package("clippy_lints", &["-A", "unfulfilled_lint_expectations"]);
43 // Check if cargo caching got in the way
44 if let Ok(file) = File::open(metadata_output_path) {
45 if let Ok(metadata) = file.metadata() {
46 if let Ok(last_modification) = metadata.modified() {
47 if last_modification > start_time {
48 // The output file has been modified. Most likely by a hungry
49 // metadata collection monster. So We'll return.
56 // Force cargo to invalidate the caches
57 filetime::set_file_mtime(
58 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("clippy_lints/src/lib.rs"),
59 filetime::FileTime::now(),
63 // Running the collection again
64 run_clippy_for_package("clippy_lints", &["-A", "unfulfilled_lint_expectations"]);
67 fn run_clippy_for_package(project: &str, args: &[&str]) {
68 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
70 let mut command = Command::new(&*test_utils::CARGO_CLIPPY_PATH);
73 .current_dir(root_dir.join(project))
74 .env("CARGO_INCREMENTAL", "0")
77 .arg("--all-features");
79 if let Ok(dogfood_args) = std::env::var("__CLIPPY_DOGFOOD_ARGS") {
80 for arg in dogfood_args.split_whitespace() {
85 command.arg("--").args(args);
86 command.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
88 if cfg!(feature = "internal") {
89 // internal lints only exist if we build with the internal feature
90 command.args(["-D", "clippy::internal"]);
92 // running a clippy built without internal lints on the clippy source
93 // that contains e.g. `allow(clippy::invalid_paths)`
94 command.args(["-A", "unknown_lints"]);
97 let output = command.output().unwrap();
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());