]> git.lizzy.rs Git - rust.git/blob - tests/integration.rs
Auto merge of #5453 - rabisg0:fix/redundant_clone, r=phansch
[rust.git] / tests / integration.rs
1 #![cfg(feature = "integration")]
2
3 use std::env;
4 use std::ffi::OsStr;
5 use std::process::Command;
6
7 #[cfg_attr(feature = "integration", test)]
8 fn integration_test() {
9     let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
10     let repo_url = format!("https://github.com/{}", repo_name);
11     let crate_name = repo_name
12         .split('/')
13         .nth(1)
14         .expect("repo name should have format `<org>/<name>`");
15
16     let mut repo_dir = tempfile::tempdir().expect("couldn't create temp dir").into_path();
17     repo_dir.push(crate_name);
18
19     let st = Command::new("git")
20         .args(&[
21             OsStr::new("clone"),
22             OsStr::new("--depth=1"),
23             OsStr::new(&repo_url),
24             OsStr::new(&repo_dir),
25         ])
26         .status()
27         .expect("unable to run git");
28     assert!(st.success());
29
30     let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
31     let target_dir = std::path::Path::new(&root_dir).join("target");
32     let clippy_binary = target_dir.join(env!("PROFILE")).join("cargo-clippy");
33
34     let output = Command::new(clippy_binary)
35         .current_dir(repo_dir)
36         .env("RUST_BACKTRACE", "full")
37         .env("CARGO_TARGET_DIR", target_dir)
38         .args(&[
39             "clippy",
40             "--all-targets",
41             "--all-features",
42             "--",
43             "--cap-lints",
44             "warn",
45             "-Wclippy::pedantic",
46             "-Wclippy::nursery",
47         ])
48         .output()
49         .expect("unable to run clippy");
50
51     let stderr = String::from_utf8_lossy(&output.stderr);
52     if stderr.contains("internal compiler error") {
53         let backtrace_start = stderr
54             .find("thread 'rustc' panicked at")
55             .expect("start of backtrace not found");
56         let backtrace_end = stderr
57             .rfind("error: internal compiler error")
58             .expect("end of backtrace not found");
59
60         panic!(
61             "internal compiler error\nBacktrace:\n\n{}",
62             &stderr[backtrace_start..backtrace_end]
63         );
64     } else if stderr.contains("query stack during panic") {
65         panic!("query stack during panic in the output");
66     } else if stderr.contains("E0463") {
67         // Encountering E0463 (can't find crate for `x`) did _not_ cause the build to fail in the
68         // past. Even though it should have. That's why we explicitly panic here.
69         // See PR #3552 and issue #3523 for more background.
70         panic!("error: E0463");
71     } else if stderr.contains("E0514") {
72         panic!("incompatible crate versions");
73     } else if stderr.contains("failed to run `rustc` to learn about target-specific information") {
74         panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
75     }
76
77     match output.status.code() {
78         Some(0) => println!("Compilation successful"),
79         Some(code) => eprintln!("Compilation failed. Exit code: {}", code),
80         None => panic!("Process terminated by signal"),
81     }
82 }