]> git.lizzy.rs Git - rust.git/blobdiff - tests/versioncheck.rs
Fix `manual_map` at the end of an if chain
[rust.git] / tests / versioncheck.rs
index ec54e11dc06c5002ca53a2ab7c2eb71a1b25ef6e..1eaec4a50a6a6396f51a1d15969be3cd580c3190 100644 (file)
@@ -2,43 +2,59 @@
 use rustc_tools_util::VersionInfo;
 
 #[test]
-fn check_that_clippy_lints_has_the_same_version_as_clippy() {
+fn check_that_clippy_lints_and_clippy_utils_have_the_same_version_as_clippy() {
+    // 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;
+    }
+
     let clippy_meta = cargo_metadata::MetadataCommand::new()
         .no_deps()
         .exec()
         .expect("could not obtain cargo metadata");
-    std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap();
-    let clippy_lints_meta = cargo_metadata::MetadataCommand::new()
-        .no_deps()
-        .exec()
-        .expect("could not obtain cargo metadata");
-    assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version);
-    for package in &clippy_meta.packages[0].dependencies {
-        if package.name == "clippy_lints" {
-            assert!(package.req.matches(&clippy_lints_meta.packages[0].version));
-            return;
+
+    for krate in &["clippy_lints", "clippy_utils"] {
+        let krate_meta = cargo_metadata::MetadataCommand::new()
+            .current_dir(std::env::current_dir().unwrap().join(krate))
+            .no_deps()
+            .exec()
+            .expect("could not obtain cargo metadata");
+        assert_eq!(krate_meta.packages[0].version, clippy_meta.packages[0].version);
+        for package in &clippy_meta.packages[0].dependencies {
+            if package.name == *krate {
+                assert!(package.req.matches(&krate_meta.packages[0].version));
+                break;
+            }
         }
     }
 }
 
 #[test]
 fn check_that_clippy_has_the_same_major_version_as_rustc() {
+    // 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;
+    }
+
     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;
 
-    // get the rustc version from cargo
-    // this way the rust-toolchain file version is honored
+    // 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());
     let rustc_version = String::from_utf8(
-        std::process::Command::new("cargo")
+        std::process::Command::new(&rustc)
             .arg("--version")
             .output()
-            .expect("failed to run 'cargo --version'")
+            .expect("failed to run `rustc --version`")
             .stdout,
     )
     .unwrap();
-    // extract "1 50 0" from "cargo 1.50.0-nightly (a3c2627fb 2020-12-14)"
+    // extract "1 XX 0" from "rustc 1.XX.0-nightly (<commit> <date>)"
     let vsplit: Vec<&str> = rustc_version
         .split(' ')
         .nth(1)
@@ -50,9 +66,7 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() {
         .collect();
     match vsplit.as_slice() {
         [rustc_major, rustc_minor, _rustc_patch] => {
-            // clippy 0.1.50 should correspond to rustc 1.50.0
-            dbg!(&rustc_version);
-            dbg!(&clippy_version);
+            // 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(),
@@ -68,8 +82,7 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() {
             // we don't want our tests failing suddenly
         },
         _ => {
-            dbg!(vsplit);
-            panic!("Failed to parse rustc version");
+            panic!("Failed to parse rustc version: {:?}", vsplit);
         },
     };
 }