1 #![cfg(feature = "integration")]
2 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 #![warn(rust_2018_idioms, unused_lifetimes)]
7 use std::process::Command;
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
16 .expect("repo name should have format `<org>/<name>`");
18 let mut repo_dir = tempfile::tempdir().expect("couldn't create temp dir").into_path();
19 repo_dir.push(crate_name);
21 let st = Command::new("git")
24 OsStr::new("--depth=1"),
25 OsStr::new(&repo_url),
26 OsStr::new(&repo_dir),
29 .expect("unable to run git");
30 assert!(st.success());
32 let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
33 let target_dir = std::path::Path::new(&root_dir).join("target");
34 let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy");
36 let output = Command::new(clippy_binary)
37 .current_dir(repo_dir)
38 .env("RUST_BACKTRACE", "full")
39 .env("CARGO_TARGET_DIR", target_dir)
51 .expect("unable to run clippy");
53 let stderr = String::from_utf8_lossy(&output.stderr);
54 if stderr.contains("internal compiler error") {
55 let backtrace_start = stderr
56 .find("thread 'rustc' panicked at")
57 .expect("start of backtrace not found");
58 let backtrace_end = stderr
59 .rfind("error: internal compiler error")
60 .expect("end of backtrace not found");
63 "internal compiler error\nBacktrace:\n\n{}",
64 &stderr[backtrace_start..backtrace_end]
66 } else if stderr.contains("query stack during panic") {
67 panic!("query stack during panic in the output");
68 } else if stderr.contains("E0463") {
69 // Encountering E0463 (can't find crate for `x`) did _not_ cause the build to fail in the
70 // past. Even though it should have. That's why we explicitly panic here.
71 // See PR #3552 and issue #3523 for more background.
72 panic!("error: E0463");
73 } else if stderr.contains("E0514") {
74 panic!("incompatible crate versions");
75 } else if stderr.contains("failed to run `rustc` to learn about target-specific information") {
76 panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
79 !stderr.contains("toolchain") || !stderr.contains("is not installed"),
80 "missing required toolchain"
84 match output.status.code() {
85 Some(0) => println!("Compilation successful"),
86 Some(code) => eprintln!("Compilation failed. Exit code: {}", code),
87 None => panic!("Process terminated by signal"),