Skip to content

Commit d42af68

Browse files
committed
Add cargo dev dogfood
1 parent 2cc5211 commit d42af68

File tree

4 files changed

+64
-5
lines changed

4 files changed

+64
-5
lines changed

clippy_dev/src/dogfood.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::clippy_project_root;
2+
use std::process::Command;
3+
4+
/// # Panics
5+
///
6+
/// Panics if unable to run the dogfood test
7+
pub fn dogfood(fix: bool, allow_dirty: bool, allow_staged: bool) {
8+
let mut cmd = Command::new("cargo");
9+
10+
cmd.current_dir(clippy_project_root())
11+
.args(["test", "--test", "dogfood"])
12+
.args(["--features", "internal"])
13+
.args(["--", "dogfood_clippy"]);
14+
15+
let mut dogfood_args = Vec::new();
16+
if fix {
17+
dogfood_args.push("--fix");
18+
}
19+
20+
if allow_dirty {
21+
dogfood_args.push("--allow-dirty");
22+
}
23+
24+
if allow_staged {
25+
dogfood_args.push("--allow-staged");
26+
}
27+
28+
cmd.env("__CLIPPY_DOGFOOD_ARGS", dogfood_args.join(" "));
29+
30+
let output = cmd.output().expect("failed to run command");
31+
32+
println!("{}", String::from_utf8_lossy(&output.stdout));
33+
}

clippy_dev/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern crate rustc_lexer;
1111
use std::path::PathBuf;
1212

1313
pub mod bless;
14+
pub mod dogfood;
1415
pub mod fmt;
1516
pub mod lint;
1617
pub mod new_lint;

clippy_dev/src/main.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use clap::{Arg, ArgAction, ArgMatches, Command, PossibleValue};
6-
use clippy_dev::{bless, fmt, lint, new_lint, serve, setup, update_lints};
6+
use clippy_dev::{bless, dogfood, fmt, lint, new_lint, serve, setup, update_lints};
77
use indoc::indoc;
8+
89
fn main() {
910
let matches = get_clap_config();
1011

1112
match matches.subcommand() {
1213
Some(("bless", matches)) => {
1314
bless::bless(matches.contains_id("ignore-timestamp"));
1415
},
16+
Some(("dogfood", matches)) => {
17+
dogfood::dogfood(
18+
matches.contains_id("fix"),
19+
matches.contains_id("allow-dirty"),
20+
matches.contains_id("allow-staged"),
21+
);
22+
},
1523
Some(("fmt", matches)) => {
1624
fmt::run(matches.contains_id("check"), matches.contains_id("verbose"));
1725
},
@@ -98,6 +106,17 @@ fn get_clap_config() -> ArgMatches {
98106
.long("ignore-timestamp")
99107
.help("Include files updated before clippy was built"),
100108
),
109+
Command::new("dogfood").about("Runs the dogfood test").args([
110+
Arg::new("fix").long("fix").help("Apply the suggestions when possible"),
111+
Arg::new("allow-dirty")
112+
.long("allow-dirty")
113+
.help("Fix code even if the working directory has changes")
114+
.requires("fix"),
115+
Arg::new("allow-staged")
116+
.long("allow-staged")
117+
.help("Fix code even if the working directory has staged changes")
118+
.requires("fix"),
119+
]),
101120
Command::new("fmt")
102121
.about("Run rustfmt on all projects and tests")
103122
.args([

tests/dogfood.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ fn run_clippy_for_package(project: &str, args: &[&str]) {
7474
.env("CARGO_INCREMENTAL", "0")
7575
.arg("clippy")
7676
.arg("--all-targets")
77-
.arg("--all-features")
78-
.arg("--")
79-
.args(args)
80-
.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
77+
.arg("--all-features");
78+
79+
if let Ok(dogfood_args) = std::env::var("__CLIPPY_DOGFOOD_ARGS") {
80+
for arg in dogfood_args.split_whitespace() {
81+
command.arg(arg);
82+
}
83+
}
84+
85+
command.arg("--").args(args);
86+
command.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
8187

8288
if cfg!(feature = "internal") {
8389
// internal lints only exist if we build with the internal feature

0 commit comments

Comments
 (0)