]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/integration.rs
1 #![cfg(feature = "integration")]
5 use std
::process
::Command
;
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
14 .expect("repo name should have format `<org>/<name>`");
16 let mut repo_dir
= tempfile
::tempdir().expect("couldn't create temp dir").into_path();
17 repo_dir
.push(crate_name
);
19 let st
= Command
::new("git")
22 OsStr
::new("--depth=1"),
23 OsStr
::new(&repo_url
),
24 OsStr
::new(&repo_dir
),
27 .expect("unable to run git");
28 assert
!(st
.success());
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");
34 let output
= Command
::new(clippy_binary
)
35 .current_dir(repo_dir
)
36 .env("RUST_BACKTRACE", "full")
37 .env("CARGO_TARGET_DIR", target_dir
)
49 .expect("unable to run clippy");
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");
61 "internal compiler error\nBacktrace:\n\n{}",
62 &stderr
[backtrace_start
..backtrace_end
]
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 } else if stderr
.contains("toolchain") && stderr
.contains("is not installed") {
76 panic
!("missing required toolchain");
79 match output
.status
.code() {
80 Some(0) => println
!("Compilation successful"),
81 Some(code
) => eprintln
!("Compilation failed. Exit code: {}", code
),
82 None
=> panic
!("Process terminated by signal"),