diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index f7ed900334..859702751f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.14.3 - 17.11.2014 +* BUGFIX: Accept and normalize versions like 6.0.1302.0-Preview - https://github.com/fsprojects/Paket/issues/364 + #### 0.14.2 - 16.11.2014 * BUGFIX: handling of package dependencies containing string "nuget" - https://github.com/fsprojects/Paket/pull/363 diff --git a/src/Paket.Core/SemVer.fs b/src/Paket.Core/SemVer.fs index eea849fdf0..94aa4355dd 100644 --- a/src/Paket.Core/SemVer.fs +++ b/src/Paket.Core/SemVer.fs @@ -50,21 +50,27 @@ type SemVerInfo = PreRelease : PreRelease option /// The optional build no. Build : string + /// The optional prerelease build no. + PreReleaseBuild : string // The original version text Original : string option } member x.Normalize() = let build = - if String.IsNullOrEmpty x.Build |> not then "." + x.Build + if String.IsNullOrEmpty x.Build |> not && x.Build <> "0" then "." + x.Build + else "" + + let preReleaseBuild = + if String.IsNullOrEmpty x.PreReleaseBuild |> not && x.PreReleaseBuild <> "0" then "." + x.PreReleaseBuild else "" let pre = - match x.PreRelease, (String.IsNullOrEmpty x.Build |> not && x.Build <> "0") with - | Some preRelease, _ -> "-" + preRelease.Name + build - | None, true -> build + match x.PreRelease, (String.IsNullOrEmpty x.PreReleaseBuild |> not) with + | Some preRelease, _ -> "-" + preRelease.Name + preReleaseBuild + | None, true -> preReleaseBuild | _ -> "" - sprintf "%d.%d.%d" x.Major x.Minor x.Patch + pre + sprintf "%d.%d.%d" x.Major x.Minor x.Patch + build + pre member x.AsString = x.ToString() @@ -76,8 +82,7 @@ type SemVerInfo = override x.Equals(yobj) = match yobj with | :? SemVerInfo as y -> - x.Major = y.Major && x.Minor = y.Minor && x.Patch = y.Patch && x.PreRelease = y.PreRelease - && (x.Build = y.Build || (x.Build = "0" && y.Build = "") || (y.Build = "0" && x.Build = "")) + x.Major = y.Major && x.Minor = y.Minor && x.Patch = y.Patch && x.PreRelease = y.PreRelease && x.Build = y.Build && x.PreReleaseBuild = y.PreReleaseBuild | _ -> false override x.GetHashCode() = hash (x.Minor, x.Minor, x.Patch, x.PreRelease, x.Build) @@ -88,14 +93,18 @@ type SemVerInfo = if x.Major <> y.Major then compare x.Major y.Major else if x.Minor <> y.Minor then compare x.Minor y.Minor else if x.Patch <> y.Patch then compare x.Patch y.Patch - else if x.PreRelease = y.PreRelease && x.Build = y.Build then 0 - else if x.PreRelease.IsNone && not y.PreRelease.IsNone && x.Build = "" then 1 - else if y.PreRelease.IsNone && not x.PreRelease.IsNone && y.Build = "" then -1 - else if x.PreRelease <> y.PreRelease then compare x.PreRelease y.PreRelease else if x.Build <> y.Build then match Int32.TryParse x.Build, Int32.TryParse y.Build with | (true, b1), (true, b2) -> compare b1 b2 | _ -> compare x.Build y.Build + else if x.PreRelease = y.PreRelease && x.PreReleaseBuild = y.PreReleaseBuild then 0 + else if x.PreRelease.IsNone && not y.PreRelease.IsNone && x.PreReleaseBuild = "0" then 1 + else if y.PreRelease.IsNone && not x.PreRelease.IsNone && y.PreReleaseBuild = "0" then -1 + else if x.PreRelease <> y.PreRelease then compare x.PreRelease y.PreRelease + else if x.PreReleaseBuild <> y.PreReleaseBuild then + match Int32.TryParse x.PreReleaseBuild, Int32.TryParse y.PreReleaseBuild with + | (true, b1), (true, b2) -> compare b1 b2 + | _ -> compare x.PreReleaseBuild y.PreReleaseBuild else 0 | _ -> invalidArg "yobj" "cannot compare values of different types" @@ -111,36 +120,16 @@ module SemVer = /// parse "1.2.3-alpha002" > parse "1.2.3-alpha1" // true /// parse "1.5.0-beta.2" > parse "1.5.0-rc.1" // false let Parse(version : string) = - let splitted = version.Split '.' + let dashSplitted = version.Split '-' + let splitted = dashSplitted.[0].Split '.' let l = splitted.Length - - let patch, preRelease = - match l with - | 0 -> 0, "" - | 1 -> - let splitted' = splitted.[0].Split '-' - 0, - if splitted'.Length > 1 then splitted'.[1] - else "" - | 2 -> - let splitted' = splitted.[1].Split '-' - 0, - if splitted'.Length > 1 then splitted'.[1] - else "" - | _ -> - let splitted' = splitted.[2].Split '-' - Int32.Parse splitted'.[0], - if splitted'.Length > 1 then splitted'.[1] - else "" - { Major = - if l > 0 then Int32.Parse (splitted.[0].Split('-').[0]) - else 0 - Minor = - if l > 1 then Int32.Parse (splitted.[1].Split('-').[0]) - else 0 - Patch = patch - PreRelease = PreRelease.TryParse preRelease - Build = - if l > 3 then splitted.[3] - else String.Empty + + let prereleaseBuild = if dashSplitted.Length > 1 && dashSplitted.[1].Split('.').Length > 1 then dashSplitted.[1].Split('.').[1] else "0" + + { Major = if l > 0 then Int32.Parse(splitted.[0]) else 0 + Minor = if l > 1 then Int32.Parse(splitted.[1]) else 0 + Patch = if l > 2 then Int32.Parse(splitted.[2]) else 0 + PreRelease = PreRelease.TryParse(if dashSplitted.Length > 1 then dashSplitted.[1].Split('.').[0] else String.Empty) + Build = if l > 3 then splitted.[3] else "0" + PreReleaseBuild = prereleaseBuild Original = Some version } \ No newline at end of file diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 1d5bb0668e..7b62adecc3 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -31,7 +31,7 @@ paket.exe - D:\code\paket + D:\code\PaketKopie pdbonly diff --git a/tests/Paket.Tests/SemVerSpecs.fs b/tests/Paket.Tests/SemVerSpecs.fs index 1eabbec590..7be5c46a90 100644 --- a/tests/Paket.Tests/SemVerSpecs.fs +++ b/tests/Paket.Tests/SemVerSpecs.fs @@ -14,6 +14,16 @@ let ``can parse semver strings and print the result``() = (SemVer.Parse "1.0.0-alpha.beta").ToString() |> shouldEqual "1.0.0-alpha.beta" (SemVer.Parse "1.0.0-rc.1").ToString() |> shouldEqual "1.0.0-rc.1" (SemVer.Parse "1.2.3-foo").ToString() |> shouldEqual "1.2.3-foo" + (SemVer.Parse "6.0.1302.0-Preview").PreRelease |> shouldEqual (PreRelease.TryParse "Preview") + (SemVer.Parse "1.2.3").ToString() |> shouldEqual "1.2.3" + (SemVer.Parse "1.2.3.0").ToString() |> shouldEqual "1.2.3.0" + (SemVer.Parse "1.2.3.0").Patch |> shouldEqual 3 + (SemVer.Parse "1.2.3").Patch |> shouldEqual 3 + (SemVer.Parse "1.2.3.0").Build |> shouldEqual "0" + (SemVer.Parse "1.2.3").Build |> shouldEqual "0" + (SemVer.Parse "3.1.1.1").Build |> shouldEqual "1" + (SemVer.Parse "1.0.0-rc.3").PreReleaseBuild |> shouldEqual "3" + (SemVer.Parse "1.0.0-rc.1").PreReleaseBuild |> shouldEqual "1" [] let ``can parse semver strings``() = @@ -24,7 +34,7 @@ let ``can parse semver strings``() = semVer.PreRelease |> shouldEqual (Some { Origin = "alpha" Name = "alpha" Number = None }) - semVer.Build |> shouldEqual "beta" + semVer.PreReleaseBuild |> shouldEqual "beta" [] let ``can compare semvers``() = @@ -69,6 +79,7 @@ let ``can parse FSharp.Data versions``() = let ``can normalize versions``() = (SemVer.Parse "2.3") |> shouldEqual (SemVer.Parse "2.3.0") (SemVer.Parse "2.3").Normalize() |> shouldEqual ((SemVer.Parse "2.3.0").ToString()) + (SemVer.Parse "3.1.1.1").Normalize() |> shouldEqual "3.1.1.1" (SemVer.Parse "3.1.1.1").Normalize() |> shouldEqual ((SemVer.Parse "3.1.1.1").ToString()) (SemVer.Parse "1.2.3").Normalize() |> shouldEqual ((SemVer.Parse "1.2.3").ToString()) (SemVer.Parse "1.0.0-rc.3").Normalize() |> shouldEqual ((SemVer.Parse "1.0.0-rc.3").ToString()) @@ -78,4 +89,9 @@ let ``can normalize versions``() = [] let ``can normalize build zeros``() = - (SemVer.Parse "2.0.30506.0").Normalize() |> shouldEqual ((SemVer.Parse "2.0.30506").ToString()) \ No newline at end of file + (SemVer.Parse "2.0.30506.0").Normalize() |> shouldEqual ((SemVer.Parse "2.0.30506").ToString()) + + +[] +let ``can normalize build zeros in prerelease``() = + (SemVer.Parse "6.0.1302.0-Preview").Normalize() |> shouldEqual "6.0.1302-Preview"