Skip to content

Commit 3e1139a

Browse files
committed
Rust implementation of integration test
1 parent b5a6714 commit 3e1139a

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
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"
@@ -58,3 +60,4 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
5860

5961
[features]
6062
deny-warnings = []
63+
integration = ["git2", "tempfile"]

tests/integration.rs

Lines changed: 75 additions & 0 deletions
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)