Skip to content

Commit d4488a5

Browse files
committed
Auto merge of #9039 - Serial-ATA:dev-dogfood, r=giraffate
Add `cargo dev dogfood` changelog: Add `cargo dev dogfood` Part of #5394
2 parents 23db5ce + 131770d commit d4488a5

File tree

5 files changed

+66
-6
lines changed

5 files changed

+66
-6
lines changed

book/src/development/basics.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ cargo uitest
5959
# only run UI tests starting with `test_`
6060
TESTNAME="test_" cargo uitest
6161
# only run dogfood tests
62-
cargo test --test dogfood
62+
cargo dev dogfood
6363
```
6464

6565
If the output of a [UI test] differs from the expected output, you can update
@@ -97,6 +97,8 @@ cargo dev deprecate
9797
cargo dev setup git-hook
9898
# (experimental) Setup Clippy to work with IntelliJ-Rust
9999
cargo dev setup intellij
100+
# runs the `dogfood` tests
101+
cargo dev dogfood
100102
```
101103

102104
More about intellij command usage and reasons

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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;
88

99
fn main() {
@@ -13,6 +13,13 @@ fn main() {
1313
Some(("bless", matches)) => {
1414
bless::bless(matches.contains_id("ignore-timestamp"));
1515
},
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+
},
1623
Some(("fmt", matches)) => {
1724
fmt::run(matches.contains_id("check"), matches.contains_id("verbose"));
1825
},
@@ -104,6 +111,17 @@ fn get_clap_config() -> ArgMatches {
104111
.long("ignore-timestamp")
105112
.help("Include files updated before clippy was built"),
106113
),
114+
Command::new("dogfood").about("Runs the dogfood test").args([
115+
Arg::new("fix").long("fix").help("Apply the suggestions when possible"),
116+
Arg::new("allow-dirty")
117+
.long("allow-dirty")
118+
.help("Fix code even if the working directory has changes")
119+
.requires("fix"),
120+
Arg::new("allow-staged")
121+
.long("allow-staged")
122+
.help("Fix code even if the working directory has staged changes")
123+
.requires("fix"),
124+
]),
107125
Command::new("fmt")
108126
.about("Run rustfmt on all projects and tests")
109127
.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)