From 72247d8e2e6e14fd428d2334b67298dc889340e4 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Wed, 21 Nov 2018 09:14:42 -0600 Subject: [PATCH 1/5] Fix dogfood tests. --- ci/base-tests.sh | 20 ------------------ tests/dogfood.rs | 55 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/ci/base-tests.sh b/ci/base-tests.sh index a046d21c4be4..2537f157ad98 100755 --- a/ci/base-tests.sh +++ b/ci/base-tests.sh @@ -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 diff --git a/tests/dogfood.rs b/tests/dogfood.rs index e8f7a080c95f..2f2b0cf50acf 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -12,18 +12,50 @@ 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"] { + let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let clippy_cmd = std::path::Path::new(&root_dir).join("target/debug/cargo-clippy"); + + println!("{:?}", clippy_cmd); + let output = std::process::Command::new(clippy_cmd) + .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")); + + 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 clippy_cmd = std::path::Path::new(&root_dir) + .join("target/debug/cargo-clippy"); 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 output = std::process::Command::new(clippy_cmd) + .arg("clippy") + .arg("--") + .args(&["-D", "clippy::all"]) + .args(&["-D", "clippy::pedantic"]) .output() .unwrap(); println!("status: {}", output.status); @@ -32,4 +64,5 @@ fn dogfood() { assert!(output.status.success()); } + std::env::set_current_dir(root_dir).unwrap(); } From 1db535a88766136c1e2dae7255c3904003761063 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Wed, 21 Nov 2018 09:15:32 -0600 Subject: [PATCH 2/5] Remove unnecessary documentation --- CONTRIBUTING.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7ee74448a092..bff456203db2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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, don’t 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. From 66251c3ecec42af22410a7290f3a82a60e97bf29 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Sat, 24 Nov 2018 15:22:23 -0600 Subject: [PATCH 3/5] Use dogfood_runner for deterministic test ordering --- tests/dogfood.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 2f2b0cf50acf..5ef2d8fc26a4 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -8,6 +8,11 @@ // except according to those terms. #[test] +fn dogfood_runner() { + dogfood(); + dogfood_tests(); +} + fn dogfood() { if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) { return; @@ -15,7 +20,7 @@ fn dogfood() { let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); let clippy_cmd = std::path::Path::new(&root_dir).join("target/debug/cargo-clippy"); - println!("{:?}", clippy_cmd); + std::env::set_current_dir(root_dir).unwrap(); let output = std::process::Command::new(clippy_cmd) .arg("clippy") .arg("--all-targets") @@ -33,7 +38,6 @@ fn dogfood() { assert!(output.status.success()); } -#[test] fn dogfood_tests() { if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) { return; @@ -64,5 +68,4 @@ fn dogfood_tests() { assert!(output.status.success()); } - std::env::set_current_dir(root_dir).unwrap(); } From 87d517df5db7597ab03a7cf0b8083f55a3cee8b7 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Sat, 24 Nov 2018 15:24:13 -0600 Subject: [PATCH 4/5] Use cargo's "PROFILE" envvar and set CLIPPY_DOGFOOD --- tests/dogfood.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 5ef2d8fc26a4..286af42fd914 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -18,10 +18,14 @@ fn dogfood() { return; } let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let clippy_cmd = std::path::Path::new(&root_dir).join("target/debug/cargo-clippy"); + let clippy_cmd = std::path::Path::new(&root_dir) + .join("target") + .join(env!("PROFILE")) + .join("cargo-clippy"); std::env::set_current_dir(root_dir).unwrap(); let output = std::process::Command::new(clippy_cmd) + .env("CLIPPY_DOGFOOD", "1") .arg("clippy") .arg("--all-targets") .arg("--all-features") @@ -43,6 +47,10 @@ fn dogfood_tests() { 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", @@ -52,10 +60,9 @@ fn dogfood_tests() { "clippy_dev", "rustc_tools_util", ] { - let clippy_cmd = std::path::Path::new(&root_dir) - .join("target/debug/cargo-clippy"); std::env::set_current_dir(root_dir.join(d)).unwrap(); - let output = std::process::Command::new(clippy_cmd) + let output = std::process::Command::new(&clippy_cmd) + .env("CLIPPY_DOGFOOD", "1") .arg("clippy") .arg("--") .args(&["-D", "clippy::all"]) From 0442bb9ce0b1f9851442fcc6f8f9dcb3ef88e3ca Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Fri, 30 Nov 2018 12:54:47 -0600 Subject: [PATCH 5/5] Don't change current working directory of cargo tests --- tests/dogfood.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/dogfood.rs b/tests/dogfood.rs index 286af42fd914..c1f02b9fcefe 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -8,11 +8,6 @@ // except according to those terms. #[test] -fn dogfood_runner() { - dogfood(); - dogfood_tests(); -} - fn dogfood() { if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) { return; @@ -23,8 +18,8 @@ fn dogfood() { .join(env!("PROFILE")) .join("cargo-clippy"); - std::env::set_current_dir(root_dir).unwrap(); let output = std::process::Command::new(clippy_cmd) + .current_dir(root_dir) .env("CLIPPY_DOGFOOD", "1") .arg("clippy") .arg("--all-targets") @@ -42,6 +37,7 @@ fn dogfood() { assert!(output.status.success()); } +#[test] fn dogfood_tests() { if option_env!("RUSTC_TEST_SUITE").is_some() || cfg!(windows) { return; @@ -60,8 +56,8 @@ fn dogfood_tests() { "clippy_dev", "rustc_tools_util", ] { - std::env::set_current_dir(root_dir.join(d)).unwrap(); let output = std::process::Command::new(&clippy_cmd) + .current_dir(root_dir.join(d)) .env("CLIPPY_DOGFOOD", "1") .arg("clippy") .arg("--")