2021-09-08 14:31:47 +00:00
|
|
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2021-01-02 15:29:43 +00:00
|
|
|
#![allow(clippy::single_match_else)]
|
2021-09-08 14:31:47 +00:00
|
|
|
|
2022-04-07 17:39:59 +00:00
|
|
|
use std::fs;
|
2021-01-02 15:29:43 +00:00
|
|
|
|
2016-05-30 10:47:04 +00:00
|
|
|
#[test]
|
2022-11-21 19:34:47 +00:00
|
|
|
fn consistent_clippy_crate_versions() {
|
2022-04-07 17:39:59 +00:00
|
|
|
fn read_version(path: &str) -> String {
|
2022-10-06 07:44:38 +00:00
|
|
|
let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("error reading `{path}`: {e:?}"));
|
2022-04-07 17:39:59 +00:00
|
|
|
contents
|
|
|
|
.lines()
|
|
|
|
.filter_map(|l| l.split_once('='))
|
|
|
|
.find_map(|(k, v)| (k.trim() == "version").then(|| v.trim()))
|
2022-10-06 07:44:38 +00:00
|
|
|
.unwrap_or_else(|| panic!("error finding version in `{path}`"))
|
2022-04-07 17:39:59 +00:00
|
|
|
.to_string()
|
|
|
|
}
|
|
|
|
|
2021-02-25 10:25:45 +00: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;
|
|
|
|
}
|
|
|
|
|
2022-04-07 17:39:59 +00:00
|
|
|
let clippy_version = read_version("Cargo.toml");
|
2021-02-25 10:25:22 +00:00
|
|
|
|
2022-11-21 19:34:47 +00:00
|
|
|
let paths = [
|
|
|
|
"declare_clippy_lint/Cargo.toml",
|
2023-11-02 16:35:56 +00:00
|
|
|
"clippy_config/Cargo.toml",
|
2022-11-21 19:34:47 +00:00
|
|
|
"clippy_lints/Cargo.toml",
|
|
|
|
"clippy_utils/Cargo.toml",
|
|
|
|
];
|
|
|
|
|
|
|
|
for path in paths {
|
|
|
|
assert_eq!(clippy_version, read_version(path), "{path} version differs");
|
|
|
|
}
|
2016-05-30 10:47:04 +00:00
|
|
|
}
|
2021-01-02 15:29:43 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_that_clippy_has_the_same_major_version_as_rustc() {
|
2021-02-11 14:04:38 +00: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 15:29:43 +00: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 17:01:42 +00: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 15:29:43 +00:00
|
|
|
let rustc_version = String::from_utf8(
|
2022-10-23 13:18:45 +00:00
|
|
|
std::process::Command::new(rustc)
|
2021-01-02 15:29:43 +00: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
|
|
|
|
},
|
|
|
|
_ => {
|
2022-10-06 07:44:38 +00:00
|
|
|
panic!("Failed to parse rustc version: {vsplit:?}");
|
2021-01-02 15:29:43 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|