From 3e1139a7dc08ce57b83f650d042719b025a30d23 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 23 Nov 2019 16:21:16 +0100 Subject: [PATCH 1/5] Rust implementation of integration test --- Cargo.toml | 3 ++ tests/integration.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/integration.rs diff --git a/Cargo.toml b/Cargo.toml index b572aebdbbe3..dabc4a62e6d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,8 @@ clippy_lints = { version = "0.0.212", path = "clippy_lints" } regex = "1" semver = "0.9" rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"} +git2 = { version = "0.10", optional = true } +tempfile = { version = "3.1.0", optional = true } [dev-dependencies] cargo_metadata = "0.9.0" @@ -58,3 +60,4 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"} [features] deny-warnings = [] +integration = ["git2", "tempfile"] diff --git a/tests/integration.rs b/tests/integration.rs new file mode 100644 index 000000000000..4d084ae34e33 --- /dev/null +++ b/tests/integration.rs @@ -0,0 +1,75 @@ +#![cfg(feature = "integration")] + +use git2::Repository; +use tempfile; + +use std::env; +use std::process::Command; + +#[cfg_attr(feature = "integration", test)] +fn integration_test() { + let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set"); + let repo_url = format!("https://github.com/{}", repo_name); + let crate_name = repo_name + .split('/') + .nth(1) + .expect("repo name should have format `/`"); + + let repo_dir = tempfile::tempdir() + .expect("couldn't create temp dir") + .path() + .join(crate_name); + + Repository::clone(&repo_url, &repo_dir).expect("clone of repo failed"); + + let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let target_dir = std::path::Path::new(&root_dir).join("target"); + let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy"); + + let output = Command::new(clippy_binary) + .current_dir(repo_dir) + .env("RUST_BACKTRACE", "full") + .env("CARGO_TARGET_DIR", target_dir) + .args(&[ + "clippy", + "--all-targets", + "--all-features", + "--", + "--cap-lints", + "warn", + "-Wclippy::pedantic", + "-Wclippy::nursery", + ]) + .output() + .expect("unable to run clippy"); + + let stderr = String::from_utf8_lossy(&output.stderr); + if stderr.contains("internal compiler error") { + let backtrace_start = stderr + .find("thread 'rustc' panicked at") + .expect("start of backtrace not found"); + let backtrace_end = stderr + .rfind("error: internal compiler error") + .expect("end of backtrace not found"); + + panic!( + "internal compiler error\nBacktrace:\n\n{}", + &stderr[backtrace_start..backtrace_end] + ); + } else if stderr.contains("query stack during panic") { + panic!("query stack during panic in the output"); + } else if stderr.contains("E0463") { + panic!("error: E0463"); + } + + match output.status.code() { + Some(code) => { + if code == 0 { + eprintln!("Compilation successful"); + } else { + eprintln!("Compilation failed. Exit code: {}", code); + } + }, + None => panic!("Process terminated by signal"), + } +} From 21e81f1712b2b894075aed194ea0496be59e9eb1 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 23 Nov 2019 16:21:53 +0100 Subject: [PATCH 2/5] Use rust implementation for integration tests in CI --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 187079602114..d21d7417f46f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,9 +66,8 @@ matrix: # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=Geal/nom if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727 - #- env: INTEGRATION=rust-lang/rustfmt - # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) + - env: INTEGRATION=rust-lang/rustfmt + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=hyperium/hyper if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=bluss/rust-itertools @@ -127,7 +126,7 @@ before_script: script: - | if [[ -n ${INTEGRATION} ]]; then - ./ci/integration-tests.sh && sleep 5 + cargo test --test integration --features integration && sleep 5 else ./ci/base-tests.sh && sleep 5 fi From 6271631ae94f0245a3f276c0dc642c672da04327 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 23 Nov 2019 16:22:20 +0100 Subject: [PATCH 3/5] Remove the old integration-tests.sh script --- ci/integration-tests.sh | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100755 ci/integration-tests.sh diff --git a/ci/integration-tests.sh b/ci/integration-tests.sh deleted file mode 100755 index f6540769bb03..000000000000 --- a/ci/integration-tests.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -set -ex - -if [[ -z "$INTEGRATION" ]]; then - exit 0 -fi - -CARGO_TARGET_DIR=$(pwd)/target/ -export CARGO_TARGET_DIR - -rm ~/.cargo/bin/cargo-clippy -cargo install --force --debug --path . - -echo "Running integration test for crate ${INTEGRATION}" - -git clone --depth=1 "https://github.com/${INTEGRATION}.git" checkout -cd checkout - -# run clippy on a project, try to be verbose and trigger as many warnings -# as possible for greater coverage -# NOTE: we use `tee` to print any warnings and errors to stdout -# to avoid build timeout in Travis -RUST_BACKTRACE=full \ -cargo clippy \ - --all-targets \ - --all-features \ - -- \ - --cap-lints warn \ - -W clippy::pedantic \ - -W clippy::nursery \ - 2>&1 | tee clippy_output - -cargo uninstall clippy - -if grep -q "internal compiler error\|query stack during panic\|E0463" clippy_output; then - exit 1 -fi From a6289ccd4c2d291ae5c463d8cd409faa330d4d05 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sat, 23 Nov 2019 16:51:37 +0100 Subject: [PATCH 4/5] Revert "Disable chalk integration test. Output too large" This reverts commit 553db874d7183d33040807142b1f4f79441c1d4c. --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d21d7417f46f..a2a67e66e614 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,9 +61,8 @@ matrix: if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang/cargo if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - # FIXME: Output too large - # - env: INTEGRATION=rust-lang-nursery/chalk - # if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) + - env: INTEGRATION=rust-lang/chalk + if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=Geal/nom if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try) - env: INTEGRATION=rust-lang/rustfmt From 82066d2f0e7fefd00e32d2cea87debcc94e66bc4 Mon Sep 17 00:00:00 2001 From: Philipp Krones Date: Thu, 28 Nov 2019 17:48:29 +0100 Subject: [PATCH 5/5] Use `println!` on success instead of `eprintln!` Co-Authored-By: Phil Hansch --- tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.rs b/tests/integration.rs index 4d084ae34e33..455965436d63 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -65,7 +65,7 @@ fn integration_test() { match output.status.code() { Some(code) => { if code == 0 { - eprintln!("Compilation successful"); + println!("Compilation successful"); } else { eprintln!("Compilation failed. Exit code: {}", code); }