Skip to content

Commit

Permalink
Merge 08e6c48 into 276664f
Browse files Browse the repository at this point in the history
  • Loading branch information
cweill committed Apr 7, 2019
2 parents 276664f + 08e6c48 commit dab1430
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
sudo: required
language: go
sudo: false
go:
- 1.8.x
# - 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
before_install:
# - sudo apt-get install go-dep
- go get github.com/mattn/goveralls
- go get github.com/mjibson/esc
# - dep ensure --add github.com/mjibson/esc@v0.1.0
- 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 dab1430

Please sign in to comment.