Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Trim 'beta' out of go version strings
Browse files Browse the repository at this point in the history
This is currently broken, so go1.6beta2 will produce `go1.6beta1`
instead of `go1.6`.

Fixes #402
  • Loading branch information
Edward Muller committed Jan 21, 2016
1 parent d84b24d commit 64044a2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions dep_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"
)

const version = 50
const version = 51

var cmdVersion = &Command{
Name: "version",
Expand Down

0 comments on commit 64044a2

Please sign in to comment.