|
3 | 3 | #![allow(clippy::single_match_else)]
|
4 | 4 |
|
5 | 5 | use rustc_tools_util::VersionInfo;
|
| 6 | +use std::fs; |
6 | 7 |
|
7 | 8 | #[test]
|
8 | 9 | fn check_that_clippy_lints_and_clippy_utils_have_the_same_version_as_clippy() {
|
| 10 | + fn read_version(path: &str) -> String { |
| 11 | + let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("error reading `{}`: {:?}", path, e)); |
| 12 | + contents |
| 13 | + .lines() |
| 14 | + .filter_map(|l| l.split_once('=')) |
| 15 | + .find_map(|(k, v)| (k.trim() == "version").then(|| v.trim())) |
| 16 | + .unwrap_or_else(|| panic!("error finding version in `{}`", path)) |
| 17 | + .to_string() |
| 18 | + } |
| 19 | + |
9 | 20 | // do not run this test inside the upstream rustc repo:
|
10 | 21 | // https://github.com/rust-lang/rust-clippy/issues/6683
|
11 | 22 | if option_env!("RUSTC_TEST_SUITE").is_some() {
|
12 | 23 | return;
|
13 | 24 | }
|
14 | 25 |
|
15 |
| - let clippy_meta = cargo_metadata::MetadataCommand::new() |
16 |
| - .no_deps() |
17 |
| - .exec() |
18 |
| - .expect("could not obtain cargo metadata"); |
| 26 | + let clippy_version = read_version("Cargo.toml"); |
| 27 | + let clippy_lints_version = read_version("clippy_lints/Cargo.toml"); |
| 28 | + let clippy_utils_version = read_version("clippy_utils/Cargo.toml"); |
19 | 29 |
|
20 |
| - for krate in &["clippy_lints", "clippy_utils"] { |
21 |
| - let krate_meta = cargo_metadata::MetadataCommand::new() |
22 |
| - .current_dir(std::env::current_dir().unwrap().join(krate)) |
23 |
| - .no_deps() |
24 |
| - .exec() |
25 |
| - .expect("could not obtain cargo metadata"); |
26 |
| - assert_eq!(krate_meta.packages[0].version, clippy_meta.packages[0].version); |
27 |
| - for package in &clippy_meta.packages[0].dependencies { |
28 |
| - if package.name == *krate { |
29 |
| - assert!(package.req.matches(&krate_meta.packages[0].version)); |
30 |
| - break; |
31 |
| - } |
32 |
| - } |
33 |
| - } |
| 30 | + assert_eq!(clippy_version, clippy_lints_version); |
| 31 | + assert_eq!(clippy_version, clippy_utils_version); |
34 | 32 | }
|
35 | 33 |
|
36 | 34 | #[test]
|
|
0 commit comments