Skip to content

Commit ae5af0c

Browse files
committed
Remove cargo_metadata dependency from clippy
1 parent 7025283 commit ae5af0c

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ name = "clippy-driver"
2121
path = "src/driver.rs"
2222

2323
[dependencies]
24-
clippy_lints = { version = "0.1", path = "clippy_lints" }
24+
clippy_lints = { path = "clippy_lints" }
2525
semver = "1.0"
26-
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
26+
rustc_tools_util = { path = "rustc_tools_util" }
2727
tempfile = { version = "3.2", optional = true }
2828

2929
[dev-dependencies]
30-
cargo_metadata = "0.14"
3130
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
3231
tester = "0.9"
3332
regex = "1.5"

tests/versioncheck.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,32 @@
33
#![allow(clippy::single_match_else)]
44

55
use rustc_tools_util::VersionInfo;
6+
use std::fs;
67

78
#[test]
89
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+
920
// do not run this test inside the upstream rustc repo:
1021
// https://github.com/rust-lang/rust-clippy/issues/6683
1122
if option_env!("RUSTC_TEST_SUITE").is_some() {
1223
return;
1324
}
1425

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");
1929

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);
3432
}
3533

3634
#[test]

0 commit comments

Comments
 (0)