]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_sta...
[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 output = Command::new(&*CLIPPY_PATH)
22         .current_dir(root_dir)
23         .env("CLIPPY_DOGFOOD", "1")
24         .env("CARGO_INCREMENTAL", "0")
25         .arg("clippy-preview")
26         .arg("--all-targets")
27         .arg("--all-features")
28         .arg("--")
29         .args(&["-D", "clippy::all"])
30         .args(&["-D", "clippy::internal"])
31         .args(&["-D", "clippy::pedantic"])
32         .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
33         .output()
34         .unwrap();
35     println!("status: {}", output.status);
36     println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
37     println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
38
39     assert!(output.status.success());
40 }
41
42 #[test]
43 fn dogfood_subprojects() {
44     // run clippy on remaining subprojects and fail the test if lint warnings are reported
45     if cargo::is_rustc_test_suite() {
46         return;
47     }
48     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
49
50     for d in &[
51         "clippy_workspace_tests",
52         "clippy_workspace_tests/src",
53         "clippy_workspace_tests/subcrate",
54         "clippy_workspace_tests/subcrate/src",
55         "clippy_dev",
56         "rustc_tools_util",
57     ] {
58         let output = Command::new(&*CLIPPY_PATH)
59             .current_dir(root_dir.join(d))
60             .env("CLIPPY_DOGFOOD", "1")
61             .env("CARGO_INCREMENTAL", "0")
62             .arg("clippy")
63             .arg("--")
64             .args(&["-D", "clippy::all"])
65             .args(&["-D", "clippy::pedantic"])
66             .arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
67             .output()
68             .unwrap();
69         println!("status: {}", output.status);
70         println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
71         println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
72
73         assert!(output.status.success());
74     }
75 }