1 #![cfg(feature = "integration")]
4 use std::process::Command;
6 #[cfg_attr(feature = "integration", test)]
7 fn integration_test() {
8 let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
9 let repo_url = format!("https://github.com/{}", repo_name);
10 let crate_name = repo_name
13 .expect("repo name should have format `<org>/<name>`");
15 let mut repo_dir = tempfile::tempdir().expect("couldn't create temp dir").into_path();
16 repo_dir.push(crate_name);
18 let st = Command::new("git")
19 .args(&["clone", "--depth=1", &repo_url, repo_dir.to_str().unwrap()])
21 .expect("unable to run git");
22 assert!(st.success());
24 let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
25 let target_dir = std::path::Path::new(&root_dir).join("target");
26 let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy");
28 let output = Command::new(clippy_binary)
29 .current_dir(repo_dir)
30 .env("RUST_BACKTRACE", "full")
31 .env("CARGO_TARGET_DIR", target_dir)
43 .expect("unable to run clippy");
45 let stderr = String::from_utf8_lossy(&output.stderr);
46 if stderr.contains("internal compiler error") {
47 let backtrace_start = stderr
48 .find("thread 'rustc' panicked at")
49 .expect("start of backtrace not found");
50 let backtrace_end = stderr
51 .rfind("error: internal compiler error")
52 .expect("end of backtrace not found");
55 "internal compiler error\nBacktrace:\n\n{}",
56 &stderr[backtrace_start..backtrace_end]
58 } else if stderr.contains("query stack during panic") {
59 panic!("query stack during panic in the output");
60 } else if stderr.contains("E0463") {
61 panic!("error: E0463");
62 } else if stderr.contains("E0514") {
63 panic!("incompatible crate versions");
64 } else if stderr.contains("failed to run `rustc` to learn about target-specific information") {
65 panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
68 match output.status.code() {
69 Some(0) => println!("Compilation successful"),
70 Some(code) => eprintln!("Compilation failed. Exit code: {}", code),
71 None => panic!("Process terminated by signal"),