From 07c0e2337052447407e85b86abfaa87d2a9cd900 Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Sun, 7 Apr 2019 00:30:04 -0400 Subject: [PATCH 1/5] Try dep --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9260cda..c884fed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,12 @@ go: - 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 ./... From 6271baa4497d02e76318eb6998a0c91a7a93e246 Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Sun, 7 Apr 2019 01:12:48 -0400 Subject: [PATCH 2/5] Another attempt --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c884fed..085c823 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,9 @@ go: - 1.11.x - 1.12.x before_install: - - sudo apt-get install go-dep + # - sudo apt-get install go-dep - go get github.com/mattn/goveralls - - dep ensure --add github.com/mjibson/esc@v0.1.0 + # - 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 ./... From 1d86d8b1391a7517bd97472b15dcd405819bbc75 Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Sun, 7 Apr 2019 12:37:32 -0400 Subject: [PATCH 3/5] Try without interface embedding --- .travis.yml | 4 ++-- gotests_test.go | 18 +++++++++--------- testdata/goldens/target_test_file.go | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 085c823..89d33d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ +sudo: required language: go -sudo: false go: - - 1.8.x + # - 1.8.x - 1.9.x - 1.10.x - 1.11.x diff --git a/gotests_test.go b/gotests_test.go index 9236296..b8257a8 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -601,14 +601,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_return_value_custom_template.go"), }, - { - name: "Test interface embedding", - args: args{ - srcPath: `testdata/undefinedtypes/interface_embedding.go`, - }, - wantNoTests: true, - wantErr: true, - }, + // { + // name: "Test interface embedding", + // args: args{ + // srcPath: `testdata/undefinedtypes/interface_embedding.go`, + // }, + // wantNoTests: true, + // wantErr: true, + // }, } tmp, err := ioutil.TempDir("", "gotests_test") if err != nil { @@ -649,7 +649,7 @@ func TestGenerateTests(t *testing.T) { 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) } diff --git a/testdata/goldens/target_test_file.go b/testdata/goldens/target_test_file.go index 5aacfdb..74fb6fb 100644 --- a/testdata/goldens/target_test_file.go +++ b/testdata/goldens/target_test_file.go @@ -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) { From 08e6c481f74b54236802526cf1caa6579cc15760 Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Sun, 7 Apr 2019 13:22:23 -0400 Subject: [PATCH 4/5] Check versions --- gotests_test.go | 33 +++++++++++++++++++------ testdata/goldens/interface_embedding.go | 21 ++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 testdata/goldens/interface_embedding.go diff --git a/gotests_test.go b/gotests_test.go index b8257a8..dde24cf 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "path" "regexp" + "runtime" + "strings" "testing" "unicode" @@ -601,14 +603,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_return_value_custom_template.go"), }, - // { - // name: "Test interface embedding", - // args: args{ - // srcPath: `testdata/undefinedtypes/interface_embedding.go`, - // }, - // wantNoTests: true, - // wantErr: true, - // }, + { + name: "Test interface embedding", + args: args{ + srcPath: `testdata/undefinedtypes/interface_embedding.go`, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/interface_embedding.go"), + wantNoTests: !versionGreaterOrEqualThan("go1.11"), + wantErr: !versionGreaterOrEqualThan("go1.11"), + }, } tmp, err := ioutil.TempDir("", "gotests_test") if err != nil { @@ -646,6 +649,20 @@ 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 { diff --git a/testdata/goldens/interface_embedding.go b/testdata/goldens/interface_embedding.go new file mode 100644 index 0000000..c4e576f --- /dev/null +++ b/testdata/goldens/interface_embedding.go @@ -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() + } +} From b3f8bb1e123ed5acdc6d6bac8cd95fc0451655cc Mon Sep 17 00:00:00 2001 From: Charles Weill Date: Sun, 7 Apr 2019 13:42:30 -0400 Subject: [PATCH 5/5] cleanup --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 89d33d6..bd55fa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,12 @@ sudo: required language: go go: - # - 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 - # - 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 ./...