From 2d5031362f87b2427bea3fbe71b5cff054646739 Mon Sep 17 00:00:00 2001 From: cxworks Date: Tue, 27 Jun 2023 14:31:46 -0400 Subject: [PATCH 1/9] Add missed test cases --- tests/test_identifier.rs | 48 +++++++++++++++++++++++++++++++++++++++ tests/test_version.rs | 12 ++++++++++ tests/test_version_req.rs | 3 +++ tests/util/mod.rs | 17 +++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/tests/test_identifier.rs b/tests/test_identifier.rs index dc888c9c..bd83cd81 100644 --- a/tests/test_identifier.rs +++ b/tests/test_identifier.rs @@ -43,3 +43,51 @@ fn test_eq() { assert_ne!(prerelease("aaaaaaaaa"), prerelease("bbbbbbbbb")); assert_ne!(build_metadata("1"), build_metadata("001")); } + +#[test] +fn test_comparator() { + let compatator = comparator("4.4.5-44"); + assert_to_string(compatator, "^4.4.5-44"); + + let compatator = comparator("2.X"); + assert_to_string(compatator, "2.*"); + + let compatator = comparator("2"); + assert_to_string(compatator, "^2"); + + let compatator = comparator("5.x.x"); + assert_to_string(compatator, "5.*"); +} + +#[test] +fn test_prerelease() { + let err = prerelease_err("88.6688.b.rrrrrrr8.b.6bbbbbbb66.66\0"); + assert_to_string(err, "unexpected character in pre-release identifier"); +} + +#[test] +fn test_comparator_err() { + let err = comparator_err("4.4.4-012"); + assert_to_string(err, "invalid leading zero in pre-release identifier"); + + let err = comparator_err("5.4.4+4."); + assert_to_string(err, "empty identifier segment in build metadata"); + + let err = comparator_err(">"); + assert_to_string( + err, + "unexpected end of input while parsing major version number", + ); + + let err = comparator_err("4."); + assert_to_string( + err, + "unexpected end of input while parsing minor version number", + ); + + let err = comparator_err("4.*."); + assert_to_string(err, "unexpected character after wildcard in version req"); + + let err = comparator_err("55444.4.45-6+6.4.5.45-5644ÿ"); + assert_to_string(err, "unexpected character 'ÿ' after build metadata"); +} diff --git a/tests/test_version.rs b/tests/test_version.rs index de3628fa..6f3943d5 100644 --- a/tests/test_version.rs +++ b/tests/test_version.rs @@ -47,6 +47,18 @@ fn test_parse() { let err = version_err("1.2.3-01"); assert_to_string(err, "invalid leading zero in pre-release identifier"); + let err = version_err("5.1.5++"); + assert_to_string(err, "empty identifier segment in build metadata"); + + let err = version_err("07"); + assert_to_string(err, "invalid leading zero in major version number"); + + let err = version_err("75774777777757777757"); + assert_to_string(err, "value of major version number exceeds u64::MAX"); + + let err = version_err("8\0"); + assert_to_string(err, "unexpected character '\\0' after major version number"); + let parsed = version("1.2.3"); let expected = Version::new(1, 2, 3); assert_eq!(parsed, expected); diff --git a/tests/test_version_req.rs b/tests/test_version_req.rs index 98a03ac8..55253848 100644 --- a/tests/test_version_req.rs +++ b/tests/test_version_req.rs @@ -168,6 +168,9 @@ pub fn test_multiple() { // https://github.com/steveklabnik/semver/issues/56 let err = req_err("1.2.3 - 2.3.4"); assert_to_string(err, "expected comma after patch version number, found '-'"); + + let err = req_err(">=2,22002222022222222,2,21,222,2,2,2,222,2,221,222,2,2,2,21,222,2,2,2,2,2,222,2222,2,2,2,222,2,222,2,222,'6"); + assert_to_string(err, "excessive number of version comparators"); } #[test] diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 5cc142c4..88021d04 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use semver::{BuildMetadata, Error, Prerelease, Version, VersionReq}; +use semver::{BuildMetadata, Comparator, Error, Prerelease, Version, VersionReq}; use std::fmt::Display; #[cfg_attr(not(no_track_caller), track_caller)] @@ -28,6 +28,11 @@ pub(super) fn prerelease(text: &str) -> Prerelease { Prerelease::new(text).unwrap() } +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn prerelease_err(text: &str) -> Error { + Prerelease::new(text).unwrap_err() +} + #[cfg_attr(not(no_track_caller), track_caller)] pub(super) fn build_metadata(text: &str) -> BuildMetadata { BuildMetadata::new(text).unwrap() @@ -37,3 +42,13 @@ pub(super) fn build_metadata(text: &str) -> BuildMetadata { pub(super) fn assert_to_string(value: impl Display, expected: &str) { assert_eq!(value.to_string(), expected); } + +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator(text: &str) -> Comparator { + Comparator::parse(text).unwrap() +} + +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator_err(text: &str) -> Error { + Comparator::parse(text).unwrap_err() +} From b074ea0465d7ff55beb10816d8b3aa8e8c976793 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 17 Jul 2023 22:07:57 -0700 Subject: [PATCH 2/9] Resolve incorrect_partial_ord_impl_on_ord_type clippy lint This is a false positive but either way is fine. warning: incorrect implementation of `partial_cmp` on an `Ord` type --> src/impls.rs:39:1 | 39 | / impl PartialOrd for Prerelease { 40 | | fn partial_cmp(&self, rhs: &Self) -> Option { | | ___________________________________________________________- 41 | || Some(Ord::cmp(self, rhs)) 42 | || } | ||_____- help: change this to: `{ Some(self.cmp(rhs)) }` 43 | | } | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type = note: `-W clippy::incorrect-partial-ord-impl-on-ord-type` implied by `-W clippy::all` warning: incorrect implementation of `partial_cmp` on an `Ord` type --> src/impls.rs:45:1 | 45 | / impl PartialOrd for BuildMetadata { 46 | | fn partial_cmp(&self, rhs: &Self) -> Option { | | ___________________________________________________________- 47 | || Some(Ord::cmp(self, rhs)) 48 | || } | ||_____- help: change this to: `{ Some(self.cmp(rhs)) }` 49 | | } | |__^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_partial_ord_impl_on_ord_type --- src/impls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impls.rs b/src/impls.rs index c3b6c601..cc4fd415 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -38,13 +38,13 @@ impl Deref for BuildMetadata { impl PartialOrd for Prerelease { fn partial_cmp(&self, rhs: &Self) -> Option { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } impl PartialOrd for BuildMetadata { fn partial_cmp(&self, rhs: &Self) -> Option { - Some(Ord::cmp(self, rhs)) + Some(self.cmp(rhs)) } } From 2399480676a3bbd6dda26b4632813071871c44a1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 21 Jul 2023 20:22:42 -0700 Subject: [PATCH 3/9] Temporarily disable -Zrandomize-layout due to rustc ICE https://github.com/rust-lang/rust/issues/113941 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 472366db..4af4e1e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: toolchain: ${{matrix.rust}} - name: Enable type layout randomization run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV - if: matrix.rust == 'nightly' + if: matrix.rust == 'nightly' && false # FIXME https://github.com/rust-lang/rust/issues/113941 - run: cargo test - run: cargo check --no-default-features - run: cargo check --features serde From fff3f407577d48be83ac39a62aec7f9f76d5c741 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 22 Jul 2023 18:37:58 -0700 Subject: [PATCH 4/9] Revert "Temporarily disable -Zrandomize-layout due to rustc ICE" Fixed in nightly-2023-07-23. This reverts commit 2399480676a3bbd6dda26b4632813071871c44a1. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4af4e1e8..472366db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: toolchain: ${{matrix.rust}} - name: Enable type layout randomization run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV - if: matrix.rust == 'nightly' && false # FIXME https://github.com/rust-lang/rust/issues/113941 + if: matrix.rust == 'nightly' - run: cargo test - run: cargo check --no-default-features - run: cargo check --features serde From cb0790143be4df9c389d90803ddb61af893696f6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 4 Sep 2023 22:35:00 -0700 Subject: [PATCH 5/9] Update actions/checkout@v3 -> v4 --- .github/workflows/ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 472366db..008c2b52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: rust: [nightly, beta, stable, 1.52.0, 1.46.0, 1.40.0, 1.39.0, 1.36.0, 1.33.0, 1.32.0, 1.31.0] timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - run: npm install semver - run: cargo test @@ -60,7 +60,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - run: cargo generate-lockfile -Z minimal-versions - run: cargo check --locked --features serde @@ -71,7 +71,7 @@ jobs: if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy --tests --benches -- -Dclippy::all -Dclippy::pedantic @@ -84,7 +84,7 @@ jobs: MIRIFLAGS: -Zmiri-strict-provenance timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@miri - name: Run cargo miri test (64-bit little endian) run: cargo miri test --target x86_64-unknown-linux-gnu @@ -102,7 +102,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - uses: dtolnay/install@cargo-fuzz - run: cargo fuzz check @@ -113,7 +113,7 @@ jobs: if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/install@cargo-outdated - run: cargo outdated --workspace --exit-code 1 - run: cargo outdated --manifest-path fuzz/Cargo.toml --exit-code 1 From 5e093296a46d982396cecad25c46c3c4e0889e38 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Sep 2023 12:37:11 -0700 Subject: [PATCH 6/9] More comprehensible excessive version comparator test --- tests/test_version_req.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_version_req.rs b/tests/test_version_req.rs index 55253848..97438312 100644 --- a/tests/test_version_req.rs +++ b/tests/test_version_req.rs @@ -169,7 +169,7 @@ pub fn test_multiple() { let err = req_err("1.2.3 - 2.3.4"); assert_to_string(err, "expected comma after patch version number, found '-'"); - let err = req_err(">=2,22002222022222222,2,21,222,2,2,2,222,2,221,222,2,2,2,21,222,2,2,2,2,2,222,2222,2,2,2,222,2,222,2,222,'6"); + let err = req_err(">1, >2, >3, >4, >5, >6, >7, >8, >9, >10, >11, >12, >13, >14, >15, >16, >17, >18, >19, >20, >21, >22, >23, >24, >25, >26, >27, >28, >29, >30, >31, >32, >33"); assert_to_string(err, "excessive number of version comparators"); } From 2d34e8fe60334d4525c70462b74e85508d2529e6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Sep 2023 12:33:55 -0700 Subject: [PATCH 7/9] Touch up PR 299 test cases --- tests/test_identifier.rs | 28 ++++++++++++++-------------- tests/test_version.rs | 4 ++-- tests/util/mod.rs | 20 ++++++++++---------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/test_identifier.rs b/tests/test_identifier.rs index bd83cd81..ef9655d3 100644 --- a/tests/test_identifier.rs +++ b/tests/test_identifier.rs @@ -46,31 +46,31 @@ fn test_eq() { #[test] fn test_comparator() { - let compatator = comparator("4.4.5-44"); - assert_to_string(compatator, "^4.4.5-44"); + let parsed = comparator("1.2.3-alpha"); + assert_to_string(parsed, "^1.2.3-alpha"); - let compatator = comparator("2.X"); - assert_to_string(compatator, "2.*"); + let parsed = comparator("2.X"); + assert_to_string(parsed, "2.*"); - let compatator = comparator("2"); - assert_to_string(compatator, "^2"); + let parsed = comparator("2"); + assert_to_string(parsed, "^2"); - let compatator = comparator("5.x.x"); - assert_to_string(compatator, "5.*"); + let parsed = comparator("2.x.x"); + assert_to_string(parsed, "2.*"); } #[test] fn test_prerelease() { - let err = prerelease_err("88.6688.b.rrrrrrr8.b.6bbbbbbb66.66\0"); + let err = prerelease_err("1.b\0"); assert_to_string(err, "unexpected character in pre-release identifier"); } #[test] fn test_comparator_err() { - let err = comparator_err("4.4.4-012"); + let err = comparator_err("1.2.3-01"); assert_to_string(err, "invalid leading zero in pre-release identifier"); - let err = comparator_err("5.4.4+4."); + let err = comparator_err("1.2.3+4."); assert_to_string(err, "empty identifier segment in build metadata"); let err = comparator_err(">"); @@ -79,15 +79,15 @@ fn test_comparator_err() { "unexpected end of input while parsing major version number", ); - let err = comparator_err("4."); + let err = comparator_err("1."); assert_to_string( err, "unexpected end of input while parsing minor version number", ); - let err = comparator_err("4.*."); + let err = comparator_err("1.*."); assert_to_string(err, "unexpected character after wildcard in version req"); - let err = comparator_err("55444.4.45-6+6.4.5.45-5644ÿ"); + let err = comparator_err("1.2.3+4ÿ"); assert_to_string(err, "unexpected character 'ÿ' after build metadata"); } diff --git a/tests/test_version.rs b/tests/test_version.rs index 6f3943d5..991087f7 100644 --- a/tests/test_version.rs +++ b/tests/test_version.rs @@ -47,13 +47,13 @@ fn test_parse() { let err = version_err("1.2.3-01"); assert_to_string(err, "invalid leading zero in pre-release identifier"); - let err = version_err("5.1.5++"); + let err = version_err("1.2.3++"); assert_to_string(err, "empty identifier segment in build metadata"); let err = version_err("07"); assert_to_string(err, "invalid leading zero in major version number"); - let err = version_err("75774777777757777757"); + let err = version_err("111111111111111111111.0.0"); assert_to_string(err, "value of major version number exceeds u64::MAX"); let err = version_err("8\0"); diff --git a/tests/util/mod.rs b/tests/util/mod.rs index 88021d04..07d691fa 100644 --- a/tests/util/mod.rs +++ b/tests/util/mod.rs @@ -23,6 +23,16 @@ pub(super) fn req_err(text: &str) -> Error { VersionReq::parse(text).unwrap_err() } +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator(text: &str) -> Comparator { + Comparator::parse(text).unwrap() +} + +#[cfg_attr(not(no_track_caller), track_caller)] +pub(super) fn comparator_err(text: &str) -> Error { + Comparator::parse(text).unwrap_err() +} + #[cfg_attr(not(no_track_caller), track_caller)] pub(super) fn prerelease(text: &str) -> Prerelease { Prerelease::new(text).unwrap() @@ -42,13 +52,3 @@ pub(super) fn build_metadata(text: &str) -> BuildMetadata { pub(super) fn assert_to_string(value: impl Display, expected: &str) { assert_eq!(value.to_string(), expected); } - -#[cfg_attr(not(no_track_caller), track_caller)] -pub(super) fn comparator(text: &str) -> Comparator { - Comparator::parse(text).unwrap() -} - -#[cfg_attr(not(no_track_caller), track_caller)] -pub(super) fn comparator_err(text: &str) -> Error { - Comparator::parse(text).unwrap_err() -} From 83abc7f7b32fba9b369fdd984730206c1d89cc92 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Sep 2023 13:05:23 -0700 Subject: [PATCH 8/9] Relocate comparator parse testing --- tests/test_identifier.rs | 42 --------------------------------------- tests/test_version_req.rs | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 43 deletions(-) diff --git a/tests/test_identifier.rs b/tests/test_identifier.rs index ef9655d3..40d85965 100644 --- a/tests/test_identifier.rs +++ b/tests/test_identifier.rs @@ -44,50 +44,8 @@ fn test_eq() { assert_ne!(build_metadata("1"), build_metadata("001")); } -#[test] -fn test_comparator() { - let parsed = comparator("1.2.3-alpha"); - assert_to_string(parsed, "^1.2.3-alpha"); - - let parsed = comparator("2.X"); - assert_to_string(parsed, "2.*"); - - let parsed = comparator("2"); - assert_to_string(parsed, "^2"); - - let parsed = comparator("2.x.x"); - assert_to_string(parsed, "2.*"); -} - #[test] fn test_prerelease() { let err = prerelease_err("1.b\0"); assert_to_string(err, "unexpected character in pre-release identifier"); } - -#[test] -fn test_comparator_err() { - let err = comparator_err("1.2.3-01"); - assert_to_string(err, "invalid leading zero in pre-release identifier"); - - let err = comparator_err("1.2.3+4."); - assert_to_string(err, "empty identifier segment in build metadata"); - - let err = comparator_err(">"); - assert_to_string( - err, - "unexpected end of input while parsing major version number", - ); - - let err = comparator_err("1."); - assert_to_string( - err, - "unexpected end of input while parsing minor version number", - ); - - let err = comparator_err("1.*."); - assert_to_string(err, "unexpected character after wildcard in version req"); - - let err = comparator_err("1.2.3+4ÿ"); - assert_to_string(err, "unexpected character 'ÿ' after build metadata"); -} diff --git a/tests/test_version_req.rs b/tests/test_version_req.rs index 97438312..1ed2358a 100644 --- a/tests/test_version_req.rs +++ b/tests/test_version_req.rs @@ -335,7 +335,7 @@ pub fn test_pre() { } #[test] -pub fn test_parse_errors() { +pub fn test_parse() { let err = req_err("\0"); assert_to_string( err, @@ -370,6 +370,45 @@ pub fn test_parse_errors() { ); } +#[test] +fn test_comparator_parse() { + let parsed = comparator("1.2.3-alpha"); + assert_to_string(parsed, "^1.2.3-alpha"); + + let parsed = comparator("2.X"); + assert_to_string(parsed, "2.*"); + + let parsed = comparator("2"); + assert_to_string(parsed, "^2"); + + let parsed = comparator("2.x.x"); + assert_to_string(parsed, "2.*"); + + let err = comparator_err("1.2.3-01"); + assert_to_string(err, "invalid leading zero in pre-release identifier"); + + let err = comparator_err("1.2.3+4."); + assert_to_string(err, "empty identifier segment in build metadata"); + + let err = comparator_err(">"); + assert_to_string( + err, + "unexpected end of input while parsing major version number", + ); + + let err = comparator_err("1."); + assert_to_string( + err, + "unexpected end of input while parsing minor version number", + ); + + let err = comparator_err("1.*."); + assert_to_string(err, "unexpected character after wildcard in version req"); + + let err = comparator_err("1.2.3+4ÿ"); + assert_to_string(err, "unexpected character 'ÿ' after build metadata"); +} + #[test] fn test_cargo3202() { let ref r = req("0.*.*"); From 72a6b5a722160befddbd210f4a3d41fdab60110f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 22 Sep 2023 13:06:28 -0700 Subject: [PATCH 9/9] Release 1.0.19 --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 863f7386..f40e9521 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "semver" -version = "1.0.18" +version = "1.0.19" authors = ["David Tolnay "] categories = ["data-structures", "no-std"] description = "Parser and evaluator for Cargo's flavor of Semantic Versioning" diff --git a/src/lib.rs b/src/lib.rs index d2c4eb37..88f24383 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ //! //! [Specifying Dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html -#![doc(html_root_url = "https://docs.rs/semver/1.0.18")] +#![doc(html_root_url = "https://docs.rs/semver/1.0.19")] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(all(not(feature = "std"), not(no_alloc_crate)), no_std)] #![cfg_attr(not(no_unsafe_op_in_unsafe_fn_lint), deny(unsafe_op_in_unsafe_fn))]