Skip to content

Commit

Permalink
fix(go): support 1.16
Browse files Browse the repository at this point in the history
resolves #428
  • Loading branch information
JanDeDobbeleer committed Feb 18, 2021
1 parent c7db86e commit de49804
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/segment_golang.go
Expand Up @@ -17,7 +17,7 @@ func (g *golang) init(props *properties, env environmentInfo) {
{
executable: "go",
args: []string{"version"},
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+)(.(?P<patch>[0-9]+))?)))`,
},
},
versionURLTemplate: "[%s](https://golang.org/doc/go%s.%s)",
Expand Down
34 changes: 34 additions & 0 deletions src/segment_golang_test.go
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGolang(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
Version string
}{
{Case: "Go 1.15", ExpectedString: "1.15.8", Version: "go version go1.15.8 darwin/amd64"},
{Case: "Go 1.16", ExpectedString: "1.16", Version: "go version go1.16 darwin/amd64"},
}
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("hasCommand", "go").Return(true)
env.On("runCommand", "go", []string{"version"}).Return(tc.Version, nil)
env.On("hasFiles", "*.go").Return(true)
props := &properties{
values: map[Property]interface{}{
DisplayVersion: true,
},
}
g := &golang{}
g.init(props, env)
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
assert.Equal(t, tc.ExpectedString, g.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
}
}

0 comments on commit de49804

Please sign in to comment.