From cec4af4cabb0ab2fb33dcc38ea56327b577587f2 Mon Sep 17 00:00:00 2001 From: Abdusalamov Arsen Date: Mon, 13 May 2019 18:45:30 +0300 Subject: [PATCH 1/7] use go-cmp instead of reflect.DeepEqual --- gotests.go | 19 ++++++++ gotests_test.go | 3 +- internal/render/bindata/esc.go | 43 ++++++++++--------- internal/render/templates/function.tmpl | 5 ++- testdata/goldens/custom_importer_fails.go | 13 +++--- testdata/goldens/existing_test_file.go | 13 +++--- ...tion_returning_two_results_and_an_error.go | 9 ++-- ...ction_with_channel_parameter_and_result.go | 9 ++-- ...ned_interface_type_parameter_and_result.go | 9 ++-- ...interface_receiver_parameter_and_result.go | 9 ++-- ...ed_struct_receiver_parameter_and_result.go | 9 ++-- ...ion_with_interface_parameter_and_result.go | 9 ++-- ...ction_with_map_argument_and_return_type.go | 9 ++-- .../goldens/function_with_named_imports.go | 9 ++-- ...ion_with_slice_argument_and_return_type.go | 9 ++-- ...struct_pointer_argument_and_return_type.go | 9 ++-- testdata/goldens/multiple_functions.go | 13 +++--- .../multiple_functions_excluding_on_method.go | 11 ++--- ...ultiple_functions_excluding_on_receiver.go | 11 ++--- .../multiple_functions_filtering_exported.go | 11 ++--- ..._functions_filtering_exported_with_only.go | 9 ++-- ...le_functions_with_case-insensitive_only.go | 11 ++--- .../goldens/multiple_functions_with_only.go | 11 ++--- testdata/goldens/multiple_named_results.go | 9 ++-- .../receiver_is_indirect_imported_struct.go | 2 +- ..._with_fields_with_complex_package_names.go | 9 ++-- ...ue_method_with_struct_value_return_type.go | 9 ++-- testdata/goldens/target_test_file.go | 7 +-- testdata/goldens/undefined_types.go | 9 ++-- 29 files changed, 177 insertions(+), 131 deletions(-) diff --git a/gotests.go b/gotests.go index 9a9b004..3843565 100644 --- a/gotests.go +++ b/gotests.go @@ -16,6 +16,13 @@ import ( "github.com/cweill/gotests/internal/output" ) +var ( + cmpImport = &models.Import{ + Name: "", + Path: `"github.com/google/go-cmp/cmp"`, + } +) + // Options provides custom filters and parameters for generating tests. type Options struct { Only *regexp.Regexp // Includes only functions that match. @@ -142,8 +149,20 @@ func parseTestFile(p *goparser.Parser, testPath string, h *models.Header) (*mode return nil, nil, fmt.Errorf("Parser.Parse test file: %v", err) } var testFuncs []string + cmpImportNeeded := false for _, fun := range tr.Funcs { testFuncs = append(testFuncs, fun.Name) + if cmpImportNeeded { + continue + } + for _, field := range fun.Parameters { + if !(field.IsWriter() || field.IsBasicType()) { + cmpImportNeeded = true + } + } + } + if cmpImportNeeded { + tr.Header.Imports = append(tr.Header.Imports, cmpImport) } tr.Header.Imports = append(tr.Header.Imports, h.Imports...) h = tr.Header diff --git a/gotests_test.go b/gotests_test.go index dde24cf..345804e 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -11,6 +11,7 @@ import ( "testing" "unicode" + "github.com/google/go-cmp/cmp" "golang.org/x/tools/imports" ) @@ -643,7 +644,7 @@ func TestGenerateTests(t *testing.T) { continue } if got := string(gts[0].Output); got != tt.want { - t.Errorf("%q. GenerateTests(%v) = \n%v, want \n%v", tt.name, tt.args.srcPath, got, tt.want) + t.Errorf("%q. GenerateTests(%v) = diff=%v", tt.name, tt.args.srcPath, cmp.Diff(got, tt.want)) outputResult(t, tmp, tt.name, gts[0].Output) } } diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index 78e11b3..0a46fd7 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -213,7 +213,7 @@ var _escData = map[string]*_escFile{ name: "call.tmpl", local: "templates/call.tmpl", size: 241, - modtime: 1540446832, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj @@ -224,22 +224,23 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= "/templates/function.tmpl": { name: "function.tmpl", local: "templates/function.tmpl", - size: 2392, - modtime: 1540483824, + size: 2541, + modtime: 1557758280, compressed: ` -H4sIAAAAAAAC/7RWTW/jNhA9S79i1sgupMJh7g58aJC06KFx4QTNoSgKRh65RGnKJUcJDIL/vSBFfVpO -c9kcImlIznvz5g0Ta3dYCoWwKGtVkKjUwrnU2mu4KmG1BuZcmvolsJY9o6FHfkDnMoIfCA0JtWfPOdg0 -8UfeBf0NbIsFijfUzqVJCIsS2C/miXRdUAh20Z8Eyp1pYgmdjghliIAJm33euFtztcfJgcTa8O1JBnqn -I8YlfwTVLn51mG1o8D559ax8mb9xzQ9IqANYoMb1fkRsQOv8RAAMoTN2A8QxvhfUeNH/+HMAo/gBPaxQ -+3h4RuaWO1e7XuuJXFHa5tEpIk2vWZvyXNAL4n0gWZIEvfyvmTMD3bZoakmmxXnhij6SrIPcItVamQet -q6jBO1f0oDW8VpWc6OyFvLmB5839ZgU/7nbgtYaCGzQstKGsNFgrSsgqDeypfm2akamKvKCP/B/c5blz -8NcSiHyTrA3JYynNdptC/GlZdpmcI7atVUbEfEeX4IdqOkYQOcN1L/tcty+M1VkPA83Qn9MRw2aunfsW -qUeF2e9c1uicbVNcmLbEWtZM/wqIWOMjNpjBZZ+gn71kZiDPPiLezAi1Zb5oQV31o9FareHb64nQsLu6 -LFHbzwDGUWnau1HyNHRTfh7fKAwq5dAxIzwcJSeEhW4cvICrMvi2Xym4lE34EosZGyeijF2bEnMOUOum -q3Mgt50pM7/vyxqUkLl/ErF2OmKbiYWUZbYY5jqgMXyPsRT0O2ANX9+W0B7/+rZYjuCFOtZd8aj1cgCW -945ob4nRuIe1yZjoULC1zc1UVIqEqjEWNuewDy11DnnJU0H1nyvqB6fzGHsK12+W3w62NKoOL6zed9Jg -xLjjRhSDP0xdc6/KOX/5oRxxGOoshcJpoz/N5zvhf9FYSiyI3SMeH/6tucy6DMsxoXzIqOveZ3zYEo5k -f60liaMckY18eq/+j1Evkrz8D8PEp+ALGl7XLnVp2vr0vwAAAP//X+Qs81gJAAA= +H4sIAAAAAAAC/7RWwW7jNhA9S18xayQLqfBy71n40MWmRQ/dFEnQPbRFwVhDl6hMueQogUHw3wtSlETJ +UpDL5hBbQw7fmzfzKFtboZAKYSNatSfZqI1zubUf4ErAzQ6Yc3nul8Ba9oiGvvIjOlcQ/EBoSKoDeyzB +5plPeZH0D7B73KN8Ru1cnoWwFMB+MQ+k2z2F4BD9SWJdmS6W0fmEIEIETNjsz427NVcHnCVk1oZnTzLQ +O58wLvkUVFV8GjD7UPJ99tWz8mX+xjU/IqEOYIEa14cJsYTWZUYADKELdgniFN8Larzof/yVwCh+RA8r +1SEmL8jcc+eqGrWeyRWl7T4GRWozatYfeSnoinivSJZlQS//byEn0e0eTVuT6XG+cUWvSTZA3iO1Wplb +rZuowQtXdKs1PDVNPdPZC/nxIzzefbm7gR+rCrzWsOcGDQttEI0Ga6WAotHAHtqnrhmFasgL+pX/i1VZ +Ogd/b4HIN8nacHgspdtuc4h/PcvhJOeI3beqIGK+o1vwpprbCCJn+DDKvtTtFVtd9DDQDP05nzBs5tq5 +95F6VJj9zusWnbP9EStuy6xlnftvgIh1c8QSD27HA0bvZQuGvHiIeAsW6sv8piUN1U+sdbOD909nQsM+ +t0Kgtm8BjFbp2nun6nM6TeVl/E5hUKmEgRnh8VRzQtjoboI3cCXC3I4re17XXXiNxcIYZ1LErs2JOQeo +ddfVJZBPw1AWft+7HShZl/6TiPXuiG0mFo4UxSY964jG8APGUtDvgB1cP2+hT79+3mwn8FKd2qF41Hqb +gJXjRPS3xMTuYW1mEx0Ktra7mfaNIqlajIUtTdirI3UJuTZTQfWfGxqNM8wYewjXb1F+SrZ0qqYX1jh3 +tcGI8ZkbuU9eTENzr8TSfHlTTjikOtdS4bzRb+bznfDf7Y8ndvtfy+tiyNxOiZQpk6Frb5m/nmgk+Wtb +kzzVE5KRxzijcP1srRc/eLgAf533rZ40xN/mf6pKCrELKf7ade614V4rMNSTXPpvQd6CF+6LFGJdt4FU +uf4rZmYe8Gqn7xCXuzzvzfN/AAAA//9kJyCm7QkAAA== `, }, @@ -247,7 +248,7 @@ f60liaMckY18eq/+j1Evkrz8D8PEp+ALGl7XLnVp2vr0vwAAAP//X+Qs81gJAAA= name: "header.tmpl", local: "templates/header.tmpl", size: 142, - modtime: 1540481163, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 @@ -259,7 +260,7 @@ jgAAAA== name: "inline.tmpl", local: "templates/inline.tmpl", size: 49, - modtime: 1540446006, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA //+q60H/MQAAAA== @@ -270,7 +271,7 @@ H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA name: "inputs.tmpl", local: "templates/inputs.tmpl", size: 152, - modtime: 1540446821, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/0yNMQoCQQxFrxKWLSUHEDyAneAJIptZptgomWz1yd1lRoupEh7/vw9sWqopLdU+Z7Ql E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ @@ -282,7 +283,7 @@ E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ name: "message.tmpl", local: "templates/message.tmpl", size: 201, - modtime: 1540446006, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 @@ -294,7 +295,7 @@ ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 name: "results.tmpl", local: "templates/results.tmpl", size: 168, - modtime: 1540446006, + modtime: 1533199207, compressed: ` H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ diff --git a/internal/render/templates/function.tmpl b/internal/render/templates/function.tmpl index f16cf48..a2c2386 100644 --- a/internal/render/templates/function.tmpl +++ b/internal/render/templates/function.tmpl @@ -74,9 +74,10 @@ func {{.TestName}}(t *testing.T) { {{- 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 .}}) { + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/goldens/custom_importer_fails.go b/testdata/goldens/custom_importer_fails.go index 71296f3..799ebea 100644 --- a/testdata/goldens/custom_importer_fails.go +++ b/testdata/goldens/custom_importer_fails.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -39,7 +40,7 @@ func TestBar_BarFilter(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { b := &Bar{} @@ -58,7 +59,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/existing_test_file.go b/testdata/goldens/existing_test_file.go index f671f3e..49b2013 100644 --- a/testdata/goldens/existing_test_file.go +++ b/testdata/goldens/existing_test_file.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestBarBar100(t *testing.T) { @@ -55,7 +56,7 @@ func TestFoo100(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := Foo100(tt.args.strs) @@ -63,8 +64,8 @@ func TestFoo100(t *testing.T) { t.Errorf("%q. Foo100() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo100() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo100() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -79,7 +80,7 @@ func TestBar_Bar100(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { b := &Bar{} @@ -98,7 +99,7 @@ func Test_baz100(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := baz100(tt.args.f); got != tt.want { diff --git a/testdata/goldens/function_returning_two_results_and_an_error.go b/testdata/goldens/function_returning_two_results_and_an_error.go index b84dd96..a84d732 100644 --- a/testdata/goldens/function_returning_two_results_and_an_error.go +++ b/testdata/goldens/function_returning_two_results_and_an_error.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo25(t *testing.T) { @@ -16,7 +17,7 @@ func TestFoo25(t *testing.T) { want1 []byte wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, got1, err := Foo25(tt.args.in0) @@ -27,8 +28,8 @@ func TestFoo25(t *testing.T) { if got != tt.want { t.Errorf("%q. Foo25() got = %v, want %v", tt.name, got, tt.want) } - if !reflect.DeepEqual(got1, tt.want1) { - t.Errorf("%q. Foo25() got1 = %v, want %v", tt.name, got1, tt.want1) + if !cmp.Equal(got1, tt.want1) { + t.Errorf("%q. Foo25() got1 = %v, want %v\ndiff=%v", tt.name, got1, tt.want1, cmp.Diff(got1, tt.want1)) } } } diff --git a/testdata/goldens/function_with_channel_parameter_and_result.go b/testdata/goldens/function_with_channel_parameter_and_result.go index 7b92e06..b86cec9 100644 --- a/testdata/goldens/function_with_channel_parameter_and_result.go +++ b/testdata/goldens/function_with_channel_parameter_and_result.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo23(t *testing.T) { @@ -14,11 +15,11 @@ func TestFoo23(t *testing.T) { args args want chan string }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo23(tt.args.ch); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo23() = %v, want %v", tt.name, got, tt.want) + if got := Foo23(tt.args.ch); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo23() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go index e7a0119..f32b670 100644 --- a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go +++ b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo16(t *testing.T) { @@ -14,11 +15,11 @@ func TestFoo16(t *testing.T) { args args want Bazzar }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo16(tt.args.in); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo16() = %v, want %v", tt.name, got, tt.want) + if got := Foo16(tt.args.in); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo16() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go index a90c8a2..d440f09 100644 --- a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go @@ -2,8 +2,9 @@ package testdata import ( "io" - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo17(t *testing.T) { @@ -15,11 +16,11 @@ func TestFoo17(t *testing.T) { args args want io.Reader }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo17(tt.args.r); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo17() = %v, want %v", tt.name, got, tt.want) + if got := Foo17(tt.args.r); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo17() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go index 7b55770..6b5cf29 100644 --- a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go @@ -2,8 +2,9 @@ package testdata import ( "os" - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo18(t *testing.T) { @@ -15,11 +16,11 @@ func TestFoo18(t *testing.T) { args args want *os.File }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo18(tt.args.t); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo18() = %v, want %v", tt.name, got, tt.want) + if got := Foo18(tt.args.t); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo18() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_interface_parameter_and_result.go b/testdata/goldens/function_with_interface_parameter_and_result.go index f3c0700..8774769 100644 --- a/testdata/goldens/function_with_interface_parameter_and_result.go +++ b/testdata/goldens/function_with_interface_parameter_and_result.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo21(t *testing.T) { @@ -14,11 +15,11 @@ func TestFoo21(t *testing.T) { args args want interface{} }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo21(tt.args.i); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo21() = %v, want %v", tt.name, got, tt.want) + if got := Foo21(tt.args.i); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo21() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_map_argument_and_return_type.go b/testdata/goldens/function_with_map_argument_and_return_type.go index 0bd44df..605ac3a 100644 --- a/testdata/goldens/function_with_map_argument_and_return_type.go +++ b/testdata/goldens/function_with_map_argument_and_return_type.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo10(t *testing.T) { @@ -14,11 +15,11 @@ func TestFoo10(t *testing.T) { args args want map[string]*Bar }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo10(tt.args.m); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo10() = %v, want %v", tt.name, got, tt.want) + if got := Foo10(tt.args.m); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo10() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_named_imports.go b/testdata/goldens/function_with_named_imports.go index a9d15c1..bfdeaea 100644 --- a/testdata/goldens/function_with_named_imports.go +++ b/testdata/goldens/function_with_named_imports.go @@ -2,8 +2,9 @@ package testdata import ( ht "html/template" - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo22(t *testing.T) { @@ -15,11 +16,11 @@ func TestFoo22(t *testing.T) { args args want *ht.Template }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { - if got := Foo22(tt.args.t); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo22() = %v, want %v", tt.name, got, tt.want) + if got := Foo22(tt.args.t); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo22() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_slice_argument_and_return_type.go b/testdata/goldens/function_with_slice_argument_and_return_type.go index ec947ee..e755234 100644 --- a/testdata/goldens/function_with_slice_argument_and_return_type.go +++ b/testdata/goldens/function_with_slice_argument_and_return_type.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo11(t *testing.T) { @@ -15,7 +16,7 @@ func TestFoo11(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := Foo11(tt.args.strs) @@ -23,8 +24,8 @@ func TestFoo11(t *testing.T) { t.Errorf("%q. Foo11() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo11() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo11() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go index 5f0d47b..0d181c8 100644 --- a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go +++ b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo8(t *testing.T) { @@ -15,7 +16,7 @@ func TestFoo8(t *testing.T) { want *Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := Foo8(tt.args.b) @@ -23,8 +24,8 @@ func TestFoo8(t *testing.T) { t.Errorf("%q. Foo8() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Foo8() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. Foo8() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions.go b/testdata/goldens/multiple_functions.go index 71296f3..799ebea 100644 --- a/testdata/goldens/multiple_functions.go +++ b/testdata/goldens/multiple_functions.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -39,7 +40,7 @@ func TestBar_BarFilter(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { b := &Bar{} @@ -58,7 +59,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/multiple_functions_excluding_on_method.go b/testdata/goldens/multiple_functions_excluding_on_method.go index 139e895..f1861b5 100644 --- a/testdata/goldens/multiple_functions_excluding_on_method.go +++ b/testdata/goldens/multiple_functions_excluding_on_method.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -38,7 +39,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/multiple_functions_excluding_on_receiver.go b/testdata/goldens/multiple_functions_excluding_on_receiver.go index 139e895..f1861b5 100644 --- a/testdata/goldens/multiple_functions_excluding_on_receiver.go +++ b/testdata/goldens/multiple_functions_excluding_on_receiver.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -38,7 +39,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/multiple_functions_filtering_exported.go b/testdata/goldens/multiple_functions_filtering_exported.go index d0d2654..575b420 100644 --- a/testdata/goldens/multiple_functions_filtering_exported.go +++ b/testdata/goldens/multiple_functions_filtering_exported.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -39,7 +40,7 @@ func TestBar_BarFilter(t *testing.T) { args args wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { b := &Bar{} diff --git a/testdata/goldens/multiple_functions_filtering_exported_with_only.go b/testdata/goldens/multiple_functions_filtering_exported_with_only.go index 588df3f..89a43e4 100644 --- a/testdata/goldens/multiple_functions_filtering_exported_with_only.go +++ b/testdata/goldens/multiple_functions_filtering_exported_with_only.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_with_case-insensitive_only.go b/testdata/goldens/multiple_functions_with_case-insensitive_only.go index 139e895..f1861b5 100644 --- a/testdata/goldens/multiple_functions_with_case-insensitive_only.go +++ b/testdata/goldens/multiple_functions_with_case-insensitive_only.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -38,7 +39,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/multiple_functions_with_only.go b/testdata/goldens/multiple_functions_with_only.go index 139e895..f1861b5 100644 --- a/testdata/goldens/multiple_functions_with_only.go +++ b/testdata/goldens/multiple_functions_with_only.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -15,7 +16,7 @@ func TestFooFilter(t *testing.T) { want []*Bar wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := FooFilter(tt.args.strs) @@ -23,8 +24,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } @@ -38,7 +39,7 @@ func Test_bazFilter(t *testing.T) { args args want float64 }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { if got := bazFilter(tt.args.f); got != tt.want { diff --git a/testdata/goldens/multiple_named_results.go b/testdata/goldens/multiple_named_results.go index 871aeea..72ae6ac 100644 --- a/testdata/goldens/multiple_named_results.go +++ b/testdata/goldens/multiple_named_results.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestFoo26(t *testing.T) { @@ -17,7 +18,7 @@ func TestFoo26(t *testing.T) { want2 []byte wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, gotI, got2, err := Foo26(tt.args.v) @@ -31,8 +32,8 @@ func TestFoo26(t *testing.T) { if gotI != tt.wantI { t.Errorf("%q. Foo26() gotI = %v, want %v", tt.name, gotI, tt.wantI) } - if !reflect.DeepEqual(got2, tt.want2) { - t.Errorf("%q. Foo26() got2 = %v, want %v", tt.name, got2, tt.want2) + if !cmp.Equal(got2, tt.want2) { + t.Errorf("%q. Foo26() got2 = %v, want %v\ndiff=%v", tt.name, got2, tt.want2, cmp.Diff(got2, tt.want2)) } } } diff --git a/testdata/goldens/receiver_is_indirect_imported_struct.go b/testdata/goldens/receiver_is_indirect_imported_struct.go index a831c34..ab67532 100644 --- a/testdata/goldens/receiver_is_indirect_imported_struct.go +++ b/testdata/goldens/receiver_is_indirect_imported_struct.go @@ -7,7 +7,7 @@ func Test_someIndirectImportedStruct_Foo037(t *testing.T) { name string smtg *someIndirectImportedStruct }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { smtg := &someIndirectImportedStruct{} diff --git a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go index 2c54ac7..f02462b 100644 --- a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go +++ b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go @@ -2,8 +2,9 @@ package testdata import ( "go/types" - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestImporter_Foo35(t *testing.T) { @@ -20,15 +21,15 @@ func TestImporter_Foo35(t *testing.T) { args args want *types.Var }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { i := &Importer{ Importer: tt.fields.Importer, Field: tt.fields.Field, } - if got := i.Foo35(tt.args.t); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Importer.Foo35() = %v, want %v", tt.name, got, tt.want) + if got := i.Foo35(tt.args.t); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Importer.Foo35() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/struct_value_method_with_struct_value_return_type.go b/testdata/goldens/struct_value_method_with_struct_value_return_type.go index 52d994a..f2ba931 100644 --- a/testdata/goldens/struct_value_method_with_struct_value_return_type.go +++ b/testdata/goldens/struct_value_method_with_struct_value_return_type.go @@ -1,8 +1,9 @@ package testdata import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestBar_Foo9(t *testing.T) { @@ -11,12 +12,12 @@ func TestBar_Foo9(t *testing.T) { b Bar want Bar }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { b := Bar{} - if got := b.Foo9(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Bar.Foo9() = %v, want %v", tt.name, got, tt.want) + if got := b.Foo9(); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Bar.Foo9() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/target_test_file.go b/testdata/goldens/target_test_file.go index 74fb6fb..996fe09 100644 --- a/testdata/goldens/target_test_file.go +++ b/testdata/goldens/target_test_file.go @@ -2,8 +2,9 @@ package testdata import ( "fmt" - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestBarBar100(t *testing.T) { @@ -67,8 +68,8 @@ func Test_wrapToString(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := wrapToString(tt.args.in); !reflect.DeepEqual(got, tt.want) { - t.Errorf("wrapToString() = %v, want %v", got, tt.want) + if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { + t.Errorf("wrapToString() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/testdata/goldens/undefined_types.go b/testdata/goldens/undefined_types.go index e792b1c..495f861 100644 --- a/testdata/goldens/undefined_types.go +++ b/testdata/goldens/undefined_types.go @@ -1,8 +1,9 @@ package undefinedtypes import ( - "reflect" "testing" + + "github.com/google/go-cmp/cmp" ) func TestUndefined_Do(t *testing.T) { @@ -16,7 +17,7 @@ func TestUndefined_Do(t *testing.T) { want *Unknown wantErr bool }{ - // TODO: Add test cases. + // TODO: Add test cases. } for _, tt := range tests { got, err := tt.u.Do(tt.args.es) @@ -24,8 +25,8 @@ func TestUndefined_Do(t *testing.T) { t.Errorf("%q. Undefined.Do() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("%q. Undefined.Do() = %v, want %v", tt.name, got, tt.want) + if !cmp.Equal(got, tt.want) { + t.Errorf("%q. Undefined.Do() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } From 7c6e3ac9028bd04f2941b581876e8798a111c481 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Wed, 24 Mar 2021 23:08:20 +0100 Subject: [PATCH 2/7] Fix tests --- .github/workflows/go.yml | 3 + go.mod | 2 +- gotests/main_test.go | 6 +- gotests/process/process_test.go | 6 +- gotests_test.go | 3 +- internal/output/output_test.go | 18 +++-- internal/render/bindata/esc.go | 44 +++++------ testdata/bad_customtemplates/function.tmpl | 5 +- testdata/customtemplates/function.tmpl | 5 +- .../target_test_file_without_only_flag.go | 76 +++++++++++++++++++ testdata/templatedata/function.tmpl | 5 +- testdata/use_template_params/function.tmpl | 5 +- 12 files changed, 135 insertions(+), 43 deletions(-) create mode 100644 testdata/goldens/target_test_file_without_only_flag.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f5ac7ae..3f1b9d5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -35,6 +35,9 @@ jobs: - name: Get Dependencies (github.com/golang.org/x/tools/imports) run: go get -v ./... + - name: Get go-cmp + run: go get github.com/google/go-cmp/cmp + - name: Test run: | go test -v ./... diff --git a/go.mod b/go.mod index 75e5b69..785a004 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/cweill/gotests require ( - github.com/google/go-cmp v0.5.5 // indirect + github.com/google/go-cmp v0.5.5 golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 ) diff --git a/gotests/main_test.go b/gotests/main_test.go index d6de618..4c5e017 100644 --- a/gotests/main_test.go +++ b/gotests/main_test.go @@ -3,6 +3,8 @@ package main import ( "os" "testing" + + "github.com/google/go-cmp/cmp" ) func Test_valOrGetenv(t *testing.T) { @@ -65,8 +67,8 @@ func Test_valOrGetenv(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := valOrGetenv(tt.args.val, tt.args.key); got != tt.want { - t.Errorf("valOrGetenv() = %v, want %v", got, tt.want) + if got := valOrGetenv(tt.args.val, tt.args.key); !cmp.Equal(got, tt.want) { + t.Errorf("valOrGetenv() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/gotests/process/process_test.go b/gotests/process/process_test.go index 5f529fd..f7562e8 100644 --- a/gotests/process/process_test.go +++ b/gotests/process/process_test.go @@ -3,6 +3,8 @@ package process import ( "bytes" "testing" + + "github.com/google/go-cmp/cmp" ) func TestRun(t *testing.T) { @@ -53,8 +55,8 @@ func TestRun(t *testing.T) { for _, tt := range tests { out := &bytes.Buffer{} Run(out, tt.args, tt.opts) - if got := out.String(); got != tt.want { - t.Errorf("%q. Run() =\n%v, want\n%v", tt.name, got, tt.want) + if got := out.String(); !cmp.Equal(got, tt.want) { + t.Errorf("%q. Run() =\n%v, want\n%v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/gotests_test.go b/gotests_test.go index a825152..3326bea 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -13,6 +13,7 @@ import ( "testing" "unicode" + "github.com/google/go-cmp/cmp" "golang.org/x/tools/imports" ) @@ -858,7 +859,7 @@ func TestGenerateTests(t *testing.T) { return } if got := string(gts[0].Output); got != tt.want { - t.Errorf("%q. GenerateTests(%v) = \n%v, want \n%v", tt.name, tt.args.srcPath, got, tt.want) + t.Errorf("%q. GenerateTests(%v) = diff=%v", tt.name, tt.args.srcPath, cmp.Diff(got, tt.want)) outputResult(t, tmp, tt.name, gts[0].Output) } }) diff --git a/internal/output/output_test.go b/internal/output/output_test.go index 909f6f2..487f091 100644 --- a/internal/output/output_test.go +++ b/internal/output/output_test.go @@ -1,6 +1,10 @@ package output -import "testing" +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) func TestOptions_providesTemplateData(t *testing.T) { tests := []struct { @@ -16,8 +20,8 @@ func TestOptions_providesTemplateData(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplateData(); got != tt.want { - t.Errorf("Options.isProvidesTemplateData() = %v, want %v", got, tt.want) + if got := tt.otpions.providesTemplateData(); !cmp.Equal(got, tt.want) { + t.Errorf("Options.isProvidesTemplateData() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) } }) } @@ -36,8 +40,8 @@ func TestOptions_providesTemplate(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplate(); got != tt.want { - t.Errorf("Options.isProvidesTemplate() = %v, want %v", got, tt.want) + if got := tt.otpions.providesTemplate(); !cmp.Equal(got, tt.want) { + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) } }) } @@ -56,8 +60,8 @@ func TestOptions_providesTemplateDir(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplateDir(); got != tt.want { - t.Errorf("Options.isProvidesTemplate() = %v, want %v", got, tt.want) + if got := tt.otpions.providesTemplateDir(); !cmp.Equal(got, tt.want) { + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index 3c92ce1..eae2a0e 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -213,7 +213,7 @@ var _escData = map[string]*_escFile{ name: "call.tmpl", local: "templates/call.tmpl", size: 241, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj @@ -224,23 +224,23 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= "/templates/function.tmpl": { name: "function.tmpl", local: "templates/function.tmpl", - size: 2465, - modtime: 1583006961, + size: 2614, + modtime: 1616493590, compressed: ` -H4sIAAAAAAAC/7RWwY7bNhA9S18xMTaBVDjM3YEPDbItemhceBfNoSgKrjxyidKUS442MAj+e0GKkihb -2uylF1sakvPevJlH29oD1kIhrOpWVSQatXIut/Y93NWw2QJzLs/9EljLHtHQF35C5wqCHwgNCXVkjyXY -PPNHvgn6G9geKxTPqJ3LsxAWNbBfzAPptqIQHKI/CZQH08UyupwR6hABEzb7vHG35uqIVwcya8O7Jxno -Xc4Yl/wRVIf4NmD2oeT56tGz8mX+xjU/IaEOYIEa18cJsYTW7YkAGEI37BLEKb4X1HjR//gzgVH8hB5W -qGM8PCNzz52rw6j1lVxR2u5rUESaUbM+5a2gC+K9IFmWBb38x8yZRLc9mlaS6XG+ckUvSTZA7pFarcy9 -1k3U4BtXdK81PDWNvNLZC/nhAzzuPu828OPhAF5rqLhBw0Ib6kaDtaKGotHAHtqnrhmFasgL+oX/g4ey -dA7+WgORb5K1IXkspdtuE359jglpr5GUKJ3rkhDFNHmWEdu3qiBivuNr8Ka7tdlsquG5KMd0Ewssjc2C -P2+GIdQbGn05Y9jMtXPvIlpsFfudyxads32KBdtm1rLuGtkAEesGkiVmXo8JRhNnM86+eYl4M17sy/yq -BQ3VTzy62cK7pwuhYZ/aukZtXwMYPdfNyU7JSzqW5W18pzCoVMLAjPB0lpwQVrqzwgru6mCAcaXiUnbh -JRYzfshEHbt2Tcw5QK27rs6BfBymu/D73mxBCVn6byLW2yy2mVhIWRerNNcJjeFHjKWg3wFbePu8hv74 -2+fVegIv1Lkdiket1wlYOU5Ef91M7o2wlroOnNOhYGu7K65qFAnV4miQ7/9MvHhVLc5UUP3nhkbjDDPG -HsI9XpQfky2dqunNN86dNBgxPnEjquQXbmjuXT03X96UEw6pzlIovG70q/n8T/hvNNYSK2KfEc/3/7Zc -FkOG9ZRQmTIauveaOewJR7K/tpLEWU7IRj7jrH5nUBdJLv/zuJpT8AV1W+B996/A5Xk/p/8FAAD//5Yq -M1yhCQAA +H4sIAAAAAAAC/7RWwW7jNhA9y18xayQLqfBy71n40MWmRQ/dFEnQPbRFwVhDlyhNueQogUHw3wtSlETZ +UppLL7ZEcea9eTOPknM1CqkR1qLVO5KNXnu/cu4DXAm42QLzfrUKj8A59oiWvvIDel8SfEdoSeo9e6zA +rYoQ8iLpL2D3uEP5jMb7VRGXpQD2k30g0+4oLg6rP0hUte3WCjodEURcARs3h7xpt+F6j2cBhXPxPpCM +9E5HTI9CCOo63Q2Y/VJ2fXYZWIUyf+GGH5DQRLBIjZv9hFhG6zIiAsalC3YZ4hQ/CGqD6L/9kcFofsAA +K/U+Bc/I3HPnuh61PpMrSdv9DYooO2rWp7wUdEG8VyQriqhX+JmJyXS7R9sqsj3ON67pNckGyHuk1mh7 +a0yTNHjhmm6NgaemUWc6ByE/foTHuy93N/B9XUPQGnbcomWxDaIx4JwUUDYG2EP71DWj1A0FQb/yv7Gu +Ku/hzw0QhSY5F5OnUrrtLuPX55iQDhophcr7LglRSrMqCmL3rS6JWOj4BoLpLm02m2q4Lqsx3cQCS2Oz +4M+LYYj1xkafjhg3c+P9+4SWWsV+5apF712fYsG2hXOsO0ZugIh1A8kyM2/GBKOJixlnX9wkvBkv9mV+ +M5KG6icevdnC+6cToWWfWyHQuLcAJs91c3Kn1Skfy+py/U5jVKmCgRnh4ag4IaxNZ4U1XIlogPHJjivV +LS+xmPFDIUXq2jkx7wGN6bo6B/JpmO4y7Hu3BS1VFf6JWG+z1GZiMaUo13muA1rL95hKwbADtnD9vIE+ +/Pp5vZnAS31sh+LRmE0GVo0T0R83k3MjPstdB96bWLBz3RG3azRJ3eJokP9+Tbx6VC3OVFT9x4ZG4wwz +xh7iOV5Wn7Itnar5yTfOnbKYMD5zK3fZG25o7pWYm69gygmHXGclNZ43+s18/if8d7vDkd3+03JVDpGb +KZEqZzJ07S3z1xNNJH9uFcmjmpBMPMYZhetn54L40cMlhPdC3+pJQ8Jr4XddSyG2MQR1Dd6/NtxLBcZ6 +AADSaL0FeQNBuC9SiGXdBlLV8ufQmXkgqN1tgQ/dp4pfrXrz/BsAAP//ilnoujYKAAA= `, }, @@ -248,7 +248,7 @@ M1yhCQAA name: "header.tmpl", local: "templates/header.tmpl", size: 142, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 @@ -260,7 +260,7 @@ jgAAAA== name: "inline.tmpl", local: "templates/inline.tmpl", size: 49, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA //+q60H/MQAAAA== @@ -271,7 +271,7 @@ H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA name: "inputs.tmpl", local: "templates/inputs.tmpl", size: 152, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/0yNMQoCQQxFrxKWLSUHEDyAneAJIptZptgomWz1yd1lRoupEh7/vw9sWqopLdU+Z7Ql E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ @@ -283,7 +283,7 @@ E1gLXW/E/a2F7B3Ez/MV2qJlRrDJoRcC1LZ/Zi388GpxH5IOXWzXwcXl0FD/dcX3xsCgfWLyzOcbAAD/ name: "message.tmpl", local: "templates/message.tmpl", size: 201, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 @@ -295,7 +295,7 @@ ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 name: "results.tmpl", local: "templates/results.tmpl", size: 168, - modtime: 1580496706, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index 1fe3a85..87ab7c7 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -74,9 +74,10 @@ func {{.TestName}}(t *testing.T) { {{- 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 .}}) { + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index 1fe3a85..87ab7c7 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -74,9 +74,10 @@ func {{.TestName}}(t *testing.T) { {{- 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 .}}) { + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/goldens/target_test_file_without_only_flag.go b/testdata/goldens/target_test_file_without_only_flag.go new file mode 100644 index 0000000..996fe09 --- /dev/null +++ b/testdata/goldens/target_test_file_without_only_flag.go @@ -0,0 +1,76 @@ +package testdata + +import ( + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBarBar100(t *testing.T) { + tests := []struct { + name string + b *Bar + i interface{} + wantErr bool + }{ + { + name: "Basic test", + b: &Bar{}, + wantErr: true, + }, + } + for _, tt := range tests { + if err := tt.b.Bar100(tt.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func TestBaz100(t *testing.T) { + tests := []struct { + name string + f *float64 + want float64 + }{ + { + name: "Basic test", + f: func() *float64 { var x float64 = 64; return &x }(), + want: 64, + }, + } + // TestBaz100 contains a comment. + for _, tt := range tests { + if got := baz100(tt.f); got != tt.want { + t.Errorf("%q. baz100() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func wrapToString(in []int) []string { + var result []string + for _, x := range in { + result = append(result, fmt.Sprintf("%v", x)) + } + return result +} + +func Test_wrapToString(t *testing.T) { + type args struct { + in []int + } + tests := []struct { + name string + args args + want []string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { + t.Errorf("wrapToString() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + } + }) + } +} diff --git a/testdata/templatedata/function.tmpl b/testdata/templatedata/function.tmpl index 1fe3a85..87ab7c7 100644 --- a/testdata/templatedata/function.tmpl +++ b/testdata/templatedata/function.tmpl @@ -74,9 +74,10 @@ func {{.TestName}}(t *testing.T) { {{- 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 .}}) { + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/use_template_params/function.tmpl b/testdata/use_template_params/function.tmpl index abfb501..2b37328 100644 --- a/testdata/use_template_params/function.tmpl +++ b/testdata/use_template_params/function.tmpl @@ -75,9 +75,10 @@ func {{.TestName}}(t *testing.T) { {{- 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 .}}) { + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} From 0a209c7c7885cab45126d8ee675a76b6bd312fd6 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Mon, 29 Mar 2021 19:35:35 +0200 Subject: [PATCH 3/7] Fix PR comments --- go.sum | 1 + gotests.go | 10 ++++------ gotests/main_test.go | 2 +- gotests/process/process_test.go | 2 +- gotests_test.go | 2 +- internal/output/output_test.go | 6 +++--- internal/render/bindata/esc.go | 6 +++--- internal/render/templates/function.tmpl | 2 +- testdata/bad_customtemplates/function.tmpl | 2 +- testdata/customtemplates/function.tmpl | 2 +- testdata/goldens/custom_importer_fails.go | 2 +- testdata/goldens/existing_test_file.go | 2 +- .../function_returning_two_results_and_an_error.go | 2 +- .../function_with_channel_parameter_and_result.go | 2 +- ...with_defined_interface_type_parameter_and_result.go | 2 +- ...imported_interface_receiver_parameter_and_result.go | 2 +- ...th_imported_struct_receiver_parameter_and_result.go | 2 +- .../function_with_interface_parameter_and_result.go | 2 +- .../function_with_map_argument_and_return_type.go | 2 +- testdata/goldens/function_with_named_imports.go | 2 +- .../function_with_slice_argument_and_return_type.go | 2 +- ...ion_with_struct_pointer_argument_and_return_type.go | 2 +- testdata/goldens/multiple_functions.go | 2 +- .../goldens/multiple_functions_excluding_on_method.go | 2 +- .../multiple_functions_excluding_on_receiver.go | 2 +- .../goldens/multiple_functions_filtering_exported.go | 2 +- .../multiple_functions_filtering_exported_with_only.go | 2 +- .../multiple_functions_with_case-insensitive_only.go | 2 +- testdata/goldens/multiple_functions_with_only.go | 2 +- testdata/goldens/multiple_named_results.go | 2 +- ...er_struct_with_fields_with_complex_package_names.go | 2 +- ...truct_value_method_with_struct_value_return_type.go | 2 +- testdata/goldens/target_test_file.go | 2 +- testdata/goldens/target_test_file_without_only_flag.go | 2 +- testdata/goldens/undefined_types.go | 2 +- testdata/templatedata/function.tmpl | 2 +- testdata/use_template_params/function.tmpl | 2 +- 37 files changed, 44 insertions(+), 45 deletions(-) diff --git a/go.sum b/go.sum index fa6692d..35a0057 100644 --- a/go.sum +++ b/go.sum @@ -8,4 +8,5 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 h1:LCmXVkvpQCDj724eX6irUTPCJP5GelFHxqGSWL2D1R0= golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/gotests.go b/gotests.go index 0122637..7def4fb 100644 --- a/gotests.go +++ b/gotests.go @@ -16,12 +16,10 @@ import ( "github.com/cweill/gotests/internal/output" ) -var ( - cmpImport = &models.Import{ - Name: "", - Path: `"github.com/google/go-cmp/cmp"`, - } -) +var cmpImport = &models.Import{ + Name: "", + Path: `"github.com/google/go-cmp/cmp"`, +} // Options provides custom filters and parameters for generating tests. type Options struct { diff --git a/gotests/main_test.go b/gotests/main_test.go index 4c5e017..0c8dd28 100644 --- a/gotests/main_test.go +++ b/gotests/main_test.go @@ -68,7 +68,7 @@ func Test_valOrGetenv(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := valOrGetenv(tt.args.val, tt.args.key); !cmp.Equal(got, tt.want) { - t.Errorf("valOrGetenv() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("valOrGetenv() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/gotests/process/process_test.go b/gotests/process/process_test.go index f7562e8..0046e5f 100644 --- a/gotests/process/process_test.go +++ b/gotests/process/process_test.go @@ -56,7 +56,7 @@ func TestRun(t *testing.T) { out := &bytes.Buffer{} Run(out, tt.args, tt.opts) if got := out.String(); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Run() =\n%v, want\n%v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Run() =\n%v, want\n%v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/gotests_test.go b/gotests_test.go index df3bda0..042f438 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -919,7 +919,7 @@ func TestGenerateTests(t *testing.T) { return } if got := string(gts[0].Output); got != tt.want { - t.Errorf("%q. GenerateTests(%v) = diff=%v", tt.name, tt.args.srcPath, cmp.Diff(got, tt.want)) + t.Errorf("%q. GenerateTests(%v) = diff=%s", tt.name, tt.args.srcPath, cmp.Diff(got, tt.want)) outputResult(t, tmp, tt.name, gts[0].Output) } }) diff --git a/internal/output/output_test.go b/internal/output/output_test.go index 487f091..055b26d 100644 --- a/internal/output/output_test.go +++ b/internal/output/output_test.go @@ -21,7 +21,7 @@ func TestOptions_providesTemplateData(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.otpions.providesTemplateData(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplateData() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("Options.isProvidesTemplateData() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } @@ -41,7 +41,7 @@ func TestOptions_providesTemplate(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.otpions.providesTemplate(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } @@ -61,7 +61,7 @@ func TestOptions_providesTemplateDir(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.otpions.providesTemplateDir(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index 7975c72..c2d010e 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -225,7 +225,7 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= name: "function.tmpl", local: "templates/function.tmpl", size: 2806, - modtime: 1616881472, + modtime: 1617038490, compressed: ` H4sIAAAAAAAC/7RWTW/jNhA9y79i1kgWUuHl3hP40MWmxR66KZKge9gWBWONXKI05ZKjBAbB/17wQxJl W6kvvdgixZl5897MUNbW2AiFsGw6tSHRqqVzC2s/wFUDN2tgzi0W/hVYy57Q0Fe+Q+dKgh8IDQm1ZU8V @@ -240,8 +240,8 @@ Q/aTGXOzhvfPB0LDPnVNg9peEjCVQSzPeyUPeTdUp/v3CgNLFQzICHd7yQlhqWMHLuGqCQU+vtlwKeP2 HIozbViIJql2DMw5QK2jqueC3A5NU/pz79aghKz8PxHruzvJTCy4bMpl7muHxvAtplTQn4A1XL+soDe/ flmuJuGF2ndD8qj1KgtWjRXRT7nJuArv8mYG53RIuG+vTatIqA7HBvnva+7NCTlbU4H1n1saG2eoMfYY bpGyus2ORFbzgTvWnTSYYnziRmyyG3oQ96o5V1++KScYcp6lUHgs9MV4/qf47za7Pbv7p+OyHCxXUyBV -jmRQ7ZL664EmkL90ksReTkAmHGONwvVL9jFQgr+Oeqkngvjb6HdVi6ZZB5M48N8q7rkEQz4AAKm0Lom8 -Ak/cZ9E087wNoKr5z7mj5gHPdjwCH+Knllss+ub5NwAA//+j/OyD9goAAA== +jmRQ7ZL664EmkL90ksReTkAmHGONwvVL9jFQgr+Oeqkngvjb6HdVi6ZZX5th4L9V3HMJhnwAAFJpXRJ5 +BZ64z6Jp5nkbQFXzn3NHzQOe7XgEPsRPLbdY9M3zbwAAAP//vowfufYKAAA= `, }, diff --git a/internal/render/templates/function.tmpl b/internal/render/templates/function.tmpl index 5da1728..f31c7bc 100644 --- a/internal/render/templates/function.tmpl +++ b/internal/render/templates/function.tmpl @@ -81,7 +81,7 @@ func {{.TestName}}(t *testing.T) { {{- else}} if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index 87ab7c7..91f9d5b 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -76,7 +76,7 @@ func {{.TestName}}(t *testing.T) { {{- else}} if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index 87ab7c7..91f9d5b 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -76,7 +76,7 @@ func {{.TestName}}(t *testing.T) { {{- else}} if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} diff --git a/testdata/goldens/custom_importer_fails.go b/testdata/goldens/custom_importer_fails.go index 799ebea..99863e4 100644 --- a/testdata/goldens/custom_importer_fails.go +++ b/testdata/goldens/custom_importer_fails.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/existing_test_file.go b/testdata/goldens/existing_test_file.go index 49b2013..78a4599 100644 --- a/testdata/goldens/existing_test_file.go +++ b/testdata/goldens/existing_test_file.go @@ -65,7 +65,7 @@ func TestFoo100(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo100() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo100() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_returning_two_results_and_an_error.go b/testdata/goldens/function_returning_two_results_and_an_error.go index a84d732..bcd0476 100644 --- a/testdata/goldens/function_returning_two_results_and_an_error.go +++ b/testdata/goldens/function_returning_two_results_and_an_error.go @@ -29,7 +29,7 @@ func TestFoo25(t *testing.T) { t.Errorf("%q. Foo25() got = %v, want %v", tt.name, got, tt.want) } if !cmp.Equal(got1, tt.want1) { - t.Errorf("%q. Foo25() got1 = %v, want %v\ndiff=%v", tt.name, got1, tt.want1, cmp.Diff(got1, tt.want1)) + t.Errorf("%q. Foo25() got1 = %v, want %v\ndiff=%s", tt.name, got1, tt.want1, cmp.Diff(got1, tt.want1)) } } } diff --git a/testdata/goldens/function_with_channel_parameter_and_result.go b/testdata/goldens/function_with_channel_parameter_and_result.go index b86cec9..b9733b4 100644 --- a/testdata/goldens/function_with_channel_parameter_and_result.go +++ b/testdata/goldens/function_with_channel_parameter_and_result.go @@ -19,7 +19,7 @@ func TestFoo23(t *testing.T) { } for _, tt := range tests { if got := Foo23(tt.args.ch); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo23() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo23() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go index f32b670..99a6334 100644 --- a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go +++ b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go @@ -19,7 +19,7 @@ func TestFoo16(t *testing.T) { } for _, tt := range tests { if got := Foo16(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo16() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo16() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go index d440f09..c900764 100644 --- a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go @@ -20,7 +20,7 @@ func TestFoo17(t *testing.T) { } for _, tt := range tests { if got := Foo17(tt.args.r); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo17() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo17() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go index 6b5cf29..05f83f5 100644 --- a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go @@ -20,7 +20,7 @@ func TestFoo18(t *testing.T) { } for _, tt := range tests { if got := Foo18(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo18() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo18() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_interface_parameter_and_result.go b/testdata/goldens/function_with_interface_parameter_and_result.go index 8774769..0f1b716 100644 --- a/testdata/goldens/function_with_interface_parameter_and_result.go +++ b/testdata/goldens/function_with_interface_parameter_and_result.go @@ -19,7 +19,7 @@ func TestFoo21(t *testing.T) { } for _, tt := range tests { if got := Foo21(tt.args.i); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo21() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo21() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_map_argument_and_return_type.go b/testdata/goldens/function_with_map_argument_and_return_type.go index 605ac3a..9079038 100644 --- a/testdata/goldens/function_with_map_argument_and_return_type.go +++ b/testdata/goldens/function_with_map_argument_and_return_type.go @@ -19,7 +19,7 @@ func TestFoo10(t *testing.T) { } for _, tt := range tests { if got := Foo10(tt.args.m); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo10() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo10() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_named_imports.go b/testdata/goldens/function_with_named_imports.go index bfdeaea..36cf0a9 100644 --- a/testdata/goldens/function_with_named_imports.go +++ b/testdata/goldens/function_with_named_imports.go @@ -20,7 +20,7 @@ func TestFoo22(t *testing.T) { } for _, tt := range tests { if got := Foo22(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo22() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo22() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_slice_argument_and_return_type.go b/testdata/goldens/function_with_slice_argument_and_return_type.go index e755234..871debb 100644 --- a/testdata/goldens/function_with_slice_argument_and_return_type.go +++ b/testdata/goldens/function_with_slice_argument_and_return_type.go @@ -25,7 +25,7 @@ func TestFoo11(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo11() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo11() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go index 0d181c8..15f1f1d 100644 --- a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go +++ b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go @@ -25,7 +25,7 @@ func TestFoo8(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo8() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Foo8() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions.go b/testdata/goldens/multiple_functions.go index 799ebea..99863e4 100644 --- a/testdata/goldens/multiple_functions.go +++ b/testdata/goldens/multiple_functions.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_excluding_on_method.go b/testdata/goldens/multiple_functions_excluding_on_method.go index f1861b5..3cec560 100644 --- a/testdata/goldens/multiple_functions_excluding_on_method.go +++ b/testdata/goldens/multiple_functions_excluding_on_method.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_excluding_on_receiver.go b/testdata/goldens/multiple_functions_excluding_on_receiver.go index f1861b5..3cec560 100644 --- a/testdata/goldens/multiple_functions_excluding_on_receiver.go +++ b/testdata/goldens/multiple_functions_excluding_on_receiver.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_filtering_exported.go b/testdata/goldens/multiple_functions_filtering_exported.go index 575b420..5848155 100644 --- a/testdata/goldens/multiple_functions_filtering_exported.go +++ b/testdata/goldens/multiple_functions_filtering_exported.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_filtering_exported_with_only.go b/testdata/goldens/multiple_functions_filtering_exported_with_only.go index 89a43e4..3ab749c 100644 --- a/testdata/goldens/multiple_functions_filtering_exported_with_only.go +++ b/testdata/goldens/multiple_functions_filtering_exported_with_only.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_with_case-insensitive_only.go b/testdata/goldens/multiple_functions_with_case-insensitive_only.go index f1861b5..3cec560 100644 --- a/testdata/goldens/multiple_functions_with_case-insensitive_only.go +++ b/testdata/goldens/multiple_functions_with_case-insensitive_only.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_functions_with_only.go b/testdata/goldens/multiple_functions_with_only.go index f1861b5..3cec560 100644 --- a/testdata/goldens/multiple_functions_with_only.go +++ b/testdata/goldens/multiple_functions_with_only.go @@ -25,7 +25,7 @@ func TestFooFilter(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/multiple_named_results.go b/testdata/goldens/multiple_named_results.go index 72ae6ac..d1ea457 100644 --- a/testdata/goldens/multiple_named_results.go +++ b/testdata/goldens/multiple_named_results.go @@ -33,7 +33,7 @@ func TestFoo26(t *testing.T) { t.Errorf("%q. Foo26() gotI = %v, want %v", tt.name, gotI, tt.wantI) } if !cmp.Equal(got2, tt.want2) { - t.Errorf("%q. Foo26() got2 = %v, want %v\ndiff=%v", tt.name, got2, tt.want2, cmp.Diff(got2, tt.want2)) + t.Errorf("%q. Foo26() got2 = %v, want %v\ndiff=%s", tt.name, got2, tt.want2, cmp.Diff(got2, tt.want2)) } } } diff --git a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go index f02462b..2e364b4 100644 --- a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go +++ b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go @@ -29,7 +29,7 @@ func TestImporter_Foo35(t *testing.T) { Field: tt.fields.Field, } if got := i.Foo35(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Importer.Foo35() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Importer.Foo35() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/struct_value_method_with_struct_value_return_type.go b/testdata/goldens/struct_value_method_with_struct_value_return_type.go index f2ba931..ebcdd15 100644 --- a/testdata/goldens/struct_value_method_with_struct_value_return_type.go +++ b/testdata/goldens/struct_value_method_with_struct_value_return_type.go @@ -17,7 +17,7 @@ func TestBar_Foo9(t *testing.T) { for _, tt := range tests { b := Bar{} if got := b.Foo9(); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Bar.Foo9() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Bar.Foo9() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/goldens/target_test_file.go b/testdata/goldens/target_test_file.go index 996fe09..41fd03d 100644 --- a/testdata/goldens/target_test_file.go +++ b/testdata/goldens/target_test_file.go @@ -69,7 +69,7 @@ func Test_wrapToString(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("wrapToString() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/testdata/goldens/target_test_file_without_only_flag.go b/testdata/goldens/target_test_file_without_only_flag.go index 996fe09..41fd03d 100644 --- a/testdata/goldens/target_test_file_without_only_flag.go +++ b/testdata/goldens/target_test_file_without_only_flag.go @@ -69,7 +69,7 @@ func Test_wrapToString(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("wrapToString() = %v, want %v\ndiff=%v", got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) } }) } diff --git a/testdata/goldens/undefined_types.go b/testdata/goldens/undefined_types.go index 495f861..8a99e21 100644 --- a/testdata/goldens/undefined_types.go +++ b/testdata/goldens/undefined_types.go @@ -26,7 +26,7 @@ func TestUndefined_Do(t *testing.T) { continue } if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Undefined.Do() = %v, want %v\ndiff=%v", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + t.Errorf("%q. Undefined.Do() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) } } } diff --git a/testdata/templatedata/function.tmpl b/testdata/templatedata/function.tmpl index 87ab7c7..91f9d5b 100644 --- a/testdata/templatedata/function.tmpl +++ b/testdata/templatedata/function.tmpl @@ -76,7 +76,7 @@ func {{.TestName}}(t *testing.T) { {{- else}} if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} diff --git a/testdata/use_template_params/function.tmpl b/testdata/use_template_params/function.tmpl index 2b37328..faa62ab 100644 --- a/testdata/use_template_params/function.tmpl +++ b/testdata/use_template_params/function.tmpl @@ -77,7 +77,7 @@ func {{.TestName}}(t *testing.T) { {{- else}} if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%v{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} From 632e2f0bdfcccd015d728e2475242923e3abf3e4 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Sun, 13 Mar 2022 00:12:13 +0100 Subject: [PATCH 4/7] Add `--use_go_cmp` flag to make usage of google/go-cmp optional When the `--use_go_cmp` flag is provided, equality checks will use `cmp.Equal` (https://pkg.go.dev/github.com/google/go-cmp/cmp) instead of `reflect.DeepEqual`. Differences between two objects will be reported using `cmp.Diff`. The tests that used `reflect.DeepEqual` have been duplicated, so that all behavior that was tested is now also tested when using `google/go-cmp`. --- README.md | 2 + go.mod | 2 +- go.sum | 4 +- gotests.go | 2 + gotests/main.go | 4 + gotests/main_test.go | 4 +- gotests/process/process.go | 2 + gotests/process/process_test.go | 4 +- gotests_test.go | 225 +++++++++++++++++- internal/output/options.go | 3 +- internal/output/options_test.go | 12 +- internal/render/bindata/esc.go | 35 +-- internal/render/render.go | 6 +- internal/render/templates/function.tmpl | 14 +- templates/tmpl.go | 28 +-- testdata/bad_customtemplates/function.tmpl | 14 +- testdata/customtemplates/function.tmpl | 14 +- testdata/goldens/custom_importer_fails.go | 7 +- testdata/goldens/custom_importer_fails_cmp.go | 69 ++++++ testdata/goldens/existing_test_file.go | 7 +- testdata/goldens/existing_test_file_cmp.go | 109 +++++++++ ...tion_returning_two_results_and_an_error.go | 7 +- ..._returning_two_results_and_an_error_cmp.go | 35 +++ ...ction_with_channel_parameter_and_result.go | 7 +- ...n_with_channel_parameter_and_result_cmp.go | 25 ++ ...ned_interface_type_parameter_and_result.go | 7 +- ...interface_type_parameter_and_result_cmp.go | 25 ++ ...interface_receiver_parameter_and_result.go | 7 +- ...rface_receiver_parameter_and_result_cmp.go | 26 ++ ...ed_struct_receiver_parameter_and_result.go | 7 +- ...truct_receiver_parameter_and_result_cmp.go | 26 ++ ...ion_with_interface_parameter_and_result.go | 7 +- ...with_interface_parameter_and_result_cmp.go | 25 ++ ...ction_with_map_argument_and_return_type.go | 7 +- ...n_with_map_argument_and_return_type_cmp.go | 25 ++ .../goldens/function_with_named_imports.go | 7 +- .../function_with_named_imports_cmp.go | 26 ++ ...ion_with_slice_argument_and_return_type.go | 7 +- ...with_slice_argument_and_return_type_cmp.go | 31 +++ ...struct_pointer_argument_and_return_type.go | 7 +- ...ct_pointer_argument_and_return_type_cmp.go | 31 +++ testdata/goldens/multiple_functions.go | 7 +- testdata/goldens/multiple_functions_cmp.go | 69 ++++++ .../multiple_functions_excluding_on_method.go | 7 +- ...tiple_functions_excluding_on_method_cmp.go | 49 ++++ ...ultiple_functions_excluding_on_receiver.go | 7 +- ...ple_functions_excluding_on_receiver_cmp.go | 49 ++++ .../multiple_functions_filtering_exported.go | 7 +- ...ltiple_functions_filtering_exported_cmp.go | 51 ++++ ..._functions_filtering_exported_with_only.go | 7 +- ...ctions_filtering_exported_with_only_cmp.go | 31 +++ ...le_functions_with_case-insensitive_only.go | 7 +- ...unctions_with_case-insensitive_only_cmp.go | 49 ++++ .../goldens/multiple_functions_with_only.go | 7 +- .../multiple_functions_with_only_cmp.go | 49 ++++ testdata/goldens/multiple_named_results.go | 7 +- .../goldens/multiple_named_results_cmp.go | 39 +++ ..._with_fields_with_complex_package_names.go | 7 +- ...h_fields_with_complex_package_names_cmp.go | 35 +++ ...ue_method_with_struct_value_return_type.go | 7 +- ...ethod_with_struct_value_return_type_cmp.go | 23 ++ testdata/goldens/target_test_file.go | 7 +- testdata/goldens/target_test_file_cmp.go | 76 ++++++ .../target_test_file_without_only_flag.go | 7 +- .../target_test_file_without_only_flag_cmp.go | 76 ++++++ testdata/goldens/undefined_types.go | 7 +- testdata/goldens/undefined_types_cmp.go | 32 +++ testdata/templatedata/function.tmpl | 14 +- testdata/use_template_params/function.tmpl | 14 +- 69 files changed, 1494 insertions(+), 165 deletions(-) create mode 100644 testdata/goldens/custom_importer_fails_cmp.go create mode 100644 testdata/goldens/existing_test_file_cmp.go create mode 100644 testdata/goldens/function_returning_two_results_and_an_error_cmp.go create mode 100644 testdata/goldens/function_with_channel_parameter_and_result_cmp.go create mode 100644 testdata/goldens/function_with_defined_interface_type_parameter_and_result_cmp.go create mode 100644 testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_cmp.go create mode 100644 testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_cmp.go create mode 100644 testdata/goldens/function_with_interface_parameter_and_result_cmp.go create mode 100644 testdata/goldens/function_with_map_argument_and_return_type_cmp.go create mode 100644 testdata/goldens/function_with_named_imports_cmp.go create mode 100644 testdata/goldens/function_with_slice_argument_and_return_type_cmp.go create mode 100644 testdata/goldens/function_with_struct_pointer_argument_and_return_type_cmp.go create mode 100644 testdata/goldens/multiple_functions_cmp.go create mode 100644 testdata/goldens/multiple_functions_excluding_on_method_cmp.go create mode 100644 testdata/goldens/multiple_functions_excluding_on_receiver_cmp.go create mode 100644 testdata/goldens/multiple_functions_filtering_exported_cmp.go create mode 100644 testdata/goldens/multiple_functions_filtering_exported_with_only_cmp.go create mode 100644 testdata/goldens/multiple_functions_with_case-insensitive_only_cmp.go create mode 100644 testdata/goldens/multiple_functions_with_only_cmp.go create mode 100644 testdata/goldens/multiple_named_results_cmp.go create mode 100644 testdata/goldens/receiver_struct_with_fields_with_complex_package_names_cmp.go create mode 100644 testdata/goldens/struct_value_method_with_struct_value_return_type_cmp.go create mode 100644 testdata/goldens/target_test_file_cmp.go create mode 100644 testdata/goldens/target_test_file_without_only_flag_cmp.go create mode 100644 testdata/goldens/undefined_types_cmp.go diff --git a/README.md b/README.md index aeea963..a7c478e 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Available options: -template_params_file read external parameters to template by json with file -template_params read external parameters to template by json with stdin + + -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals ``` ## Contributions diff --git a/go.mod b/go.mod index 785a004..1d174a4 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/cweill/gotests require ( - github.com/google/go-cmp v0.5.5 + github.com/google/go-cmp v0.5.7 golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 ) diff --git a/go.sum b/go.sum index 35a0057..e47abb9 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/gotests.go b/gotests.go index d7a9ea2..5bdf819 100644 --- a/gotests.go +++ b/gotests.go @@ -35,6 +35,7 @@ type Options struct { TemplateDir string // Path to custom template set TemplateParams map[string]interface{} // Custom external parameters TemplateData [][]byte // Data slice for templates + UseGoCmp bool // Use google/go-cmp instead of reflect.DeepEquals } // A GeneratedTest contains information about a test file with generated tests. @@ -134,6 +135,7 @@ func generateTest(src models.Path, files []models.Path, opt *Options) (*Generate TemplateDir: opt.TemplateDir, TemplateParams: opt.TemplateParams, TemplateData: opt.TemplateData, + UseGoCmp: opt.UseGoCmp, } b, err := options.Process(h, funcs) diff --git a/gotests/main.go b/gotests/main.go index 11d4ed4..94f7ec1 100644 --- a/gotests/main.go +++ b/gotests/main.go @@ -40,6 +40,8 @@ // -template_params_file read external parameters to template by json with file // // -template_params read external parameters to template by json with stdin +// +// -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals package main import ( @@ -60,6 +62,7 @@ var ( template = flag.String("template", "", `optional. Specify custom test code templates, e.g. testify. This can also be set via environment variable GOTESTS_TEMPLATE`) templateParamsPath = flag.String("template_params_file", "", "read external parameters to template by json with file") templateParams = flag.String("template_params", "", "read external parameters to template by json with stdin") + useGoCmp = flag.Bool("use_go_cmp", false, `use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals to perform equality checks`) ) var ( @@ -92,6 +95,7 @@ func main() { Template: valOrGetenv(*template, "GOTESTS_TEMPLATE"), TemplateDir: valOrGetenv(*templateDir, "GOTESTS_TEMPLATE_DIR"), TemplateParamsPath: *templateParamsPath, + UseGoCmp: *useGoCmp, }) } diff --git a/gotests/main_test.go b/gotests/main_test.go index 0c8dd28..8f8763b 100644 --- a/gotests/main_test.go +++ b/gotests/main_test.go @@ -67,8 +67,8 @@ func Test_valOrGetenv(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := valOrGetenv(tt.args.val, tt.args.key); !cmp.Equal(got, tt.want) { - t.Errorf("valOrGetenv() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := valOrGetenv(tt.args.val, tt.args.key); !cmp.Equal(tt.want, got) { + t.Errorf("valOrGetenv() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) } }) } diff --git a/gotests/process/process.go b/gotests/process/process.go index 9ffae5a..72964ec 100644 --- a/gotests/process/process.go +++ b/gotests/process/process.go @@ -36,6 +36,7 @@ type Options struct { TemplateDir string // Path to custom template set TemplateParamsPath string // Path to custom parameters json file(s). TemplateData [][]byte // Data slice for templates + UseGoCmp bool // Use google/go-cmp instead of reflect.DeepEquals } // Generates tests for the Go files defined in args with the given options. @@ -102,6 +103,7 @@ func parseOptions(out io.Writer, opt *Options) *gotests.Options { TemplateDir: opt.TemplateDir, TemplateParams: templateParams, TemplateData: opt.TemplateData, + UseGoCmp: opt.UseGoCmp, } } diff --git a/gotests/process/process_test.go b/gotests/process/process_test.go index 0046e5f..c52b883 100644 --- a/gotests/process/process_test.go +++ b/gotests/process/process_test.go @@ -55,8 +55,8 @@ func TestRun(t *testing.T) { for _, tt := range tests { out := &bytes.Buffer{} Run(out, tt.args, tt.opts) - if got := out.String(); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Run() =\n%v, want\n%v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := out.String(); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Run() =\n%v, want\n%v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) } } } diff --git a/gotests_test.go b/gotests_test.go index 4dbb835..5abc15a 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -32,6 +32,7 @@ func TestGenerateTests(t *testing.T) { template string templateParamsPath string templateData [][]byte + useGoCmp bool } tests := []struct { name string @@ -92,6 +93,18 @@ func TestGenerateTests(t *testing.T) { wantErr: false, want: mustReadAndFormatGoFile(t, `testdata/goldens/target_test_file.go`), }, + { + name: "Target test file with go-cmp", + args: args{ + srcPath: `testdata/test103_test.go`, + only: regexp.MustCompile("wrapToString"), + subtests: true, + useGoCmp: true, + }, + wantNoTests: false, + wantErr: false, + want: mustReadAndFormatGoFile(t, `testdata/goldens/target_test_file_cmp.go`), + }, { name: "Target test file without only flag", args: args{ @@ -100,7 +113,18 @@ func TestGenerateTests(t *testing.T) { }, wantNoTests: false, wantErr: false, - want: mustReadAndFormatGoFile(t, `testdata/goldens/target_test_file.go`), + want: mustReadAndFormatGoFile(t, `testdata/goldens/target_test_file_without_only_flag.go`), + }, + { + name: "Target test file without only flag with go-cmp", + args: args{ + srcPath: `testdata/test103_test.go`, + subtests: true, + useGoCmp: true, + }, + wantNoTests: false, + wantErr: false, + want: mustReadAndFormatGoFile(t, `testdata/goldens/target_test_file_without_only_flag_cmp.go`), }, { name: "No funcs", @@ -181,6 +205,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_struct_pointer_argument_and_return_type.go"), }, + { + name: "Function with struct pointer argument and return type and go-cmp", + args: args{ + srcPath: `testdata/test008.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_struct_pointer_argument_and_return_type_cmp.go"), + }, { name: "Struct value method with struct value return type", args: args{ @@ -188,6 +220,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/struct_value_method_with_struct_value_return_type.go"), }, + { + name: "Struct value method with struct value return type and go-cmp", + args: args{ + srcPath: `testdata/test009.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/struct_value_method_with_struct_value_return_type_cmp.go"), + }, { name: "Function with map argument and return type", args: args{ @@ -195,6 +235,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_map_argument_and_return_type.go"), }, + { + name: "Function with map argument, return type and go-cmp", + args: args{ + srcPath: `testdata/test010.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_map_argument_and_return_type_cmp.go"), + }, { name: "Function with slice argument and return type", args: args{ @@ -202,6 +250,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_slice_argument_and_return_type.go"), }, + { + name: "Function with slice argument, return type and go-cmp", + args: args{ + srcPath: `testdata/test011.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_slice_argument_and_return_type_cmp.go"), + }, { name: "Function returning only an error", args: args{ @@ -237,6 +293,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_defined_interface_type_parameter_and_result.go"), }, + { + name: "Function with defined interface type parameter, result and go-cmp", + args: args{ + srcPath: `testdata/test016.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_defined_interface_type_parameter_and_result_cmp.go"), + }, { name: "Function with imported interface receiver, parameter, and result", args: args{ @@ -245,12 +309,28 @@ func TestGenerateTests(t *testing.T) { want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go"), }, { - name: "Function with imported struct receiver, parameter, and result", + name: "Function with imported interface receiver, parameter, result and go-cmp", + args: args{ + srcPath: `testdata/test017.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_cmp.go"), + }, + { + name: "Function with imported struct receiver, parameter and result", args: args{ srcPath: `testdata/test018.go`, }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go"), }, + { + name: "Function with imported struct receiver, parameter, result and go-cmp", + args: args{ + srcPath: `testdata/test018.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_cmp.go"), + }, { name: "Function with multiple parameters of the same type", args: args{ @@ -272,6 +352,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_interface_parameter_and_result.go"), }, + { + name: "Function with interface{} parameter, result and go-cmp", + args: args{ + srcPath: `testdata/test021.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_interface_parameter_and_result_cmp.go"), + }, { name: "Function with named imports", args: args{ @@ -279,6 +367,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_named_imports.go"), }, + { + name: "Function with named imports and go-cmp", + args: args{ + srcPath: `testdata/test022.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_named_imports_cmp.go"), + }, { name: "Function with channel parameter and result", args: args{ @@ -286,6 +382,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_channel_parameter_and_result.go"), }, + { + name: "Function with channel parameter, result and go-cmp", + args: args{ + srcPath: `testdata/test023.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_with_channel_parameter_and_result_cmp.go"), + }, { name: "File with multiple imports", args: args{ @@ -300,6 +404,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/function_returning_two_results_and_an_error.go"), }, + { + name: "Function returning two results and an error with go-cmp", + args: args{ + srcPath: `testdata/test025.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/function_returning_two_results_and_an_error_cmp.go"), + }, { name: "Multiple named results", args: args{ @@ -307,6 +419,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_named_results.go"), }, + { + name: "Multiple named results with go-cmp", + args: args{ + srcPath: `testdata/test026.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_named_results_cmp.go"), + }, { name: "Two different structs with same method name", args: args{ @@ -370,6 +490,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go"), }, + { + name: "Receiver struct with fields with complex package names and go-cmp", + args: args{ + srcPath: `testdata/test035.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/receiver_struct_with_fields_with_complex_package_names_cmp.go"), + }, { name: "Functions and receivers with same names except exporting", args: args{ @@ -391,6 +519,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions.go"), }, + { + name: "Multiple functions with go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_cmp.go"), + }, { name: "Multiple functions with only", args: args{ @@ -399,6 +535,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_with_only.go"), }, + { + name: "Multiple functions with only and go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + only: regexp.MustCompile("FooFilter|bazFilter"), + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_with_only_cmp.go"), + }, { name: "Multiple functions with only regexp without matches", args: args{ @@ -415,6 +560,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_with_case-insensitive_only.go"), }, + { + name: "Multiple functions with case-insensitive only and go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + only: regexp.MustCompile("(?i)fooFilter|BazFilter"), + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_with_case-insensitive_only_cmp.go"), + }, { name: "Multiple functions with only filtering on receiver", args: args{ @@ -439,6 +593,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_filtering_exported.go"), }, + { + name: "Multiple functions filtering exported with go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + exported: true, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_filtering_exported_cmp.go"), + }, { name: "Multiple functions filtering exported with only", args: args{ @@ -448,6 +611,16 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_filtering_exported_with_only.go"), }, + { + name: "Multiple functions filtering exported with only and go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + only: regexp.MustCompile(`FooFilter`), + exported: true, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_filtering_exported_with_only_cmp.go"), + }, { name: "Multiple functions filtering all out", args: args{ @@ -497,6 +670,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_excluding_on_receiver.go"), }, + { + name: "Multiple functions excluding on receiver with go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + excl: regexp.MustCompile("^BarBarFilter$"), + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_excluding_on_receiver_cmp.go"), + }, { name: "Multiple functions excluding on method", args: args{ @@ -505,6 +687,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_excluding_on_method.go"), }, + { + name: "Multiple functions excluding on method with go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + excl: regexp.MustCompile("^BarFilter$"), + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/multiple_functions_excluding_on_method_cmp.go"), + }, { name: "Multiple functions with both only and excl", args: args{ @@ -531,6 +722,15 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/custom_importer_fails.go"), }, + { + name: "Custom importer fails with go-cmp", + args: args{ + srcPath: `testdata/test_filter.go`, + importer: &fakeImporter{err: errors.New("error")}, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/custom_importer_fails_cmp.go"), + }, { name: "Existing test file", args: args{ @@ -538,6 +738,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/existing_test_file.go"), }, + { + name: "Existing test file with go-cmp", + args: args{ + srcPath: `testdata/test100.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/existing_test_file_cmp.go"), + }, { name: "Existing test file with just package declaration", args: args{ @@ -602,6 +810,14 @@ func TestGenerateTests(t *testing.T) { }, want: mustReadAndFormatGoFile(t, "testdata/goldens/undefined_types.go"), }, + { + name: "Undefined types with go-cmp", + args: args{ + srcPath: `testdata/undefinedtypes/undefined.go`, + useGoCmp: true, + }, + want: mustReadAndFormatGoFile(t, "testdata/goldens/undefined_types_cmp.go"), + }, { name: "Subtest Edition - Functions and receivers with same names except exporting", args: args{ @@ -901,6 +1117,7 @@ func TestGenerateTests(t *testing.T) { Template: tt.args.template, TemplateParams: params, TemplateData: tt.args.templateData, + UseGoCmp: tt.args.useGoCmp, }) if (err != nil) != tt.wantErr { t.Errorf("%q. GenerateTests(%v) error = %v, wantErr %v", tt.name, tt.args.srcPath, err, tt.wantErr) @@ -917,8 +1134,8 @@ func TestGenerateTests(t *testing.T) { if tt.wantNoTests || tt.wantMultipleTests { return } - if got := string(gts[0].Output); got != tt.want { - t.Errorf("%q. GenerateTests(%v) = diff=%s", tt.name, tt.args.srcPath, cmp.Diff(got, tt.want)) + if got := string(gts[0].Output); !cmp.Equal(tt.want, got) { + t.Errorf("%q. GenerateTests(%v) = diff=%s", tt.name, tt.args.srcPath, cmp.Diff(tt.want, got)) outputResult(t, tmp, tt.name, gts[0].Output) } }) diff --git a/internal/output/options.go b/internal/output/options.go index 2572f3a..9113f0f 100755 --- a/internal/output/options.go +++ b/internal/output/options.go @@ -22,6 +22,7 @@ type Options struct { TemplateDir string TemplateParams map[string]interface{} TemplateData [][]byte + UseGoCmp bool render *render.Render } @@ -89,7 +90,7 @@ func (o *Options) writeTests(w io.Writer, head *models.Header, funcs []*models.F } for _, fun := range funcs { - err := o.render.TestFunction(b, fun, o.PrintInputs, o.Subtests, o.Named, o.Parallel, o.TemplateParams) + err := o.render.TestFunction(b, fun, o.PrintInputs, o.Subtests, o.Named, o.Parallel, o.UseGoCmp, o.TemplateParams) if err != nil { return fmt.Errorf("render.TestFunction: %v", err) } diff --git a/internal/output/options_test.go b/internal/output/options_test.go index 055b26d..fb177ee 100755 --- a/internal/output/options_test.go +++ b/internal/output/options_test.go @@ -20,8 +20,8 @@ func TestOptions_providesTemplateData(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplateData(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplateData() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := tt.otpions.providesTemplateData(); !cmp.Equal(tt.want, got) { + t.Errorf("Options.isProvidesTemplateData() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) } }) } @@ -40,8 +40,8 @@ func TestOptions_providesTemplate(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplate(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := tt.otpions.providesTemplate(); !cmp.Equal(tt.want, got) { + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) } }) } @@ -60,8 +60,8 @@ func TestOptions_providesTemplateDir(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := tt.otpions.providesTemplateDir(); !cmp.Equal(got, tt.want) { - t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := tt.otpions.providesTemplateDir(); !cmp.Equal(tt.want, got) { + t.Errorf("Options.isProvidesTemplate() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) } }) } diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go index c2d010e..948dab2 100644 --- a/internal/render/bindata/esc.go +++ b/internal/render/bindata/esc.go @@ -224,24 +224,25 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= "/templates/function.tmpl": { name: "function.tmpl", local: "templates/function.tmpl", - size: 2806, - modtime: 1617038490, + size: 3201, + modtime: 1647120987, compressed: ` -H4sIAAAAAAAC/7RWTW/jNhA9y79i1kgWUuHl3hP40MWmxR66KZKge9gWBWONXKI05ZKjBAbB/17wQxJl -W6kvvdgixZl5897MUNbW2AiFsGw6tSHRqqVzC2s/wFUDN2tgzi0W/hVYy57Q0Fe+Q+dKgh8IDQm1ZU8V -2EXhTV4F/QXsATcoXlA7tyjCtmiAfTGPpLsNhc1h9yeBsjZxr6DDHqEJO2DCYe83ndZcbfHIoLA2rD3I -AO+wx/TKm6Cq02qI2W9lz0ePHpVP81eu+Q4JdQgWoHG9nQDLYJ1ahIBh6wRdFnEa3xNqPOnWBhye6tq5 -Hd9/N6SF2v4Ro1uL0qBz38e1d5BAedNStZTsK+cU3yFED+loQnFGr54ErupRtCPek0bxb6A2QEqJ9y5P -lZlR4Q3uiyIQ73/O2GQCPKDpJJk+zjeu6C3uh5APSJ1W5k7rNnHwyhXdaQ3PbSuPBPMcf/wIT/ef72/g -x7oGLxpsuEHDgp5Nq8Far0GrgT12z1HVqMgX85X/jXVVBViZxl6iXtY/k0grIIrVEOWNqUZ3NsPfx5gk -5TmUEqVz0QnR7VT7XuP+4ASKt/D/t9b6zCFYEXvoVDkLm4ilZQTvh8bpmDiLcHguqynIoYXnqnVmvpzU -YKAx1Ndhj+Ew1869T9FShbDfuOzQOdu7mBk7hbUsjsEbIGKxD1g2jFajg3EIFWcm08kixTszS/o0v2lB -Q/aTGXOzhvfPB0LDPnVNg9peEjCVQSzPeyUPeTdUp/v3CgNLFQzICHd7yQlhqWMHLuGqCQU+vtlwKeP2 -HIozbViIJql2DMw5QK2jqueC3A5NU/pz79aghKz8PxHruzvJTCy4bMpl7muHxvAtplTQn4A1XL+soDe/ -flmuJuGF2ndD8qj1KgtWjRXRT7nJuArv8mYG53RIuG+vTatIqA7HBvnva+7NCTlbU4H1n1saG2eoMfYY -bpGyus2ORFbzgTvWnTSYYnziRmyyG3oQ96o5V1++KScYcp6lUHgs9MV4/qf47za7Pbv7p+OyHCxXUyBV -jmRQ7ZL664EmkL90ksReTkAmHGONwvVL9jFQgr+Oeqkngvjb6HdVi6ZZX5th4L9V3HMJhnwAAFJpXRJ5 -BZ64z6Jp5nkbQFXzn3NHzQOe7XgEPsRPLbdY9M3zbwAAAP//vowfufYKAAA= +H4sIAAAAAAAC/7RWTW/jNhA9279i1kgWVuHl3hP40G3SxR66KZK0e9gWBWOPXKE0pZKjLAyC/73gl0TZ +UmoU6cUWKc7Mm/dmhjJmi2UlERZlKzdU1XJh7dyYd3BRwtUamLXzuXsFxrBH1PSZ79HaJcF3hJoquWOP +BZj5zJl8q+hPYPe4weoZlbXzmd+uSmCf9AOpdkN+s9v9sUKx1WFvRocGofQ7oP1h5zeeVlzu8MhgZoxf +O5Ae3qHB+MqZoNzGVRczbWXPR48OlUvzZ674HgmVD+ahcbUbAMtgnVr4gH7rBF0WcRjfEaod6cZ4HI7q +rbV73nzVpCq5+z1ENwaFRmu/9mvnIIJypktZU7QvrJV8jxA8xKMRxYheiQQut71oR7xHjcJfR62HFBNP +Lk+VmVDhBe5nM0+8+xmxyQS4R90K0inOFy7pJe67kPdIrZL6Vqk6cvCNS7pVCp7qWhwJ5jh+/x4e727u +ruD77RacaLDhGjXzepa1AmOcBrUC9tA+BVWDIp/0Z/4XbovCw8o0dhIlWf+IIq2AKFRDkDekGtyZDH+K +MUjKcSgECmuDE6LrofZJ43RwAMVZuP9rY1zm4K2I3bdyOQmbiMVlAO+GxumYGEXYPS+LIciuhaeqdWK+ +nNSgp9HX16FBf5gra9/GaLFC2K9ctGitSS4mxs7MGBbG4BUQsdAHLBtGq95BP4RmI5PpZBHjjcySlOYX +VVGX/WDGXK3h7dOBULMPbVmiMucEjGUQyvNOikPeDcXp/p1Ez1IBHTLCfSM4ISxU6MAFXJS+wPs3Gy5E +2J5CMdKGs6qMqh0DsxZQqaDqWJDrrmmW7tybNchKFO6fiKXujjIT8y7L5SL3tUet+Q5jKuhOwBoun1eQ +zC+fF6tB+Eo2bZc8KrXKghV9RaQpNxhX/l3ezGCt8gmn9trUkirZYt8g/37NvTghJ2vKs/6xpr5xuhpj +D/4WWRbX2ZHAaj5w+7oTGmOMD1xXm+yG7sS9KMfqyzXlAEPOs6gkHgt9Np6cOxee/aLxY/3DvumUeGVk +bzb7ht3+3XKxHOBa9ZgLyGZODvLVsSgsBW6I3SA2AVPnYTWkbYipK7LT1SiJ53RVSiwm9VMrqGrEIKmI +u+88uHzOPnGW4C7ZVMCDMnN37G9yW5Xl+lJ319hLLTtFBPiMAABSuufEXoGT/aYqy2nVO1jFaIX+jxz+ +Fx6Kc7+sj+YYuFIKR+Bd+Oq183maY/8EAAD//7cMF+uBDAAA `, }, diff --git a/internal/render/render.go b/internal/render/render.go index 4317420..7e51b30 100755 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -104,13 +104,16 @@ func (r *Render) TestFunction( subtests bool, named bool, parallel bool, - params map[string]interface{}) error { + useGoCmp bool, + params map[string]interface{}, +) error { return r.tmpls.ExecuteTemplate(w, "function", struct { *models.Function PrintInputs bool Subtests bool Parallel bool Named bool + UseGoCmp bool TemplateParams map[string]interface{} }{ Function: f, @@ -118,6 +121,7 @@ func (r *Render) TestFunction( Subtests: subtests, Parallel: parallel, Named: named, + UseGoCmp: useGoCmp, TemplateParams: params, }) } diff --git a/internal/render/templates/function.tmpl b/internal/render/templates/function.tmpl index f31c7bc..5868a24 100644 --- a/internal/render/templates/function.tmpl +++ b/internal/render/templates/function.tmpl @@ -79,10 +79,18 @@ func {{.TestName}}(t *testing.T) { {{- 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}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { + {{- if $.UseGoCmp}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal(tt.{{Want .}}, {{Got .}}) { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { + {{- end}} + {{- end}} + {{- if $.UseGoCmp}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff(tt.{{Want .}}, {{Got .}}){{ end }}) + {{- else}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} - {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/templates/tmpl.go b/templates/tmpl.go index 3a8bce2..2f8e06b 100644 --- a/templates/tmpl.go +++ b/templates/tmpl.go @@ -213,7 +213,7 @@ var _escData = map[string]*_escFile{ name: "call.tmpl", local: "test/call.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -223,7 +223,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "function.tmpl", local: "test/function.tmpl", size: 19, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/6qu1tdSSFRIzs/NTc0rUdDSr+UCBAAA//+6o7WcEwAAAA== `, @@ -233,7 +233,7 @@ H4sIAAAAAAAC/6qu1tdSSFRIzs/NTc0rUdDSr+UCBAAA//+6o7WcEwAAAA== name: "header.tmpl", local: "test/header.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -243,7 +243,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "inline.tmpl", local: "test/inline.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -253,7 +253,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "inputs.tmpl", local: "test/inputs.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -263,7 +263,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "message.tmpl", local: "test/message.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -273,7 +273,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "results.tmpl", local: "test/results.tmpl", size: 0, - modtime: 1615633710, + modtime: 1616493590, compressed: ` H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= `, @@ -283,7 +283,7 @@ H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= name: "call.tmpl", local: "testify/call.tmpl", size: 241, - modtime: 1613754073, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj @@ -295,7 +295,7 @@ Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= name: "function.tmpl", local: "testify/function.tmpl", size: 2798, - modtime: 1616467003, + modtime: 1616880641, compressed: ` H4sIAAAAAAAC/5xWUW/cNgx+tn8FYQTFebiq7yn60GHtkJemSIL1oRgG9UzfjPl0N4necBD43wdRlu3z 2VnTPOQsyiQ/8qM+y/sK68YgFNo5tNQcTQGvmXMiNVg2tAXvmxrUvWnPD0idNe6DtUfL7D3h4dRqQih2 @@ -319,7 +319,7 @@ nHO4HUWX/wIAAP//vN7yje4KAAA= name: "header.tmpl", local: "testify/header.tmpl", size: 142, - modtime: 1616472631, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 @@ -331,7 +331,7 @@ jgAAAA== name: "inline.tmpl", local: "testify/inline.tmpl", size: 49, - modtime: 1613735787, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA //+q60H/MQAAAA== @@ -342,7 +342,7 @@ H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA name: "inputs.tmpl", local: "testify/inputs.tmpl", size: 177, - modtime: 1616467003, + modtime: 1616880641, compressed: ` H4sIAAAAAAAC/0yNMaoDMQxE+38KsWz58QECOUCaEMgJFCwvLqwESVsJ3T1YpHAlzWN4416pdSbYOn9O 0y3CfW9wuUKZb2/Ab4PyPF9GarqyOw6qEWbFnbhGMA76h1/I3t7KQzrbLeUTCvJByVFwkJFoKlAOLe5J @@ -354,7 +354,7 @@ H4sIAAAAAAAC/0yNMaoDMQxE+38KsWz58QECOUCaEMgJFCwvLqwESVsJ3T1YpHAlzWN4416pdSbYOn9O name: "message.tmpl", local: "testify/message.tmpl", size: 201, - modtime: 1613735787, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 @@ -366,7 +366,7 @@ ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 name: "results.tmpl", local: "testify/results.tmpl", size: 168, - modtime: 1613735787, + modtime: 1616493299, compressed: ` H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ diff --git a/testdata/bad_customtemplates/function.tmpl b/testdata/bad_customtemplates/function.tmpl index 91f9d5b..a1ec329 100644 --- a/testdata/bad_customtemplates/function.tmpl +++ b/testdata/bad_customtemplates/function.tmpl @@ -74,10 +74,18 @@ func {{.TestName}}(t *testing.T) { {{- 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}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { + {{- if $.UseGoCmp}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal(tt.{{Want .}}, {{Got .}}) { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { + {{- end}} + {{- end}} + {{- if $.UseGoCmp}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff(tt.{{Want .}}, {{Got .}}){{ end }}) + {{- else}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} - {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/customtemplates/function.tmpl b/testdata/customtemplates/function.tmpl index 91f9d5b..a1ec329 100644 --- a/testdata/customtemplates/function.tmpl +++ b/testdata/customtemplates/function.tmpl @@ -74,10 +74,18 @@ func {{.TestName}}(t *testing.T) { {{- 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}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { + {{- if $.UseGoCmp}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal(tt.{{Want .}}, {{Got .}}) { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { + {{- end}} + {{- end}} + {{- if $.UseGoCmp}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff(tt.{{Want .}}, {{Got .}}){{ end }}) + {{- else}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} - {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/goldens/custom_importer_fails.go b/testdata/goldens/custom_importer_fails.go index 99863e4..aaa8d7e 100644 --- a/testdata/goldens/custom_importer_fails.go +++ b/testdata/goldens/custom_importer_fails.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/custom_importer_fails_cmp.go b/testdata/goldens/custom_importer_fails_cmp.go new file mode 100644 index 0000000..08364eb --- /dev/null +++ b/testdata/goldens/custom_importer_fails_cmp.go @@ -0,0 +1,69 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func TestBar_BarFilter(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + b *Bar + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + if err := b.BarFilter(tt.args.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.BarFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/existing_test_file.go b/testdata/goldens/existing_test_file.go index 78a4599..4016794 100644 --- a/testdata/goldens/existing_test_file.go +++ b/testdata/goldens/existing_test_file.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestBarBar100(t *testing.T) { @@ -64,8 +63,8 @@ func TestFoo100(t *testing.T) { t.Errorf("%q. Foo100() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo100() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo100() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/existing_test_file_cmp.go b/testdata/goldens/existing_test_file_cmp.go new file mode 100644 index 0000000..b883db1 --- /dev/null +++ b/testdata/goldens/existing_test_file_cmp.go @@ -0,0 +1,109 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBarBar100(t *testing.T) { + tests := []struct { + name string + b *Bar + i interface{} + wantErr bool + }{ + { + name: "Basic test", + b: &Bar{}, + wantErr: true, + }, + } + for _, tt := range tests { + if err := tt.b.Bar100(tt.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func TestBaz100(t *testing.T) { + tests := []struct { + name string + f *float64 + want float64 + }{ + { + name: "Basic test", + f: func() *float64 { var x float64 = 64; return &x }(), + want: 64, + }, + } + // TestBaz100 contains a comment. + for _, tt := range tests { + if got := baz100(tt.f); got != tt.want { + t.Errorf("%q. baz100() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func TestFoo100(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo100(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo100() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func TestBar_Bar100(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + b *Bar + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + if err := b.Bar100(tt.args.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.Bar100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func Test_baz100(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := baz100(tt.args.f); got != tt.want { + t.Errorf("%q. baz100() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/function_returning_two_results_and_an_error.go b/testdata/goldens/function_returning_two_results_and_an_error.go index bcd0476..0f53cf3 100644 --- a/testdata/goldens/function_returning_two_results_and_an_error.go +++ b/testdata/goldens/function_returning_two_results_and_an_error.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo25(t *testing.T) { @@ -28,8 +27,8 @@ func TestFoo25(t *testing.T) { if got != tt.want { t.Errorf("%q. Foo25() got = %v, want %v", tt.name, got, tt.want) } - if !cmp.Equal(got1, tt.want1) { - t.Errorf("%q. Foo25() got1 = %v, want %v\ndiff=%s", tt.name, got1, tt.want1, cmp.Diff(got1, tt.want1)) + if !reflect.DeepEqual(got1, tt.want1) { + t.Errorf("%q. Foo25() got1 = %v, want %v", tt.name, got1, tt.want1) } } } diff --git a/testdata/goldens/function_returning_two_results_and_an_error_cmp.go b/testdata/goldens/function_returning_two_results_and_an_error_cmp.go new file mode 100644 index 0000000..7a28190 --- /dev/null +++ b/testdata/goldens/function_returning_two_results_and_an_error_cmp.go @@ -0,0 +1,35 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo25(t *testing.T) { + type args struct { + in0 interface{} + } + tests := []struct { + name string + args args + want string + want1 []byte + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, got1, err := Foo25(tt.args.in0) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo25() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Foo25() got = %v, want %v", tt.name, got, tt.want) + } + if !cmp.Equal(tt.want1, got1) { + t.Errorf("%q. Foo25() got1 = %v, want %v\ndiff=%s", tt.name, got1, tt.want1, cmp.Diff(tt.want1, got1)) + } + } +} diff --git a/testdata/goldens/function_with_channel_parameter_and_result.go b/testdata/goldens/function_with_channel_parameter_and_result.go index b9733b4..88ea072 100644 --- a/testdata/goldens/function_with_channel_parameter_and_result.go +++ b/testdata/goldens/function_with_channel_parameter_and_result.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo23(t *testing.T) { @@ -18,8 +17,8 @@ func TestFoo23(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo23(tt.args.ch); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo23() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo23(tt.args.ch); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo23() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_channel_parameter_and_result_cmp.go b/testdata/goldens/function_with_channel_parameter_and_result_cmp.go new file mode 100644 index 0000000..d6c200e --- /dev/null +++ b/testdata/goldens/function_with_channel_parameter_and_result_cmp.go @@ -0,0 +1,25 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo23(t *testing.T) { + type args struct { + ch chan bool + } + tests := []struct { + name string + args args + want chan string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo23(tt.args.ch); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo23() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go index 99a6334..438f7a0 100644 --- a/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go +++ b/testdata/goldens/function_with_defined_interface_type_parameter_and_result.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo16(t *testing.T) { @@ -18,8 +17,8 @@ func TestFoo16(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo16(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo16() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo16(tt.args.in); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo16() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_defined_interface_type_parameter_and_result_cmp.go b/testdata/goldens/function_with_defined_interface_type_parameter_and_result_cmp.go new file mode 100644 index 0000000..d05e3c4 --- /dev/null +++ b/testdata/goldens/function_with_defined_interface_type_parameter_and_result_cmp.go @@ -0,0 +1,25 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo16(t *testing.T) { + type args struct { + in Bazzar + } + tests := []struct { + name string + args args + want Bazzar + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo16(tt.args.in); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo16() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go index c900764..a753d72 100644 --- a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result.go @@ -2,9 +2,8 @@ package testdata import ( "io" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo17(t *testing.T) { @@ -19,8 +18,8 @@ func TestFoo17(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo17(tt.args.r); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo17() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo17(tt.args.r); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo17() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_cmp.go b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_cmp.go new file mode 100644 index 0000000..e826fad --- /dev/null +++ b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_cmp.go @@ -0,0 +1,26 @@ +package testdata + +import ( + "io" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo17(t *testing.T) { + type args struct { + r io.Reader + } + tests := []struct { + name string + args args + want io.Reader + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo17(tt.args.r); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo17() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go index 05f83f5..1ba505b 100644 --- a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go +++ b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result.go @@ -2,9 +2,8 @@ package testdata import ( "os" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo18(t *testing.T) { @@ -19,8 +18,8 @@ func TestFoo18(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo18(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo18() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo18(tt.args.t); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo18() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_cmp.go b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_cmp.go new file mode 100644 index 0000000..8ef4782 --- /dev/null +++ b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_cmp.go @@ -0,0 +1,26 @@ +package testdata + +import ( + "os" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo18(t *testing.T) { + type args struct { + t *os.File + } + tests := []struct { + name string + args args + want *os.File + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo18(tt.args.t); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo18() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_interface_parameter_and_result.go b/testdata/goldens/function_with_interface_parameter_and_result.go index 0f1b716..e415d97 100644 --- a/testdata/goldens/function_with_interface_parameter_and_result.go +++ b/testdata/goldens/function_with_interface_parameter_and_result.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo21(t *testing.T) { @@ -18,8 +17,8 @@ func TestFoo21(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo21(tt.args.i); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo21() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo21(tt.args.i); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo21() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_interface_parameter_and_result_cmp.go b/testdata/goldens/function_with_interface_parameter_and_result_cmp.go new file mode 100644 index 0000000..0911963 --- /dev/null +++ b/testdata/goldens/function_with_interface_parameter_and_result_cmp.go @@ -0,0 +1,25 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo21(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + args args + want interface{} + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo21(tt.args.i); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo21() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_map_argument_and_return_type.go b/testdata/goldens/function_with_map_argument_and_return_type.go index 9079038..8062de9 100644 --- a/testdata/goldens/function_with_map_argument_and_return_type.go +++ b/testdata/goldens/function_with_map_argument_and_return_type.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo10(t *testing.T) { @@ -18,8 +17,8 @@ func TestFoo10(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo10(tt.args.m); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo10() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo10(tt.args.m); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo10() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_map_argument_and_return_type_cmp.go b/testdata/goldens/function_with_map_argument_and_return_type_cmp.go new file mode 100644 index 0000000..c4cc8b7 --- /dev/null +++ b/testdata/goldens/function_with_map_argument_and_return_type_cmp.go @@ -0,0 +1,25 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo10(t *testing.T) { + type args struct { + m map[string]int32 + } + tests := []struct { + name string + args args + want map[string]*Bar + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo10(tt.args.m); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo10() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_named_imports.go b/testdata/goldens/function_with_named_imports.go index 36cf0a9..39b2e34 100644 --- a/testdata/goldens/function_with_named_imports.go +++ b/testdata/goldens/function_with_named_imports.go @@ -2,9 +2,8 @@ package testdata import ( ht "html/template" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo22(t *testing.T) { @@ -19,8 +18,8 @@ func TestFoo22(t *testing.T) { // TODO: Add test cases. } for _, tt := range tests { - if got := Foo22(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo22() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := Foo22(tt.args.t); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo22() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_named_imports_cmp.go b/testdata/goldens/function_with_named_imports_cmp.go new file mode 100644 index 0000000..173526e --- /dev/null +++ b/testdata/goldens/function_with_named_imports_cmp.go @@ -0,0 +1,26 @@ +package testdata + +import ( + ht "html/template" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo22(t *testing.T) { + type args struct { + t *ht.Template + } + tests := []struct { + name string + args args + want *ht.Template + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo22(tt.args.t); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo22() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_slice_argument_and_return_type.go b/testdata/goldens/function_with_slice_argument_and_return_type.go index 871debb..42d5a61 100644 --- a/testdata/goldens/function_with_slice_argument_and_return_type.go +++ b/testdata/goldens/function_with_slice_argument_and_return_type.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo11(t *testing.T) { @@ -24,8 +23,8 @@ func TestFoo11(t *testing.T) { t.Errorf("%q. Foo11() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo11() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo11() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_slice_argument_and_return_type_cmp.go b/testdata/goldens/function_with_slice_argument_and_return_type_cmp.go new file mode 100644 index 0000000..a896c0b --- /dev/null +++ b/testdata/goldens/function_with_slice_argument_and_return_type_cmp.go @@ -0,0 +1,31 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo11(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo11(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo11() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo11() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go index 15f1f1d..6f77092 100644 --- a/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go +++ b/testdata/goldens/function_with_struct_pointer_argument_and_return_type.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo8(t *testing.T) { @@ -24,8 +23,8 @@ func TestFoo8(t *testing.T) { t.Errorf("%q. Foo8() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Foo8() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo8() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/function_with_struct_pointer_argument_and_return_type_cmp.go b/testdata/goldens/function_with_struct_pointer_argument_and_return_type_cmp.go new file mode 100644 index 0000000..d645e5a --- /dev/null +++ b/testdata/goldens/function_with_struct_pointer_argument_and_return_type_cmp.go @@ -0,0 +1,31 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo8(t *testing.T) { + type args struct { + b *Bar + } + tests := []struct { + name string + args args + want *Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo8(tt.args.b) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo8() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. Foo8() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/multiple_functions.go b/testdata/goldens/multiple_functions.go index 99863e4..aaa8d7e 100644 --- a/testdata/goldens/multiple_functions.go +++ b/testdata/goldens/multiple_functions.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_cmp.go b/testdata/goldens/multiple_functions_cmp.go new file mode 100644 index 0000000..08364eb --- /dev/null +++ b/testdata/goldens/multiple_functions_cmp.go @@ -0,0 +1,69 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func TestBar_BarFilter(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + b *Bar + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + if err := b.BarFilter(tt.args.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.BarFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/multiple_functions_excluding_on_method.go b/testdata/goldens/multiple_functions_excluding_on_method.go index 3cec560..5c448d5 100644 --- a/testdata/goldens/multiple_functions_excluding_on_method.go +++ b/testdata/goldens/multiple_functions_excluding_on_method.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_excluding_on_method_cmp.go b/testdata/goldens/multiple_functions_excluding_on_method_cmp.go new file mode 100644 index 0000000..ede0373 --- /dev/null +++ b/testdata/goldens/multiple_functions_excluding_on_method_cmp.go @@ -0,0 +1,49 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/multiple_functions_excluding_on_receiver.go b/testdata/goldens/multiple_functions_excluding_on_receiver.go index 3cec560..5c448d5 100644 --- a/testdata/goldens/multiple_functions_excluding_on_receiver.go +++ b/testdata/goldens/multiple_functions_excluding_on_receiver.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_excluding_on_receiver_cmp.go b/testdata/goldens/multiple_functions_excluding_on_receiver_cmp.go new file mode 100644 index 0000000..ede0373 --- /dev/null +++ b/testdata/goldens/multiple_functions_excluding_on_receiver_cmp.go @@ -0,0 +1,49 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/multiple_functions_filtering_exported.go b/testdata/goldens/multiple_functions_filtering_exported.go index 5848155..6e92855 100644 --- a/testdata/goldens/multiple_functions_filtering_exported.go +++ b/testdata/goldens/multiple_functions_filtering_exported.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_filtering_exported_cmp.go b/testdata/goldens/multiple_functions_filtering_exported_cmp.go new file mode 100644 index 0000000..d0899ac --- /dev/null +++ b/testdata/goldens/multiple_functions_filtering_exported_cmp.go @@ -0,0 +1,51 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func TestBar_BarFilter(t *testing.T) { + type args struct { + i interface{} + } + tests := []struct { + name string + b *Bar + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + if err := b.BarFilter(tt.args.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.BarFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} diff --git a/testdata/goldens/multiple_functions_filtering_exported_with_only.go b/testdata/goldens/multiple_functions_filtering_exported_with_only.go index 3ab749c..5095342 100644 --- a/testdata/goldens/multiple_functions_filtering_exported_with_only.go +++ b/testdata/goldens/multiple_functions_filtering_exported_with_only.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_filtering_exported_with_only_cmp.go b/testdata/goldens/multiple_functions_filtering_exported_with_only_cmp.go new file mode 100644 index 0000000..a722646 --- /dev/null +++ b/testdata/goldens/multiple_functions_filtering_exported_with_only_cmp.go @@ -0,0 +1,31 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/multiple_functions_with_case-insensitive_only.go b/testdata/goldens/multiple_functions_with_case-insensitive_only.go index 3cec560..5c448d5 100644 --- a/testdata/goldens/multiple_functions_with_case-insensitive_only.go +++ b/testdata/goldens/multiple_functions_with_case-insensitive_only.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_with_case-insensitive_only_cmp.go b/testdata/goldens/multiple_functions_with_case-insensitive_only_cmp.go new file mode 100644 index 0000000..ede0373 --- /dev/null +++ b/testdata/goldens/multiple_functions_with_case-insensitive_only_cmp.go @@ -0,0 +1,49 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/multiple_functions_with_only.go b/testdata/goldens/multiple_functions_with_only.go index 3cec560..5c448d5 100644 --- a/testdata/goldens/multiple_functions_with_only.go +++ b/testdata/goldens/multiple_functions_with_only.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFooFilter(t *testing.T) { @@ -24,8 +23,8 @@ func TestFooFilter(t *testing.T) { t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. FooFilter() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/multiple_functions_with_only_cmp.go b/testdata/goldens/multiple_functions_with_only_cmp.go new file mode 100644 index 0000000..ede0373 --- /dev/null +++ b/testdata/goldens/multiple_functions_with_only_cmp.go @@ -0,0 +1,49 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFooFilter(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := FooFilter(tt.args.strs) + if (err != nil) != tt.wantErr { + t.Errorf("%q. FooFilter() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. FooFilter() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} + +func Test_bazFilter(t *testing.T) { + type args struct { + f *float64 + } + tests := []struct { + name string + args args + want float64 + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := bazFilter(tt.args.f); got != tt.want { + t.Errorf("%q. bazFilter() = %v, want %v", tt.name, got, tt.want) + } + } +} diff --git a/testdata/goldens/multiple_named_results.go b/testdata/goldens/multiple_named_results.go index d1ea457..6f99408 100644 --- a/testdata/goldens/multiple_named_results.go +++ b/testdata/goldens/multiple_named_results.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestFoo26(t *testing.T) { @@ -32,8 +31,8 @@ func TestFoo26(t *testing.T) { if gotI != tt.wantI { t.Errorf("%q. Foo26() gotI = %v, want %v", tt.name, gotI, tt.wantI) } - if !cmp.Equal(got2, tt.want2) { - t.Errorf("%q. Foo26() got2 = %v, want %v\ndiff=%s", tt.name, got2, tt.want2, cmp.Diff(got2, tt.want2)) + if !reflect.DeepEqual(got2, tt.want2) { + t.Errorf("%q. Foo26() got2 = %v, want %v", tt.name, got2, tt.want2) } } } diff --git a/testdata/goldens/multiple_named_results_cmp.go b/testdata/goldens/multiple_named_results_cmp.go new file mode 100644 index 0000000..971b741 --- /dev/null +++ b/testdata/goldens/multiple_named_results_cmp.go @@ -0,0 +1,39 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestFoo26(t *testing.T) { + type args struct { + v interface{} + } + tests := []struct { + name string + args args + want string + wantI int + want2 []byte + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, gotI, got2, err := Foo26(tt.args.v) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo26() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Foo26() got = %v, want %v", tt.name, got, tt.want) + } + if gotI != tt.wantI { + t.Errorf("%q. Foo26() gotI = %v, want %v", tt.name, gotI, tt.wantI) + } + if !cmp.Equal(tt.want2, got2) { + t.Errorf("%q. Foo26() got2 = %v, want %v\ndiff=%s", tt.name, got2, tt.want2, cmp.Diff(tt.want2, got2)) + } + } +} diff --git a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go index 2e364b4..44449cc 100644 --- a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go +++ b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names.go @@ -2,9 +2,8 @@ package testdata import ( "go/types" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestImporter_Foo35(t *testing.T) { @@ -28,8 +27,8 @@ func TestImporter_Foo35(t *testing.T) { Importer: tt.fields.Importer, Field: tt.fields.Field, } - if got := i.Foo35(tt.args.t); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Importer.Foo35() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := i.Foo35(tt.args.t); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Importer.Foo35() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/receiver_struct_with_fields_with_complex_package_names_cmp.go b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names_cmp.go new file mode 100644 index 0000000..2a50271 --- /dev/null +++ b/testdata/goldens/receiver_struct_with_fields_with_complex_package_names_cmp.go @@ -0,0 +1,35 @@ +package testdata + +import ( + "go/types" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestImporter_Foo35(t *testing.T) { + type fields struct { + Importer types.Importer + Field *types.Var + } + type args struct { + t types.Type + } + tests := []struct { + name string + fields fields + args args + want *types.Var + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + i := &Importer{ + Importer: tt.fields.Importer, + Field: tt.fields.Field, + } + if got := i.Foo35(tt.args.t); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Importer.Foo35() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/struct_value_method_with_struct_value_return_type.go b/testdata/goldens/struct_value_method_with_struct_value_return_type.go index ebcdd15..c5e7074 100644 --- a/testdata/goldens/struct_value_method_with_struct_value_return_type.go +++ b/testdata/goldens/struct_value_method_with_struct_value_return_type.go @@ -1,9 +1,8 @@ package testdata import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestBar_Foo9(t *testing.T) { @@ -16,8 +15,8 @@ func TestBar_Foo9(t *testing.T) { } for _, tt := range tests { b := Bar{} - if got := b.Foo9(); !cmp.Equal(got, tt.want) { - t.Errorf("%q. Bar.Foo9() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if got := b.Foo9(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Bar.Foo9() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/struct_value_method_with_struct_value_return_type_cmp.go b/testdata/goldens/struct_value_method_with_struct_value_return_type_cmp.go new file mode 100644 index 0000000..dda6463 --- /dev/null +++ b/testdata/goldens/struct_value_method_with_struct_value_return_type_cmp.go @@ -0,0 +1,23 @@ +package testdata + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBar_Foo9(t *testing.T) { + tests := []struct { + name string + b Bar + want Bar + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := Bar{} + if got := b.Foo9(); !cmp.Equal(tt.want, got) { + t.Errorf("%q. Bar.Foo9() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/goldens/target_test_file.go b/testdata/goldens/target_test_file.go index 41fd03d..74fb6fb 100644 --- a/testdata/goldens/target_test_file.go +++ b/testdata/goldens/target_test_file.go @@ -2,9 +2,8 @@ package testdata import ( "fmt" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestBarBar100(t *testing.T) { @@ -68,8 +67,8 @@ func Test_wrapToString(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := wrapToString(tt.args.in); !reflect.DeepEqual(got, tt.want) { + t.Errorf("wrapToString() = %v, want %v", got, tt.want) } }) } diff --git a/testdata/goldens/target_test_file_cmp.go b/testdata/goldens/target_test_file_cmp.go new file mode 100644 index 0000000..ba2c3fc --- /dev/null +++ b/testdata/goldens/target_test_file_cmp.go @@ -0,0 +1,76 @@ +package testdata + +import ( + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBarBar100(t *testing.T) { + tests := []struct { + name string + b *Bar + i interface{} + wantErr bool + }{ + { + name: "Basic test", + b: &Bar{}, + wantErr: true, + }, + } + for _, tt := range tests { + if err := tt.b.Bar100(tt.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func TestBaz100(t *testing.T) { + tests := []struct { + name string + f *float64 + want float64 + }{ + { + name: "Basic test", + f: func() *float64 { var x float64 = 64; return &x }(), + want: 64, + }, + } + // TestBaz100 contains a comment. + for _, tt := range tests { + if got := baz100(tt.f); got != tt.want { + t.Errorf("%q. baz100() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func wrapToString(in []int) []string { + var result []string + for _, x := range in { + result = append(result, fmt.Sprintf("%v", x)) + } + return result +} + +func Test_wrapToString(t *testing.T) { + type args struct { + in []int + } + tests := []struct { + name string + args args + want []string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := wrapToString(tt.args.in); !cmp.Equal(tt.want, got) { + t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) + } + }) + } +} diff --git a/testdata/goldens/target_test_file_without_only_flag.go b/testdata/goldens/target_test_file_without_only_flag.go index 41fd03d..74fb6fb 100644 --- a/testdata/goldens/target_test_file_without_only_flag.go +++ b/testdata/goldens/target_test_file_without_only_flag.go @@ -2,9 +2,8 @@ package testdata import ( "fmt" + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestBarBar100(t *testing.T) { @@ -68,8 +67,8 @@ func Test_wrapToString(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := wrapToString(tt.args.in); !cmp.Equal(got, tt.want) { - t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(got, tt.want)) + if got := wrapToString(tt.args.in); !reflect.DeepEqual(got, tt.want) { + t.Errorf("wrapToString() = %v, want %v", got, tt.want) } }) } diff --git a/testdata/goldens/target_test_file_without_only_flag_cmp.go b/testdata/goldens/target_test_file_without_only_flag_cmp.go new file mode 100644 index 0000000..ba2c3fc --- /dev/null +++ b/testdata/goldens/target_test_file_without_only_flag_cmp.go @@ -0,0 +1,76 @@ +package testdata + +import ( + "fmt" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestBarBar100(t *testing.T) { + tests := []struct { + name string + b *Bar + i interface{} + wantErr bool + }{ + { + name: "Basic test", + b: &Bar{}, + wantErr: true, + }, + } + for _, tt := range tests { + if err := tt.b.Bar100(tt.i); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar100() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func TestBaz100(t *testing.T) { + tests := []struct { + name string + f *float64 + want float64 + }{ + { + name: "Basic test", + f: func() *float64 { var x float64 = 64; return &x }(), + want: 64, + }, + } + // TestBaz100 contains a comment. + for _, tt := range tests { + if got := baz100(tt.f); got != tt.want { + t.Errorf("%q. baz100() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func wrapToString(in []int) []string { + var result []string + for _, x := range in { + result = append(result, fmt.Sprintf("%v", x)) + } + return result +} + +func Test_wrapToString(t *testing.T) { + type args struct { + in []int + } + tests := []struct { + name string + args args + want []string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := wrapToString(tt.args.in); !cmp.Equal(tt.want, got) { + t.Errorf("wrapToString() = %v, want %v\ndiff=%s", got, tt.want, cmp.Diff(tt.want, got)) + } + }) + } +} diff --git a/testdata/goldens/undefined_types.go b/testdata/goldens/undefined_types.go index 8a99e21..3e8dfd5 100644 --- a/testdata/goldens/undefined_types.go +++ b/testdata/goldens/undefined_types.go @@ -1,9 +1,8 @@ package undefinedtypes import ( + "reflect" "testing" - - "github.com/google/go-cmp/cmp" ) func TestUndefined_Do(t *testing.T) { @@ -25,8 +24,8 @@ func TestUndefined_Do(t *testing.T) { t.Errorf("%q. Undefined.Do() error = %v, wantErr %v", tt.name, err, tt.wantErr) continue } - if !cmp.Equal(got, tt.want) { - t.Errorf("%q. Undefined.Do() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(got, tt.want)) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Undefined.Do() = %v, want %v", tt.name, got, tt.want) } } } diff --git a/testdata/goldens/undefined_types_cmp.go b/testdata/goldens/undefined_types_cmp.go new file mode 100644 index 0000000..b229a4d --- /dev/null +++ b/testdata/goldens/undefined_types_cmp.go @@ -0,0 +1,32 @@ +package undefinedtypes + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestUndefined_Do(t *testing.T) { + type args struct { + es Something + } + tests := []struct { + name string + u *Undefined + args args + want *Unknown + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := tt.u.Do(tt.args.es) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Undefined.Do() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if !cmp.Equal(tt.want, got) { + t.Errorf("%q. Undefined.Do() = %v, want %v\ndiff=%s", tt.name, got, tt.want, cmp.Diff(tt.want, got)) + } + } +} diff --git a/testdata/templatedata/function.tmpl b/testdata/templatedata/function.tmpl index 91f9d5b..a1ec329 100644 --- a/testdata/templatedata/function.tmpl +++ b/testdata/templatedata/function.tmpl @@ -74,10 +74,18 @@ func {{.TestName}}(t *testing.T) { {{- 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}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { + {{- if $.UseGoCmp}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal(tt.{{Want .}}, {{Got .}}) { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { + {{- end}} + {{- end}} + {{- if $.UseGoCmp}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff(tt.{{Want .}}, {{Got .}}){{ end }}) + {{- else}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} - {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} diff --git a/testdata/use_template_params/function.tmpl b/testdata/use_template_params/function.tmpl index faa62ab..6ec0766 100644 --- a/testdata/use_template_params/function.tmpl +++ b/testdata/use_template_params/function.tmpl @@ -75,10 +75,18 @@ func {{.TestName}}(t *testing.T) { {{- 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}} !cmp.Equal({{Got .}}, tt.{{Want .}}) { + {{- if $.UseGoCmp}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !cmp.Equal(tt.{{Want .}}, {{Got .}}) { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, tt.{{Want .}}) { + {{- end}} + {{- end}} + {{- if $.UseGoCmp}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} + {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff(tt.{{Want .}}, {{Got .}}){{ end }}) + {{- else}} + t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}}) {{- end}} - t.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v{{ if (not ( or .IsWriter .IsBasicType))}}\ndiff=%s{{ end }}", {{template "inputs" $f}} {{Got .}}, tt.{{Want .}} - {{- if (not ( or .IsWriter .IsBasicType))}}, cmp.Diff({{Got .}}, tt.{{Want .}}){{ end }}) } {{- end}} {{- if .Subtests }} }) {{- end -}} From 2ecd7a07e541ebb55547f634e6cd777b949cca9b Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Sun, 13 Mar 2022 00:18:37 +0100 Subject: [PATCH 5/7] Fix missing `named` flag in README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a7c478e..a0743ac 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ Available options: -i print test inputs in error messages + -named switch table tests from using slice to map (with test name for the key) + -only regexp. generate tests for functions and methods that match only. Takes precedence over -all From 2156f8070c85bbe11dad7f2a1525a380fb93df1f Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Sun, 13 Mar 2022 00:20:31 +0100 Subject: [PATCH 6/7] Fix typo in `reflect.DeepEqual` --- README.md | 2 +- gotests/main.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a0743ac..8c1ae8f 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Available options: -template_params read external parameters to template by json with stdin - -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals + -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEqual ``` ## Contributions diff --git a/gotests/main.go b/gotests/main.go index 94f7ec1..d252186 100644 --- a/gotests/main.go +++ b/gotests/main.go @@ -41,7 +41,7 @@ // // -template_params read external parameters to template by json with stdin // -// -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals +// -use_go_cmp use cmp.Equal (google/go-cmp) instead of reflect.DeepEqual package main import ( @@ -62,7 +62,7 @@ var ( template = flag.String("template", "", `optional. Specify custom test code templates, e.g. testify. This can also be set via environment variable GOTESTS_TEMPLATE`) templateParamsPath = flag.String("template_params_file", "", "read external parameters to template by json with file") templateParams = flag.String("template_params", "", "read external parameters to template by json with stdin") - useGoCmp = flag.Bool("use_go_cmp", false, `use cmp.Equal (google/go-cmp) instead of reflect.DeepEquals to perform equality checks`) + useGoCmp = flag.Bool("use_go_cmp", false, `use cmp.Equal (google/go-cmp) instead of reflect.DeepEqual to perform equality checks`) ) var ( From 3ad4a929b234a51fd267c0a2cf1b5689a3f7abac Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Sun, 13 Mar 2022 11:38:17 +0100 Subject: [PATCH 7/7] Remove old Go version (temporarily) --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3f1b9d5..f23c7bb 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ 1.16.x, 1.15.x, 1.14.x, 1.13.x, 1.12.x, 1.11.x, 1.10.x, 1.9.x ] + go: [ 1.17.x, 1.16.x, 1.15.x, 1.14.x] env: GOPATH: ${{ github.workspace }} GO111MODULE: auto