-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from cweill/develop
Merge `develop` into `master`
- Loading branch information
Showing
14 changed files
with
235 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
pull_request: | ||
branches: [ develop ] | ||
|
||
jobs: | ||
|
||
test: | ||
name: Test | ||
strategy: | ||
matrix: | ||
go-version: [1.9.x, 1.10.x, 1.11.x, 1.12.x, 1.13.x, 1.14.x, 1.15.x] | ||
os: [ubuntu-latest] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
GOPATH: ${{ github.workspace }} | ||
GO111MODULE: auto | ||
defaults: | ||
run: | ||
working-directory: ${{ env.GOPATH }}/src/github.com/${{ github.repository }} | ||
steps: | ||
|
||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
with: | ||
path: src/github.com/${{ github.repository }} | ||
|
||
- name: Get dependencies | ||
run: | | ||
go get github.com/mattn/goveralls | ||
if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi | ||
go get -v ./... | ||
- name: Test | ||
run: go test ./... | ||
|
||
- name: Get Coverage Report | ||
run: | | ||
go test -c -covermode=count -coverpkg=github.com/cweill/gotests,github.com/cweill/gotests/internal/input,github.com/cweill/gotests/internal/render,github.com/cweill/gotests/internal/goparser,github.com/cweill/gotests/internal/output,github.com/cweill/gotests/internal/models | ||
./gotests.test -test.coverprofile coverage.cov | ||
- name: Send Coverage Report | ||
run: $GOPATH/bin/goveralls -coverprofile=coverage.cov -service=github | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
testdata/goldens/function_with_return_value_template_data.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package testdata | ||
|
||
import "testing" | ||
|
||
func TestFoo4(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
want bool | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for _, tt := range testCases { | ||
if got := Foo4(); got != tt.want { | ||
t.Errorf("%q. Foo4() = %v, want %v", tt.name, got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{define "call"}}{{with .Receiver}}{{if not .IsStruct}}tt.{{end}}{{Receiver .}}.{{end}}{{.Name}}({{range $i, $el := .Parameters}}{{if $i}}, {{end}}{{if not .IsWriter}}tt.args.{{end}}{{Param .}}{{if .Type.IsVariadic}}...{{end}}{{end}}){{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{{define "function"}} | ||
{{- $f := .}} | ||
|
||
func {{.TestName}}(t *testing.T) { | ||
{{- with .Receiver}} | ||
{{- if .IsStruct}} | ||
{{- if .Fields}} | ||
type fields struct { | ||
{{- range .Fields}} | ||
{{Field .}} {{.Type}} | ||
{{- end}} | ||
} | ||
{{- end}} | ||
{{- end}} | ||
{{- end}} | ||
{{- if .TestParameters}} | ||
type args struct { | ||
{{- range .TestParameters}} | ||
{{Param .}} {{.Type}} | ||
{{- end}} | ||
} | ||
{{- end}} | ||
testCases := []struct { | ||
name string | ||
{{- with .Receiver}} | ||
{{- if and .IsStruct .Fields}} | ||
fields fields | ||
{{- else}} | ||
{{Receiver .}} {{.Type}} | ||
{{- end}} | ||
{{- end}} | ||
{{- if .TestParameters}} | ||
args args | ||
{{- end}} | ||
{{- range .TestResults}} | ||
{{Want .}} {{.Type}} | ||
{{- end}} | ||
{{- if .ReturnsError}} | ||
wantErr bool | ||
{{- end}} | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for {{if (or .Subtests (not .IsNaked))}} _, tt := {{end}} range testCases { | ||
{{- if .Subtests }}t.Run(tt.name, func(t *testing.T) { {{- end -}} | ||
{{- with .Receiver}} | ||
{{- if .IsStruct}} | ||
{{Receiver .}} := {{if .Type.IsStar}}&{{end}}{{.Type.Value}}{ | ||
{{- range .Fields}} | ||
{{.Name}}: tt.fields.{{Field .}}, | ||
{{- end}} | ||
} | ||
{{- end}} | ||
{{- end}} | ||
{{- range .Parameters}} | ||
{{- if .IsWriter}} | ||
{{Param .}} := &bytes.Buffer{} | ||
{{- end}} | ||
{{- end}} | ||
{{- if and (not .OnlyReturnsError) (not .OnlyReturnsOneValue) }} | ||
{{template "results" $f}} {{template "call" $f}} | ||
{{- end}} | ||
{{- if .ReturnsError}} | ||
if {{if .OnlyReturnsError}} err := {{template "call" $f}}; {{end}} (err != nil) != tt.wantErr { | ||
t.Errorf("{{template "message" $f}} error = %v, wantErr %v", {{template "inputs" $f}} err, tt.wantErr) | ||
{{- if .TestResults}} | ||
{{if .Subtests }}return{{else}}continue{{end}} | ||
{{- end}} | ||
} | ||
{{- end}} | ||
{{- range .TestResults}} | ||
{{- if .IsWriter}} | ||
if {{Got .}} := {{Param .}}.String(); {{Got .}} != tt.{{Want .}} { | ||
{{- else if .IsBasicType}} | ||
if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} {{Got .}} != tt.{{Want .}} { | ||
{{- else}} | ||
if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { | ||
{{- end}} | ||
t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) | ||
} | ||
{{- end}} | ||
{{- if .Subtests }} }) {{- end -}} | ||
} | ||
} | ||
|
||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{define "header"}} | ||
{{range .Comments}}{{.}} | ||
{{end}} | ||
package {{.Package}} | ||
|
||
import ( | ||
{{range .Imports}}{{.Name}} {{.Path}} | ||
{{end}} | ||
) | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{define "inline"}} {{template "call" .}} {{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{define "inputs"}}{{$f := .}}{{if not .Subtests}}tt.name, {{end}}{{if $f.PrintInputs}}{{range $f.Parameters}}tt.args.{{Param .}}, {{end}}{{end}}{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{define "message" -}} | ||
{{if not .Subtests}}%q. {{end}}{{with .Receiver}}{{.Type.Value}}.{{end}}{{.Name}}({{if .PrintInputs}}{{range $i, $el := .Parameters}}{{if $i}}, {{end}}%v{{end}}{{end}}) | ||
{{- end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{define "results"}} {{range $i, $el := .Results}}{{if $i}}, {{end}}{{Got .}}{{end}}{{if .ReturnsError}}, err{{end}} {{if or .Results .ReturnsError}} := {{end}} {{end}} |