Skip to content

Commit 7cb1b1f

Browse files
authored
Merge pull request #3444 from waynr/fix-dogfood-tests
Fix dogfood tests
2 parents 29bf75c + 0442bb9 commit 7cb1b1f

File tree

3 files changed

+51
-44
lines changed

3 files changed

+51
-44
lines changed

CONTRIBUTING.md

-12
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,6 @@ Manually testing against an example file is useful if you have added some
168168
local modifications, run `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs`
169169
from the working copy root.
170170

171-
### Linting Clippy with your local changes
172-
173-
Clippy CI only passes if all lints defined in the version of the Clippy being
174-
tested pass (that is, don’t report any suggestions). You can avoid prolonging
175-
the CI feedback cycle for PRs you submit by running these lints yourself ahead
176-
of time and addressing any issues found:
177-
178-
```
179-
cargo build
180-
`pwd`/target/debug/cargo-clippy clippy --all-targets --all-features -- -D clippy::all -D clippy::internal -D clippy::pedantic
181-
```
182-
183171
### How Clippy works
184172

185173
Clippy is a [rustc compiler plugin][compiler_plugin]. The main entry point is at [`src/lib.rs`][main_entry]. In there, the lint registration is delegated to the [`clippy_lints`][lint_crate] crate.

ci/base-tests.sh

-20
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,3 @@ cd clippy_dev && cargo test && cd ..
2727
# Perform various checks for lint registration
2828
./util/dev update_lints --check
2929
cargo +nightly fmt --all -- --check
30-
31-
# Add bin to PATH for windows
32-
PATH=$PATH:$(rustc --print sysroot)/bin
33-
34-
CLIPPY="`pwd`/target/debug/cargo-clippy clippy"
35-
# run clippy on its own codebase...
36-
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal -Dclippy::pedantic
37-
# ... and some test directories
38-
for dir in clippy_workspace_tests clippy_workspace_tests/src clippy_workspace_tests/subcrate clippy_workspace_tests/subcrate/src clippy_dev rustc_tools_util
39-
do
40-
cd ${dir}
41-
${CLIPPY} -- -D clippy::all -D clippy::pedantic
42-
cd -
43-
done
44-
45-
46-
# test --manifest-path
47-
${CLIPPY} --manifest-path=clippy_workspace_tests/Cargo.toml -- -D clippy::all
48-
cd clippy_workspace_tests/subcrate && ${CLIPPY} --manifest-path=../Cargo.toml -- -D clippy::all && cd ../..
49-
set +x

tests/dogfood.rs

+51-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,57 @@ fn dogfood() {
1212
if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
1313
return;
1414
}
15-
let root_dir = std::env::current_dir().unwrap();
16-
for d in &[".", "clippy_lints", "rustc_tools_util", "clippy_dev"] {
17-
std::env::set_current_dir(root_dir.join(d)).unwrap();
18-
let output = std::process::Command::new("cargo")
19-
.arg("run")
20-
.arg("--bin")
21-
.arg("cargo-clippy")
22-
.arg("--all-features")
23-
.arg("--manifest-path")
24-
.arg(root_dir.join("Cargo.toml"))
25-
.args(&["--", "-W clippy::internal -W clippy::pedantic"])
26-
.env("CLIPPY_DOGFOOD", "true")
15+
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
16+
let clippy_cmd = std::path::Path::new(&root_dir)
17+
.join("target")
18+
.join(env!("PROFILE"))
19+
.join("cargo-clippy");
20+
21+
let output = std::process::Command::new(clippy_cmd)
22+
.current_dir(root_dir)
23+
.env("CLIPPY_DOGFOOD", "1")
24+
.arg("clippy")
25+
.arg("--all-targets")
26+
.arg("--all-features")
27+
.arg("--")
28+
.args(&["-D", "clippy::all"])
29+
.args(&["-D", "clippy::internal"])
30+
.args(&["-D", "clippy::pedantic"])
31+
.output()
32+
.unwrap();
33+
println!("status: {}", output.status);
34+
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
35+
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
36+
37+
assert!(output.status.success());
38+
}
39+
40+
#[test]
41+
fn dogfood_tests() {
42+
if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
43+
return;
44+
}
45+
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
46+
let clippy_cmd = std::path::Path::new(&root_dir)
47+
.join("target")
48+
.join(env!("PROFILE"))
49+
.join("cargo-clippy");
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 = std::process::Command::new(&clippy_cmd)
60+
.current_dir(root_dir.join(d))
61+
.env("CLIPPY_DOGFOOD", "1")
62+
.arg("clippy")
63+
.arg("--")
64+
.args(&["-D", "clippy::all"])
65+
.args(&["-D", "clippy::pedantic"])
2766
.output()
2867
.unwrap();
2968
println!("status: {}", output.status);

0 commit comments

Comments
 (0)