1 #![cfg(feature = "integration")]
2 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 #![warn(rust_2018_idioms, unused_lifetimes)]
7 use std::process::Command;
10 const CARGO_CLIPPY: &str = "cargo-clippy";
12 const CARGO_CLIPPY: &str = "cargo-clippy.exe";
14 #[cfg_attr(feature = "integration", test)]
15 fn integration_test() {
16 let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
17 let repo_url = format!("https://github.com/{repo_name}");
18 let crate_name = repo_name
21 .expect("repo name should have format `<org>/<name>`");
23 let mut repo_dir = tempfile::tempdir().expect("couldn't create temp dir").into_path();
24 repo_dir.push(crate_name);
26 let st = Command::new("git")
29 OsStr::new("--depth=1"),
30 OsStr::new(&repo_url),
31 OsStr::new(&repo_dir),
34 .expect("unable to run git");
35 assert!(st.success());
37 let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
38 let target_dir = std::path::Path::new(&root_dir).join("target");
39 let clippy_binary = target_dir.join(env!("PROFILE")).join(CARGO_CLIPPY);
41 let output = Command::new(clippy_binary)
42 .current_dir(repo_dir)
43 .env("RUST_BACKTRACE", "full")
44 .env("CARGO_TARGET_DIR", target_dir)
56 .expect("unable to run clippy");
58 let stderr = String::from_utf8_lossy(&output.stderr);
59 if let Some(backtrace_start) = stderr.find("error: internal compiler error") {
60 static BACKTRACE_END_MSG: &str = "end of query stack";
61 let backtrace_end = stderr[backtrace_start..]
62 .find(BACKTRACE_END_MSG)
63 .expect("end of backtrace not found");
66 "internal compiler error\nBacktrace:\n\n{}",
67 &stderr[backtrace_start..backtrace_start + backtrace_end + BACKTRACE_END_MSG.len()]
69 } else if stderr.contains("query stack during panic") {
70 panic!("query stack during panic in the output");
71 } else if stderr.contains("E0463") {
72 // Encountering E0463 (can't find crate for `x`) did _not_ cause the build to fail in the
73 // past. Even though it should have. That's why we explicitly panic here.
74 // See PR #3552 and issue #3523 for more background.
75 panic!("error: E0463");
76 } else if stderr.contains("E0514") {
77 panic!("incompatible crate versions");
78 } else if stderr.contains("failed to run `rustc` to learn about target-specific information") {
79 panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
82 !stderr.contains("toolchain") || !stderr.contains("is not installed"),
83 "missing required toolchain"
87 match output.status.code() {
88 Some(0) => println!("Compilation successful"),
89 Some(code) => eprintln!("Compilation failed. Exit code: {code}"),
90 None => panic!("Process terminated by signal"),