]> git.lizzy.rs Git - rust.git/blob - tests/dogfood.rs
Fix dogfood to use cargo mod too
[rust.git] / tests / dogfood.rs
1 use std::path::PathBuf;
2 use std::process::Command;
3
4 #[allow(dead_code)]
5 mod cargo;
6
7 fn clippy_path() -> PathBuf {
8     let build_info = cargo::BuildInfo::new();
9     build_info.target_lib().join("cargo-clippy")
10 }
11
12 #[test]
13 fn dogfood_clippy() {
14     // run clippy on itself and fail the test if lint warnings are reported
15     if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
16         return;
17     }
18     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
19     let clippy_binary = clippy_path();
20
21     let output = Command::new(clippy_binary)
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 option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
46         return;
47     }
48     let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
49     let clippy_binary = clippy_path();
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_binary)
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 }