Merge pull request #3444 from waynr/fix-dogfood-tests

Fix dogfood tests
This commit is contained in:
Philipp Hansch 2018-12-06 07:10:04 +01:00 committed by GitHub
commit 7cb1b1f7e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 44 deletions

View file

@ -168,18 +168,6 @@ Manually testing against an example file is useful if you have added some
local modifications, run `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs`
from the working copy root.
### Linting Clippy with your local changes
Clippy CI only passes if all lints defined in the version of the Clippy being
tested pass (that is, dont report any suggestions). You can avoid prolonging
the CI feedback cycle for PRs you submit by running these lints yourself ahead
of time and addressing any issues found:
```
cargo build
`pwd`/target/debug/cargo-clippy clippy --all-targets --all-features -- -D clippy::all -D clippy::internal -D clippy::pedantic
```
### How Clippy works
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.

View file

@ -27,23 +27,3 @@ cd clippy_dev && cargo test && cd ..
# Perform various checks for lint registration
./util/dev update_lints --check
cargo +nightly fmt --all -- --check
# Add bin to PATH for windows
PATH=$PATH:$(rustc --print sysroot)/bin
CLIPPY="`pwd`/target/debug/cargo-clippy clippy"
# run clippy on its own codebase...
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal -Dclippy::pedantic
# ... and some test directories
for dir in clippy_workspace_tests clippy_workspace_tests/src clippy_workspace_tests/subcrate clippy_workspace_tests/subcrate/src clippy_dev rustc_tools_util
do
cd ${dir}
${CLIPPY} -- -D clippy::all -D clippy::pedantic
cd -
done
# test --manifest-path
${CLIPPY} --manifest-path=clippy_workspace_tests/Cargo.toml -- -D clippy::all
cd clippy_workspace_tests/subcrate && ${CLIPPY} --manifest-path=../Cargo.toml -- -D clippy::all && cd ../..
set +x

View file

@ -12,18 +12,57 @@ fn dogfood() {
if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
return;
}
let root_dir = std::env::current_dir().unwrap();
for d in &[".", "clippy_lints", "rustc_tools_util", "clippy_dev"] {
std::env::set_current_dir(root_dir.join(d)).unwrap();
let output = std::process::Command::new("cargo")
.arg("run")
.arg("--bin")
.arg("cargo-clippy")
.arg("--all-features")
.arg("--manifest-path")
.arg(root_dir.join("Cargo.toml"))
.args(&["--", "-W clippy::internal -W clippy::pedantic"])
.env("CLIPPY_DOGFOOD", "true")
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let clippy_cmd = std::path::Path::new(&root_dir)
.join("target")
.join(env!("PROFILE"))
.join("cargo-clippy");
let output = std::process::Command::new(clippy_cmd)
.current_dir(root_dir)
.env("CLIPPY_DOGFOOD", "1")
.arg("clippy")
.arg("--all-targets")
.arg("--all-features")
.arg("--")
.args(&["-D", "clippy::all"])
.args(&["-D", "clippy::internal"])
.args(&["-D", "clippy::pedantic"])
.output()
.unwrap();
println!("status: {}", output.status);
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
assert!(output.status.success());
}
#[test]
fn dogfood_tests() {
if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) {
return;
}
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let clippy_cmd = std::path::Path::new(&root_dir)
.join("target")
.join(env!("PROFILE"))
.join("cargo-clippy");
for d in &[
"clippy_workspace_tests",
"clippy_workspace_tests/src",
"clippy_workspace_tests/subcrate",
"clippy_workspace_tests/subcrate/src",
"clippy_dev",
"rustc_tools_util",
] {
let output = std::process::Command::new(&clippy_cmd)
.current_dir(root_dir.join(d))
.env("CLIPPY_DOGFOOD", "1")
.arg("clippy")
.arg("--")
.args(&["-D", "clippy::all"])
.args(&["-D", "clippy::pedantic"])
.output()
.unwrap();
println!("status: {}", output.status);