2023-01-12 11:30:51 -06:00
|
|
|
//! This test is meant to only be run in CI. To run it locally use:
|
|
|
|
//!
|
2023-01-03 12:04:28 -06:00
|
|
|
//! `env INTEGRATION=rust-lang/log cargo test --test integration --features=integration`
|
|
|
|
//!
|
|
|
|
//! You can use a different `INTEGRATION` value to test different repositories.
|
2023-01-12 11:30:51 -06:00
|
|
|
//!
|
|
|
|
//! This test will clone the specified repository and run Clippy on it. The test succeeds, if
|
|
|
|
//! Clippy doesn't produce an ICE. Lint warnings are ignored by this test.
|
2023-01-03 12:04:28 -06:00
|
|
|
|
2019-11-23 09:21:16 -06:00
|
|
|
#![cfg(feature = "integration")]
|
2021-09-08 08:19:14 -05:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2019-11-23 09:21:16 -06:00
|
|
|
|
2023-01-12 11:30:51 -06:00
|
|
|
use std::env;
|
2020-03-14 09:30:08 -05:00
|
|
|
use std::ffi::OsStr;
|
2019-11-23 09:21:16 -06:00
|
|
|
use std::process::Command;
|
|
|
|
|
2022-09-24 23:39:05 -05:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
const CARGO_CLIPPY: &str = "cargo-clippy";
|
|
|
|
#[cfg(windows)]
|
|
|
|
const CARGO_CLIPPY: &str = "cargo-clippy.exe";
|
|
|
|
|
2023-01-12 11:30:51 -06:00
|
|
|
#[cfg_attr(feature = "integration", test)]
|
2023-02-16 10:58:51 -06:00
|
|
|
#[allow(clippy::missing_assert_message)]
|
2023-01-12 11:30:51 -06:00
|
|
|
fn integration_test() {
|
|
|
|
let repo_name = env::var("INTEGRATION").expect("`INTEGRATION` var not set");
|
2022-09-23 13:25:03 -05:00
|
|
|
let repo_url = format!("https://github.com/{repo_name}");
|
2019-11-23 09:21:16 -06:00
|
|
|
let crate_name = repo_name
|
|
|
|
.split('/')
|
|
|
|
.nth(1)
|
|
|
|
.expect("repo name should have format `<org>/<name>`");
|
|
|
|
|
2020-03-14 10:17:52 -05:00
|
|
|
let mut repo_dir = tempfile::tempdir().expect("couldn't create temp dir").into_path();
|
|
|
|
repo_dir.push(crate_name);
|
2019-11-23 09:21:16 -06:00
|
|
|
|
2020-03-13 20:22:51 -05:00
|
|
|
let st = Command::new("git")
|
2022-07-08 04:30:17 -05:00
|
|
|
.args([
|
2020-03-14 09:30:08 -05:00
|
|
|
OsStr::new("clone"),
|
|
|
|
OsStr::new("--depth=1"),
|
|
|
|
OsStr::new(&repo_url),
|
|
|
|
OsStr::new(&repo_dir),
|
|
|
|
])
|
2020-03-13 20:22:51 -05:00
|
|
|
.status()
|
2020-03-14 04:22:49 -05:00
|
|
|
.expect("unable to run git");
|
2020-03-13 20:22:51 -05:00
|
|
|
assert!(st.success());
|
2019-11-23 09:21:16 -06:00
|
|
|
|
2023-01-12 11:30:51 -06:00
|
|
|
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
let target_dir = std::path::Path::new(&root_dir).join("target");
|
|
|
|
let clippy_binary = target_dir.join(env!("PROFILE")).join(CARGO_CLIPPY);
|
2019-11-23 09:21:16 -06:00
|
|
|
|
2023-01-12 11:30:51 -06:00
|
|
|
let output = Command::new(clippy_binary)
|
|
|
|
.current_dir(repo_dir)
|
|
|
|
.env("RUST_BACKTRACE", "full")
|
|
|
|
.env("CARGO_TARGET_DIR", target_dir)
|
|
|
|
.args([
|
|
|
|
"clippy",
|
|
|
|
"--all-targets",
|
|
|
|
"--all-features",
|
|
|
|
"--",
|
|
|
|
"--cap-lints",
|
|
|
|
"warn",
|
|
|
|
"-Wclippy::pedantic",
|
|
|
|
"-Wclippy::nursery",
|
|
|
|
])
|
|
|
|
.output()
|
|
|
|
.expect("unable to run clippy");
|
2023-01-03 12:04:28 -06:00
|
|
|
|
2023-01-12 11:30:51 -06:00
|
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
2022-09-24 23:39:05 -05:00
|
|
|
if let Some(backtrace_start) = stderr.find("error: internal compiler error") {
|
|
|
|
static BACKTRACE_END_MSG: &str = "end of query stack";
|
|
|
|
let backtrace_end = stderr[backtrace_start..]
|
|
|
|
.find(BACKTRACE_END_MSG)
|
2019-11-23 09:21:16 -06:00
|
|
|
.expect("end of backtrace not found");
|
|
|
|
|
|
|
|
panic!(
|
|
|
|
"internal compiler error\nBacktrace:\n\n{}",
|
2022-09-24 23:39:05 -05:00
|
|
|
&stderr[backtrace_start..backtrace_start + backtrace_end + BACKTRACE_END_MSG.len()]
|
2019-11-23 09:21:16 -06:00
|
|
|
);
|
|
|
|
} else if stderr.contains("query stack during panic") {
|
|
|
|
panic!("query stack during panic in the output");
|
|
|
|
} else if stderr.contains("E0463") {
|
2020-04-13 15:12:57 -05:00
|
|
|
// Encountering E0463 (can't find crate for `x`) did _not_ cause the build to fail in the
|
|
|
|
// past. Even though it should have. That's why we explicitly panic here.
|
|
|
|
// See PR #3552 and issue #3523 for more background.
|
2019-11-23 09:21:16 -06:00
|
|
|
panic!("error: E0463");
|
2020-01-31 07:43:02 -06:00
|
|
|
} else if stderr.contains("E0514") {
|
|
|
|
panic!("incompatible crate versions");
|
|
|
|
} else if stderr.contains("failed to run `rustc` to learn about target-specific information") {
|
|
|
|
panic!("couldn't find librustc_driver, consider setting `LD_LIBRARY_PATH`");
|
2021-09-14 03:28:09 -05:00
|
|
|
} else {
|
|
|
|
assert!(
|
|
|
|
!stderr.contains("toolchain") || !stderr.contains("is not installed"),
|
|
|
|
"missing required toolchain"
|
|
|
|
);
|
2019-11-23 09:21:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
match output.status.code() {
|
2020-03-14 07:29:48 -05:00
|
|
|
Some(0) => println!("Compilation successful"),
|
2022-09-23 13:25:03 -05:00
|
|
|
Some(code) => eprintln!("Compilation failed. Exit code: {code}"),
|
2019-11-23 09:21:16 -06:00
|
|
|
None => panic!("Process terminated by signal"),
|
|
|
|
}
|
|
|
|
}
|