]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/integration.rs
1 //! This test is meant to only be run in CI. To run it locally use:
3 //! `env INTEGRATION=rust-lang/log cargo test --test integration --features=integration`
5 //! You can use a different `INTEGRATION` value to test different repositories.
7 //! This test will clone the specified repository and run Clippy on it. The test succeeds, if
8 //! Clippy doesn't produce an ICE. Lint warnings are ignored by this test.
10 #![cfg(feature = "integration")]
11 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
12 #![warn(rust_2018_idioms, unused_lifetimes)]
16 use std
::process
::Command
;
19 const CARGO_CLIPPY
: &str = "cargo-clippy";
21 const CARGO_CLIPPY
: &str = "cargo-clippy.exe";
23 #[cfg_attr(feature = "integration", test)]
24 fn integration_test() {
25 let repo_name
= env
::var("INTEGRATION").expect("`INTEGRATION` var not set");
26 let repo_url
= format
!("https://github.com/{repo_name}");
27 let crate_name
= repo_name
30 .expect("repo name should have format `<org>/<name>`");
32 let mut repo_dir
= tempfile
::tempdir().expect("couldn't create temp dir").into_path();
33 repo_dir
.push(crate_name
);
35 let st
= Command
::new("git")
38 OsStr
::new("--depth=1"),
39 OsStr
::new(&repo_url
),
40 OsStr
::new(&repo_dir
),
43 .expect("unable to run git");
44 assert
!(st
.success());
46 let root_dir
= std
::path
::PathBuf
::from(env
!("CARGO_MANIFEST_DIR"));
47 let target_dir
= std
::path
::Path
::new(&root_dir
).join("target");
48 let clippy_binary
= target_dir
.join(env
!("PROFILE")).join(CARGO_CLIPPY
);
50 let output
= Command
::new(clippy_binary
)
51 .current_dir(repo_dir
)
52 .env("RUST_BACKTRACE", "full")
53 .env("CARGO_TARGET_DIR", target_dir
)
65 .expect("unable to run clippy");
67 let stderr
= String
::from_utf8_lossy(&output
.stderr
);
70 eprintln
!("{stderr}");
72 // this is an internal test to make sure we would correctly panic on a span_delayed_bug
73 if repo_name
== "matthiaskrgr/clippy_ci_panic_test" {
74 // we need to kind of switch around our logic here:
75 // if we find a panic, everything is fine, if we don't panic, SOMETHING is broken about our testing
77 // the repo basically just contains a span_delayed_bug that forces rustc/clippy to panic:
79 #![feature(rustc_attrs)]
80 #[rustc_error(delayed_bug_from_inside_query)]
84 if stderr
.find("error: internal compiler error").is_some() {
85 eprintln
!("we saw that we intentionally panicked, yay");
89 panic
!("panic caused by span_delayed_bug was NOT detected! Something is broken!");
92 if let Some(backtrace_start
) = stderr
.find("error: internal compiler error") {
93 static BACKTRACE_END_MSG
: &str = "end of query stack";
94 let backtrace_end
= stderr
[backtrace_start
..]
95 .find(BACKTRACE_END_MSG
)
96 .expect("end of backtrace not found");
99 "internal compiler error\nBacktrace:\n\n{}",
100 &stderr
[backtrace_start
..backtrace_start
+ backtrace_end
+ BACKTRACE_END_MSG
.len()]
102 } else if stderr
.contains("query stack during panic") {
103 panic
!("query stack during panic in the output");
104 } else if stderr
.contains("E0463") {
105 // Encountering E0463 (can't find crate for `x`) did _not_ cause the build to fail in the
106 // past. Even though it should have. That's why we explicitly panic here.
107 // See PR #3552 and issue #3523 for more background.
108 panic
!("error: E0463");
109 } else if stderr
.contains("E0514") {
110 panic
!("incompatible crate versions");
111 } else if stderr
.contains("failed to run `rustc` to learn about target-specific information") {
112 panic
!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
115 !stderr
.contains("toolchain") || !stderr
.contains("is not installed"),
116 "missing required toolchain"
120 match output
.status
.code() {
121 Some(0) => println
!("Compilation successful"),
122 Some(code
) => eprintln
!("Compilation failed. Exit code: {code}"),
123 None
=> panic
!("Process terminated by signal"),