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
31 run_clippy_for_package(package, &["-D", "clippy::all", "-D", "clippy::pedantic"]);
37 #[cfg(feature = "internal")]
38 fn run_metadata_collection_lint() {
40 use std::time::SystemTime;
42 // Setup for validation
43 let metadata_output_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("util/gh-pages/lints.json");
44 let start_time = SystemTime::now();
46 // Run collection as is
47 std::env::set_var("ENABLE_METADATA_COLLECTION", "1");
48 run_clippy_for_package("clippy_lints", &["-A", "unfulfilled_lint_expectations"]);
50 // Check if cargo caching got in the way
51 if let Ok(file) = File::open(metadata_output_path) {
52 if let Ok(metadata) = file.metadata() {
53 if let Ok(last_modification) = metadata.modified() {
54 if last_modification > start_time {
55 // The output file has been modified. Most likely by a hungry
56 // metadata collection monster. So We'll return.
63 // Force cargo to invalidate the caches
64 filetime::set_file_mtime(
65 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("clippy_lints/src/lib.rs"),
66 filetime::FileTime::now(),
70 // Running the collection again
71 run_clippy_for_package("clippy_lints", &["-A", "unfulfilled_lint_expectations"]);
74 fn run_clippy_for_package(project: &str, args: &[&str]) {
75 let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
77 let mut command = Command::new(&*test_utils::CARGO_CLIPPY_PATH);
80 .current_dir(root_dir.join(project))
81 .env("CARGO_INCREMENTAL", "0")
84 .arg("--all-features");
86 if let Ok(dogfood_args) = std::env::var("__CLIPPY_DOGFOOD_ARGS") {
87 for arg in dogfood_args.split_whitespace() {
92 command.arg("--").args(args);
93 command.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
95 if cfg!(feature = "internal") {
96 // internal lints only exist if we build with the internal feature
97 command.args(["-D", "clippy::internal"]);
99 // running a clippy built without internal lints on the clippy source
100 // that contains e.g. `allow(clippy::invalid_paths)`
101 command.args(["-A", "unknown_lints"]);
104 let output = command.output().unwrap();
106 println!("status: {}", output.status);
107 println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
108 println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
110 assert!(output.status.success());