From 72247d8e2e6e14fd428d2334b67298dc889340e4 Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Wed, 21 Nov 2018 09:14:42 -0600 Subject: [PATCH] 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 a046d21c4be..2537f157ad9 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 e8f7a080c95..2f2b0cf50ac 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(); }