diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 0e18fcb..4252e4d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -12,8 +12,8 @@ }, { "ImportPath": "github.com/blang/semver", - "Comment": "v2.1.0", - "Rev": "9bf7bff48b0388cb75991e58c6df7d13e982f1f2" + "Comment": "v3.0.0", + "Rev": "2f3112b6f8f18f9df8743cc75ed51da08094ef6a" }, { "ImportPath": "github.com/google/go-github/github", diff --git a/Godeps/_workspace/src/github.com/blang/semver/README.md b/Godeps/_workspace/src/github.com/blang/semver/README.md index d9c2f98..5171c5c 100644 --- a/Godeps/_workspace/src/github.com/blang/semver/README.md +++ b/Godeps/_workspace/src/github.com/blang/semver/README.md @@ -12,8 +12,8 @@ Note: Always vendor your dependencies or fix on a specific version tag. ```go import github.com/blang/semver -v1, err := semver.New("1.0.0-beta") -v2, err := semver.New("2.0.0-beta") +v1, err := semver.Make("1.0.0-beta") +v2, err := semver.Make("2.0.0-beta") v1.Compare(v2) ``` @@ -53,7 +53,7 @@ Have a look at full examples in [examples/main.go](examples/main.go) ```go import github.com/blang/semver -v, err := semver.New("0.0.1-alpha.preview+123.github") +v, err := semver.Make("0.0.1-alpha.preview+123.github") fmt.Printf("Major: %d\n", v.Major) fmt.Printf("Minor: %d\n", v.Minor) fmt.Printf("Patch: %d\n", v.Patch) @@ -76,7 +76,7 @@ if len(v.Build) > 0 { } } -v001, err := semver.New("0.0.1") +v001, err := semver.Make("0.0.1") // Compare using helpers: v.GT(v2), v.LT, v.GTE, v.LTE v001.GT(v) == true v.LT(v001) == true diff --git a/Godeps/_workspace/src/github.com/blang/semver/examples/main.go b/Godeps/_workspace/src/github.com/blang/semver/examples/main.go index 617d72a..f36c983 100644 --- a/Godeps/_workspace/src/github.com/blang/semver/examples/main.go +++ b/Godeps/_workspace/src/github.com/blang/semver/examples/main.go @@ -32,8 +32,8 @@ func main() { } } - // New == Parse - v001, err := semver.New("0.0.1") + // Make == Parse (Value), New for Pointer + v001, err := semver.Make("0.0.1") fmt.Println("\nUse Version.Compare for comparisons (-1, 0, 1):") fmt.Printf("%q is greater than %q: Compare == %d\n", v001, v, v001.Compare(v)) diff --git a/Godeps/_workspace/src/github.com/blang/semver/semver.go b/Godeps/_workspace/src/github.com/blang/semver/semver.go index 9df310b..c82fe66 100644 --- a/Godeps/_workspace/src/github.com/blang/semver/semver.go +++ b/Godeps/_workspace/src/github.com/blang/semver/semver.go @@ -191,12 +191,19 @@ func (v Version) Validate() error { return nil } -// Alias for Parse, parses version string and returns a validated Version or error -func New(s string) (Version, error) { +// New is an alias for Parse and returns a pointer, parses version string and returns a validated Version or error +func New(s string) (vp *Version, err error) { + v, err := Parse(s) + vp = &v + return +} + +// Make is an alias for Parse, parses version string and returns a validated Version or error +func Make(s string) (Version, error) { return Parse(s) } -// Parses version string and returns a validated Version or error +// Parse parses version string and returns a validated Version or error func Parse(s string) (Version, error) { if len(s) == 0 { return Version{}, errors.New("Version string empty") @@ -285,6 +292,15 @@ func Parse(s string) (Version, error) { return v, nil } +// MustParse is like Parse but panics if the version cannot be parsed. +func MustParse(s string) Version { + v, err := Parse(s) + if err != nil { + panic(`semver: Parse(` + s + `): ` + err.Error()) + } + return v +} + // PreRelease Version type PRVersion struct { VersionStr string diff --git a/Godeps/_workspace/src/github.com/blang/semver/semver_test.go b/Godeps/_workspace/src/github.com/blang/semver/semver_test.go index 90c4545..e56ebce 100644 --- a/Godeps/_workspace/src/github.com/blang/semver/semver_test.go +++ b/Godeps/_workspace/src/github.com/blang/semver/semver_test.go @@ -50,6 +50,19 @@ func TestParse(t *testing.T) { } } +func TestMustParse(t *testing.T) { + _ = MustParse("32.2.1-alpha") +} + +func TestMustParse_panic(t *testing.T) { + defer func() { + if recover() == nil { + t.Errorf("Should have panicked") + } + }() + _ = MustParse("invalid version") +} + func TestValidate(t *testing.T) { for _, test := range formatTests { if err := test.v.Validate(); err != nil { @@ -259,6 +272,21 @@ func TestNewHelper(t *testing.T) { if err != nil { t.Fatalf("Unexpected error %q", err) } + + // New returns pointer + if v == nil { + t.Fatal("Version is nil") + } + if v.Compare(Version{1, 2, 3, nil, nil}) != 0 { + t.Fatal("Unexpected comparison problem") + } +} + +func TestMakeHelper(t *testing.T) { + v, err := Make("1.2.3") + if err != nil { + t.Fatalf("Unexpected error %q", err) + } if v.Compare(Version{1, 2, 3, nil, nil}) != 0 { t.Fatal("Unexpected comparison problem") } @@ -269,7 +297,7 @@ func BenchmarkParseSimple(b *testing.B) { b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { - New(VERSION) + Parse(VERSION) } } @@ -278,7 +306,7 @@ func BenchmarkParseComplex(b *testing.B) { b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { - New(VERSION) + Parse(VERSION) } } @@ -287,13 +315,13 @@ func BenchmarkParseAverage(b *testing.B) { b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { - New(formatTests[n%l].result) + Parse(formatTests[n%l].result) } } func BenchmarkStringSimple(b *testing.B) { const VERSION = "0.0.1" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -303,7 +331,7 @@ func BenchmarkStringSimple(b *testing.B) { func BenchmarkStringLarger(b *testing.B) { const VERSION = "11.15.2012" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -313,7 +341,7 @@ func BenchmarkStringLarger(b *testing.B) { func BenchmarkStringComplex(b *testing.B) { const VERSION = "0.0.1-alpha.preview+123.456" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -332,7 +360,7 @@ func BenchmarkStringAverage(b *testing.B) { func BenchmarkValidateSimple(b *testing.B) { const VERSION = "0.0.1" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -342,7 +370,7 @@ func BenchmarkValidateSimple(b *testing.B) { func BenchmarkValidateComplex(b *testing.B) { const VERSION = "0.0.1-alpha.preview+123.456" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -361,7 +389,7 @@ func BenchmarkValidateAverage(b *testing.B) { func BenchmarkCompareSimple(b *testing.B) { const VERSION = "0.0.1" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { @@ -371,7 +399,7 @@ func BenchmarkCompareSimple(b *testing.B) { func BenchmarkCompareComplex(b *testing.B) { const VERSION = "0.0.1-alpha.preview+123.456" - v, _ := New(VERSION) + v, _ := Parse(VERSION) b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { diff --git a/Godeps/_workspace/src/github.com/blang/semver/sort_test.go b/Godeps/_workspace/src/github.com/blang/semver/sort_test.go index 209a6ef..6889397 100644 --- a/Godeps/_workspace/src/github.com/blang/semver/sort_test.go +++ b/Godeps/_workspace/src/github.com/blang/semver/sort_test.go @@ -6,9 +6,9 @@ import ( ) func TestSort(t *testing.T) { - v100, _ := New("1.0.0") - v010, _ := New("0.1.0") - v001, _ := New("0.0.1") + v100, _ := Parse("1.0.0") + v010, _ := Parse("0.1.0") + v001, _ := Parse("0.0.1") versions := []Version{v010, v100, v001} Sort(versions) @@ -19,9 +19,9 @@ func TestSort(t *testing.T) { } func BenchmarkSort(b *testing.B) { - v100, _ := New("1.0.0") - v010, _ := New("0.1.0") - v001, _ := New("0.0.1") + v100, _ := Parse("1.0.0") + v010, _ := Parse("0.1.0") + v001, _ := Parse("0.0.1") b.ReportAllocs() b.ResetTimer() for n := 0; n < b.N; n++ { diff --git a/check_command.go b/check_command.go index f5e8f4a..ae6cb83 100644 --- a/check_command.go +++ b/check_command.go @@ -82,5 +82,5 @@ func (r byVersion) Less(i, j int) bool { return false } - return first.LT(second) + return first.LT(*second) }