From 64044a295f54ca90da1d2d3b93f1de1630427a48 Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Thu, 21 Jan 2016 11:19:31 -0800 Subject: [PATCH] Trim 'beta' out of go version strings This is currently broken, so go1.6beta2 will produce `go1.6beta1` instead of `go1.6`. Fixes #402 --- Changelog.md | 4 ++++ dep.go | 3 +++ dep_test.go | 26 ++++++++++++++++++++++++++ version.go | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 dep_test.go diff --git a/Changelog.md b/Changelog.md index 2dd1d26..9bc7d69 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +# v51 2016/01/21 + +* Trim 'beta' out of go version strings when determining major version. + # v50 2016/01/19 * More verbose output on save -v. diff --git a/dep.go b/dep.go index 66e7af1..22d3c35 100644 --- a/dep.go +++ b/dep.go @@ -77,6 +77,9 @@ func trimGoVersion(version string) (string, error) { if len(p) < 2 { return "", fmt.Errorf("Error determing major go version from: %q", version) } + if strings.Contains(p[1], "beta") { + p[1] = strings.Split(p[1], "beta")[0] + } return p[0] + "." + p[1], nil } diff --git a/dep_test.go b/dep_test.go new file mode 100644 index 0000000..3c2ee59 --- /dev/null +++ b/dep_test.go @@ -0,0 +1,26 @@ +package main + +import "testing" + +func TestTrimGoVersion(t *testing.T) { + var cases = []struct { + in, out string + err bool + }{ + {in: "go1.5", out: "go1.5", err: false}, + {in: "go1.5beta1", out: "go1.5", err: false}, + {in: "go1.5.1", out: "go1.5", err: false}, + {in: "devel", out: "devel", err: false}, + {in: "boom", out: "", err: true}, + } + + for _, c := range cases { + mv, err := trimGoVersion(c.in) + if err != nil && !c.err { + t.Errorf("Unexpected error: %s", err) + } + if mv != c.out { + t.Errorf("Expected trimGoVersion(%s) == '%s', but got '%s'", c.in, c.out, mv) + } + } +} diff --git a/version.go b/version.go index 7396411..aaf0aaf 100644 --- a/version.go +++ b/version.go @@ -5,7 +5,7 @@ import ( "runtime" ) -const version = 50 +const version = 51 var cmdVersion = &Command{ Name: "version",