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