]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
Merge commit 'c1664c50b27a51f7a78c93ba65558e7c33eabee6' into clippyup
[rust.git] / tests / dogfood.rs
1 // Dogfood cannot run on Windows
2 #![cfg(not(windows))]
3 #![feature(once_cell)]
4
5 use std::lazy::SyncLazy;
6 use std::path::PathBuf;
7 use std::process::Command;
8
9 mod cargo;
10
11 static CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| cargo::TARGET_LIB.join("cargo-clippy"));
12
13 #[test]
14 fn dogfood_clippy() {
15     // run clippy on itself and fail the test if lint warnings are reported
16     if cargo::is_rustc_test_suite() {
17         return;
18     }
19     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
20
21     let mut command = Command::new(&*CLIPPY_PATH);
22     command
23         .current_dir(root_dir)
24         .env("CLIPPY_DOGFOOD", "1")
25         .env("CARGO_INCREMENTAL", "0")
26         .arg("clippy-preview")
27         .arg("--all-targets")
28         .arg("--all-features")
29         .arg("--")
30         .args(&["-D", "clippy::all"])
31         .args(&["-D", "clippy::pedantic"])
32         .arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
33
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"]);
37     }
38
39     let output = command.output().unwrap();
40
41     println!("status: {}", output.status);
42     println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
43     println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
44
45     assert!(output.status.success());
46 }
47
48 #[test]
49 fn dogfood_subprojects() {
50     // run clippy on remaining subprojects and fail the test if lint warnings are reported
51     if cargo::is_rustc_test_suite() {
52         return;
53     }
54     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
55
56     for d in &[
57         "clippy_workspace_tests",
58         "clippy_workspace_tests/src",
59         "clippy_workspace_tests/subcrate",
60         "clippy_workspace_tests/subcrate/src",
61         "clippy_dev",
62         "rustc_tools_util",
63     ] {
64         let output = Command::new(&*CLIPPY_PATH)
65             .current_dir(root_dir.join(d))
66             .env("CLIPPY_DOGFOOD", "1")
67             .env("CARGO_INCREMENTAL", "0")
68             .arg("clippy")
69             .arg("--")
70             .args(&["-D", "clippy::all"])
71             .args(&["-D", "clippy::pedantic"])
72             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
73             .output()
74             .unwrap();
75         println!("status: {}", output.status);
76         println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
77         println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
78
79         assert!(output.status.success());
80     }
81 }