]> git.lizzy.rs Git - rust.git/blob - tests/integration.rs
redundant_pattern: take binding (ref, ref mut) into account in suggestion.
[rust.git] / tests / integration.rs
1 #![cfg(feature = "integration")]
2
3 use git2::Repository;
4
5 use std::env;
6 use std::process::Command;
7
8 #[cfg_attr(feature = "integration", test)]
9 fn integration_test() {
10     let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
11     let repo_url = format!("https://github.com/{}", repo_name);
12     let crate_name = repo_name
13         .split('/')
14         .nth(1)
15         .expect("repo name should have format `<org>/<name>`");
16
17     let repo_dir = tempfile::tempdir()
18         .expect("couldn't create temp dir")
19         .path()
20         .join(crate_name);
21
22     Repository::clone(&repo_url, &repo_dir).expect("clone of repo failed");
23
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");
27
28     let output = Command::new(clippy_binary)
29         .current_dir(repo_dir)
30         .env("RUST_BACKTRACE", "full")
31         .env("CARGO_TARGET_DIR", target_dir)
32         .args(&[
33             "clippy",
34             "--all-targets",
35             "--all-features",
36             "--",
37             "--cap-lints",
38             "warn",
39             "-Wclippy::pedantic",
40             "-Wclippy::nursery",
41         ])
42         .output()
43         .expect("unable to run clippy");
44
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");
53
54         panic!(
55             "internal compiler error\nBacktrace:\n\n{}",
56             &stderr[backtrace_start..backtrace_end]
57         );
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`");
66     }
67
68     match output.status.code() {
69         Some(code) => {
70             if code == 0 {
71                 println!("Compilation successful");
72             } else {
73                 eprintln!("Compilation failed. Exit code: {}", code);
74             }
75         },
76         None => panic!("Process terminated by signal"),
77     }
78 }