Skip to content

Commit 97a6da4

Browse files
committed
Auto merge of #4837 - flip1995:integration, r=<try>
[WIP] RIIR: Integration tests In #4825 the `rust-lang/chalk` test failed because the output was too large. I didn't want to completely disabling the output, since showing the backtrace of an ICE directly in travis is pretty useful. Since finding strings in command outputs is easier in Rust, than in bash, I just RIIRed it. This and also rewriting our tests in Rust may help with trying out new CI platforms (cc #4577) changelog: none
2 parents cc35165 + ab67235 commit 97a6da4

File tree

4 files changed

+83
-44
lines changed

4 files changed

+83
-44
lines changed

.travis.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ matrix:
6161
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6262
- env: INTEGRATION=rust-lang/cargo
6363
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
64-
# FIXME: Output too large
65-
# - env: INTEGRATION=rust-lang-nursery/chalk
66-
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
64+
- env: INTEGRATION=rust-lang/chalk
65+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
6766
- env: INTEGRATION=Geal/nom
6867
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
69-
# FIXME blocked on https://github.com/rust-lang/rust-clippy/issues/4727
70-
#- env: INTEGRATION=rust-lang/rustfmt
71-
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
68+
- env: INTEGRATION=rust-lang/rustfmt
69+
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7270
- env: INTEGRATION=hyperium/hyper
7371
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
7472
- env: INTEGRATION=bluss/rust-itertools
@@ -127,7 +125,7 @@ before_script:
127125
script:
128126
- |
129127
if [[ -n ${INTEGRATION} ]]; then
130-
./ci/integration-tests.sh && sleep 5
128+
cargo test --test integration --features integration && sleep 5
131129
else
132130
./ci/base-tests.sh && sleep 5
133131
fi

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ clippy_lints = { version = "0.0.212", path = "clippy_lints" }
3838
regex = "1"
3939
semver = "0.9"
4040
rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
41+
git2 = { version = "0.10", optional = true }
42+
tempfile = { version = "3.1.0", optional = true }
4143

4244
[dev-dependencies]
4345
cargo_metadata = "0.9.0"
@@ -59,3 +61,4 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
5961
[features]
6062
deny-warnings = []
6163
debugging = []
64+
integration = ["git2", "tempfile"]

ci/integration-tests.sh

-37
This file was deleted.

tests/integration.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#![cfg(feature = "integration")]
2+
3+
use git2::Repository;
4+
use tempfile;
5+
6+
use std::env;
7+
use std::process::Command;
8+
9+
#[cfg_attr(feature = "integration", test)]
10+
fn integration_test() {
11+
let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
12+
let repo_url = format!("https://github.com/{}", repo_name);
13+
let crate_name = repo_name
14+
.split('/')
15+
.nth(1)
16+
.expect("repo name should have format `<org>/<name>`");
17+
18+
let repo_dir = tempfile::tempdir()
19+
.expect("couldn't create temp dir")
20+
.path()
21+
.join(crate_name);
22+
23+
Repository::clone(&repo_url, &repo_dir).expect("clone of repo failed");
24+
25+
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
26+
let target_dir = std::path::Path::new(&root_dir).join("target");
27+
let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy");
28+
29+
let output = Command::new(clippy_binary)
30+
.current_dir(repo_dir)
31+
.env("RUST_BACKTRACE", "full")
32+
.env("CARGO_TARGET_DIR", target_dir)
33+
.args(&[
34+
"clippy",
35+
"--all-targets",
36+
"--all-features",
37+
"--",
38+
"--cap-lints",
39+
"warn",
40+
"-Wclippy::pedantic",
41+
"-Wclippy::nursery",
42+
])
43+
.output()
44+
.expect("unable to run clippy");
45+
46+
let stderr = String::from_utf8_lossy(&output.stderr);
47+
if stderr.contains("internal compiler error") {
48+
let backtrace_start = stderr
49+
.find("thread 'rustc' panicked at")
50+
.expect("start of backtrace not found");
51+
let backtrace_end = stderr
52+
.rfind("error: internal compiler error")
53+
.expect("end of backtrace not found");
54+
55+
panic!(
56+
"internal compiler error\nBacktrace:\n\n{}",
57+
&stderr[backtrace_start..backtrace_end]
58+
);
59+
} else if stderr.contains("query stack during panic") {
60+
panic!("query stack during panic in the output");
61+
} else if stderr.contains("E0463") {
62+
panic!("error: E0463");
63+
}
64+
65+
match output.status.code() {
66+
Some(code) => {
67+
if code == 0 {
68+
eprintln!("Compilation successful");
69+
} else {
70+
eprintln!("Compilation failed. Exit code: {}", code);
71+
}
72+
},
73+
None => panic!("Process terminated by signal"),
74+
}
75+
}

0 commit comments

Comments
 (0)