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);
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");
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");
67 fn run_clippy_for_package(project: &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 .args(&["-D", "clippy::all"])
80 .args(&["-D", "clippy::pedantic"])
81 .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
83 // internal lints only exist if we build with the internal feature
84 if cfg!(feature = "internal") {
85 command.args(&["-D", "clippy::internal"]);
88 let output = command.output().unwrap();
90 println!("status: {}", output.status);
91 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
92 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
94 assert!(output.status.success());