Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TravisCI and add go1.11 and go1.12 support #94

Merged
merged 5 commits into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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