From 8731934f46d5419c2e74646abe42aff307963a4d Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 12:26:24 +0000 Subject: [PATCH 1/2] Fixed semver version compatibility --- common/version-checker/src/lib.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/common/version-checker/src/lib.rs b/common/version-checker/src/lib.rs index 55232a9885..9cca937c37 100644 --- a/common/version-checker/src/lib.rs +++ b/common/version-checker/src/lib.rs @@ -1,5 +1,4 @@ use semver::Version; -use semver::VersionReq; /// Checks whether given `version` is compatible with a given semantic version requirement `req` /// according to major-minor semver rules. The semantic version requirement can be passed as a full, @@ -7,18 +6,16 @@ use semver::VersionReq; /// The patch number in the requirement gets dropped and replaced with a wildcard (0.3.*) as all /// minor versions should be compatible with each other. pub fn is_minor_version_compatible(version: &str, req: &str) -> bool { - let version = match Version::parse(version) { + let expected_version = match Version::parse(version) { Ok(v) => v, Err(_) => return false, }; - let tmp = match Version::parse(req) { + let req_version = match Version::parse(req) { Ok(v) => v, Err(_) => return false, }; - let wildcard = format!("{}.{}.*", tmp.major, tmp.minor).to_string(); - let semver_requirement = VersionReq::parse(&wildcard).expect("panicked on semver requirement parsing. This should never happen as inputs should already have been sanitized."); - semver_requirement.matches(&version) + expected_version.major == req_version.major && expected_version.minor == req_version.minor } #[cfg(test)] @@ -56,12 +53,17 @@ mod tests { } #[test] - fn returns_false_on_foo_version() { - assert!(!is_minor_version_compatible("foo", "0.3.2")); + fn version_0_4_0_rc_1_is_compatible_with_version_0_4_0_rc_1() { + assert!(is_minor_version_compatible("0.4.0-rc.1", "0.4.0-rc.1")); } - #[test] - fn returns_false_on_bar_version() { - assert!(!is_minor_version_compatible("0.3.2", "bar")); - } + // #[test] + // fn returns_false_on_foo_version() { + // assert!(!is_minor_version_compatible("foo", "0.3.2")); + // } + // + // #[test] + // fn returns_false_on_bar_version() { + // assert!(!is_minor_version_compatible("0.3.2", "bar")); + // } } From 3e40d90b72a9de0c3bf23ef7529404b201cd37d1 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 12:26:46 +0000 Subject: [PATCH 2/2] Restored commented tests --- common/version-checker/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common/version-checker/src/lib.rs b/common/version-checker/src/lib.rs index 9cca937c37..eda9391205 100644 --- a/common/version-checker/src/lib.rs +++ b/common/version-checker/src/lib.rs @@ -57,13 +57,13 @@ mod tests { assert!(is_minor_version_compatible("0.4.0-rc.1", "0.4.0-rc.1")); } - // #[test] - // fn returns_false_on_foo_version() { - // assert!(!is_minor_version_compatible("foo", "0.3.2")); - // } - // - // #[test] - // fn returns_false_on_bar_version() { - // assert!(!is_minor_version_compatible("0.3.2", "bar")); - // } + #[test] + fn returns_false_on_foo_version() { + assert!(!is_minor_version_compatible("foo", "0.3.2")); + } + + #[test] + fn returns_false_on_bar_version() { + assert!(!is_minor_version_compatible("0.3.2", "bar")); + } }