Skip to content

Commit

Permalink
Fix TravisCI and add go1.11 and go1.12 support (#94) (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
cweill authored Apr 7, 2019
1 parent 276664f commit 893b576
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
sudo: required
language: go
sudo: false
go:
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
before_install:
- go get github.com/mattn/goveralls
- go get github.com/mjibson/esc
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
script:
- go test ./...
Expand Down
23 changes: 20 additions & 3 deletions gotests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"path"
"regexp"
"runtime"
"strings"
"testing"
"unicode"

Expand Down Expand Up @@ -606,8 +608,9 @@ func TestGenerateTests(t *testing.T) {
args: args{
srcPath: `testdata/undefinedtypes/interface_embedding.go`,
},
wantNoTests: true,
wantErr: true,
want: mustReadAndFormatGoFile(t, "testdata/goldens/interface_embedding.go"),
wantNoTests: !versionGreaterOrEqualThan("go1.11"),
wantErr: !versionGreaterOrEqualThan("go1.11"),
},
}
tmp, err := ioutil.TempDir("", "gotests_test")
Expand Down Expand Up @@ -646,10 +649,24 @@ func TestGenerateTests(t *testing.T) {
}
}

func versionGreaterOrEqualThan(version string) bool {
prefixes := []string{"go1.9", "go1.10", "go1.11", "go1.12", "go1.13"}
v := runtime.Version()
for _, prefix := range prefixes {
if strings.Contains(version, prefix) {
return true
}
if strings.Contains(v, prefix) {
return false
}
}
return true
}

func mustReadAndFormatGoFile(t *testing.T, filename string) string {
fmted, err := imports.Process(filename, nil, nil)
if err != nil {
t.Fatal(err)
t.Fatalf("reading and formatting file: %v", err)
}
return string(fmted)
}
Expand Down
21 changes: 21 additions & 0 deletions testdata/goldens/interface_embedding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package undefinedtypes

import "testing"

func TestSomeStruct_Do(t *testing.T) {
type fields struct {
Doer some.Doer
}
testCases := []struct {
name string
fields fields
}{
// TODO: Add test cases.
}
for _, tt := range testCases {
c := &SomeStruct{
Doer: tt.fields.Doer,
}
c.Do()
}
}
2 changes: 1 addition & 1 deletion testdata/goldens/target_test_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test_wrapToString(t *testing.T) {
args args
want []string
}{
// TODO: Add test cases.
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 893b576

Please sign in to comment.