2021-01-02 09:29:43 -06:00
|
|
|
#![allow(clippy::single_match_else)]
|
|
|
|
use rustc_tools_util::VersionInfo;
|
|
|
|
|
2016-05-30 05:47:04 -05:00
|
|
|
#[test]
|
2021-02-25 04:25:22 -06:00
|
|
|
fn check_that_clippy_lints_and_clippy_utils_have_the_same_version_as_clippy() {
|
2021-02-25 04:25:45 -06:00
|
|
|
// do not run this test inside the upstream rustc repo:
|
|
|
|
// https://github.com/rust-lang/rust-clippy/issues/6683
|
|
|
|
if option_env!("RUSTC_TEST_SUITE").is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:39:45 -06:00
|
|
|
let clippy_meta = cargo_metadata::MetadataCommand::new()
|
2019-01-25 14:28:09 -06:00
|
|
|
.no_deps()
|
2019-01-25 13:39:45 -06:00
|
|
|
.exec()
|
|
|
|
.expect("could not obtain cargo metadata");
|
2021-02-25 04:25:22 -06:00
|
|
|
|
|
|
|
for krate in &["clippy_lints", "clippy_utils"] {
|
2021-03-12 08:30:50 -06:00
|
|
|
let krate_meta = cargo_metadata::MetadataCommand::new()
|
|
|
|
.current_dir(std::env::current_dir().unwrap().join(krate))
|
|
|
|
.no_deps()
|
|
|
|
.exec()
|
2021-02-25 04:25:22 -06:00
|
|
|
.expect("could not obtain cargo metadata");
|
2021-03-12 08:30:50 -06:00
|
|
|
assert_eq!(krate_meta.packages[0].version, clippy_meta.packages[0].version);
|
2021-02-25 04:25:22 -06:00
|
|
|
for package in &clippy_meta.packages[0].dependencies {
|
|
|
|
if package.name == *krate {
|
2021-03-12 08:30:50 -06:00
|
|
|
assert!(package.req.matches(&krate_meta.packages[0].version));
|
2021-02-25 04:25:22 -06:00
|
|
|
break;
|
|
|
|
}
|
2016-05-30 05:47:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 09:29:43 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_that_clippy_has_the_same_major_version_as_rustc() {
|
2021-02-11 08:04:38 -06:00
|
|
|
// do not run this test inside the upstream rustc repo:
|
|
|
|
// https://github.com/rust-lang/rust-clippy/issues/6683
|
|
|
|
if option_env!("RUSTC_TEST_SUITE").is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-02 09:29:43 -06:00
|
|
|
let clippy_version = rustc_tools_util::get_version_info!();
|
|
|
|
let clippy_major = clippy_version.major;
|
|
|
|
let clippy_minor = clippy_version.minor;
|
|
|
|
let clippy_patch = clippy_version.patch;
|
|
|
|
|
2021-01-02 11:01:42 -06:00
|
|
|
// get the rustc version either from the rustc installed with the toolchain file or from
|
|
|
|
// `RUSTC_REAL` if Clippy is build in the Rust repo with `./x.py`.
|
|
|
|
let rustc = std::env::var("RUSTC_REAL").unwrap_or_else(|_| "rustc".to_string());
|
2021-01-02 09:29:43 -06:00
|
|
|
let rustc_version = String::from_utf8(
|
2021-01-02 11:01:42 -06:00
|
|
|
std::process::Command::new(&rustc)
|
2021-01-02 09:29:43 -06:00
|
|
|
.arg("--version")
|
|
|
|
.output()
|
|
|
|
.expect("failed to run `rustc --version`")
|
|
|
|
.stdout,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
// extract "1 XX 0" from "rustc 1.XX.0-nightly (<commit> <date>)"
|
|
|
|
let vsplit: Vec<&str> = rustc_version
|
|
|
|
.split(' ')
|
|
|
|
.nth(1)
|
|
|
|
.unwrap()
|
|
|
|
.split('-')
|
|
|
|
.next()
|
|
|
|
.unwrap()
|
|
|
|
.split('.')
|
|
|
|
.collect();
|
|
|
|
match vsplit.as_slice() {
|
|
|
|
[rustc_major, rustc_minor, _rustc_patch] => {
|
|
|
|
// clippy 0.1.XX should correspond to rustc 1.XX.0
|
|
|
|
assert_eq!(clippy_major, 0); // this will probably stay the same for a long time
|
|
|
|
assert_eq!(
|
|
|
|
clippy_minor.to_string(),
|
|
|
|
*rustc_major,
|
|
|
|
"clippy minor version does not equal rustc major version"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
clippy_patch.to_string(),
|
|
|
|
*rustc_minor,
|
|
|
|
"clippy patch version does not equal rustc minor version"
|
|
|
|
);
|
|
|
|
// do not check rustc_patch because when a stable-patch-release is made (like 1.50.2),
|
|
|
|
// we don't want our tests failing suddenly
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
panic!("Failed to parse rustc version: {:?}", vsplit);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|