Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RIIR: Integration tests #4837

Merged
merged 5 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ 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)
# 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
Expand Down Expand Up @@ -127,7 +125,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
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -58,3 +60,4 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}

[features]
deny-warnings = []
integration = ["git2", "tempfile"]
37 changes: 0 additions & 37 deletions ci/integration-tests.sh

This file was deleted.

75 changes: 75 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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 `<org>/<name>`");

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");
flip1995 marked this conversation as resolved.
Show resolved Hide resolved
} else {
eprintln!("Compilation failed. Exit code: {}", code);
}
},
None => panic!("Process terminated by signal"),
}
}