diff --git a/gotests.go b/gotests.go index 9a9b004..2f52507 100644 --- a/gotests.go +++ b/gotests.go @@ -18,13 +18,14 @@ import ( // Options provides custom filters and parameters for generating tests. type Options struct { - Only *regexp.Regexp // Includes only functions that match. - Exclude *regexp.Regexp // Excludes functions that match. - Exported bool // Include only exported methods - PrintInputs bool // Print function parameters in error messages - Subtests bool // Print tests using Go 1.7 subtests - Importer func() types.Importer // A custom importer. - TemplateDir string // Path to custom template set + Only *regexp.Regexp // Includes only functions that match. + Exclude *regexp.Regexp // Excludes functions that match. + Exported bool // Include only exported methods + PrintInputs bool // Print function parameters in error messages + Subtests bool // Print tests using Go 1.7 subtests + Importer func() types.Importer // A custom importer. + TemplateDir string // Path to custom template set + WithBenchmark bool // Generate benchmark for function and methods } // A GeneratedTest contains information about a test file with generated tests. @@ -115,9 +116,10 @@ func generateTest(src models.Path, files []models.Path, opt *Options) (*Generate return nil, nil } b, err := output.Process(h, funcs, &output.Options{ - PrintInputs: opt.PrintInputs, - Subtests: opt.Subtests, - TemplateDir: opt.TemplateDir, + PrintInputs: opt.PrintInputs, + Subtests: opt.Subtests, + TemplateDir: opt.TemplateDir, + WithBenchmark: opt.WithBenchmark, }) if err != nil { return nil, fmt.Errorf("output.Process: %v", err) diff --git a/gotests/main.go b/gotests/main.go index d9aaa14..707a504 100644 --- a/gotests/main.go +++ b/gotests/main.go @@ -35,13 +35,14 @@ import ( ) var ( - onlyFuncs = flag.String("only", "", `regexp. generate tests for functions and methods that match only. Takes precedence over -all`) - exclFuncs = flag.String("excl", "", `regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all`) - exportedFuncs = flag.Bool("exported", false, `generate tests for exported functions and methods. Takes precedence over -only and -all`) - allFuncs = flag.Bool("all", false, "generate tests for all functions and methods") - printInputs = flag.Bool("i", false, "print test inputs in error messages") - writeOutput = flag.Bool("w", false, "write output to (test) files instead of stdout") - templateDir = flag.String("template_dir", "", `optional. Path to a directory containing custom test code templates`) + onlyFuncs = flag.String("only", "", `regexp. generate tests for functions and methods that match only. Takes precedence over -all`) + exclFuncs = flag.String("excl", "", `regexp. generate tests for functions and methods that don't match. Takes precedence over -only, -exported, and -all`) + exportedFuncs = flag.Bool("exported", false, `generate tests for exported functions and methods. Takes precedence over -only and -all`) + allFuncs = flag.Bool("all", false, "generate tests for all functions and methods") + printInputs = flag.Bool("i", false, "print test inputs in error messages") + writeOutput = flag.Bool("w", false, "write output to (test) files instead of stdout") + templateDir = flag.String("template_dir", "", `optional. Path to a directory containing custom test code templates`) + withBenchmarks = flag.Bool("b", false, "generate benchmarks for functions and methods") ) // nosubtests is always set to default value of true when Go < 1.7. @@ -62,5 +63,6 @@ func main() { Subtests: !nosubtests, WriteOutput: *writeOutput, TemplateDir: *templateDir, + WithBenchmark: *withBenchmarks, }) } diff --git a/gotests/process/process.go b/gotests/process/process.go index af9dd8f..5f32e26 100644 --- a/gotests/process/process.go +++ b/gotests/process/process.go @@ -25,6 +25,7 @@ type Options struct { Subtests bool // Print tests using Go 1.7 subtests WriteOutput bool // Write output to test file(s). TemplateDir string // Path to custom template set + WithBenchmark bool // Print benchmarks. } // Generates tests for the Go files defined in args with the given options. @@ -63,12 +64,13 @@ func parseOptions(out io.Writer, opt *Options) *gotests.Options { return nil } return &gotests.Options{ - Only: onlyRE, - Exclude: exclRE, - Exported: opt.ExportedFuncs, - PrintInputs: opt.PrintInputs, - Subtests: opt.Subtests, - TemplateDir: opt.TemplateDir, + Only: onlyRE, + Exclude: exclRE, + Exported: opt.ExportedFuncs, + PrintInputs: opt.PrintInputs, + Subtests: opt.Subtests, + TemplateDir: opt.TemplateDir, + WithBenchmark: opt.WithBenchmark, } } diff --git a/gotests_test.go b/gotests_test.go index 7e38ac7..5f1f8b1 100644 --- a/gotests_test.go +++ b/gotests_test.go @@ -607,6 +607,387 @@ func TestGenerateTests(t *testing.T) { } } +func TestGenerateBenchmarks(t *testing.T) { + type args struct { + srcPath string + only *regexp.Regexp + excl *regexp.Regexp + exported bool + printInputs bool + subtests bool + withBenchmark bool + importer types.Importer + templateDir string + } + tests := []struct { + name string + args args + want string + wantNoTests bool + wantMultipleTests bool + wantErr bool + }{ + { + name: "Blank Go file", + args: args{ + srcPath: `testdata/blankfile/blank.go`, + withBenchmark: true, + }, + wantNoTests: true, + wantErr: true, + }, { + name: "Blank Go file in directory", + args: args{ + srcPath: `testdata/blankfile/notblank.go`, + withBenchmark: true, + }, + wantNoTests: true, + wantErr: true, + }, { + name: "Test file with garbage data", + args: args{ + srcPath: `testdata/invalidtest/invalid.go`, + withBenchmark: true, + }, + wantNoTests: true, + wantErr: true, + }, { + name: "Hidden file", + args: args{ + srcPath: `testdata/.hidden.go`, + withBenchmark: true, + }, + wantNoTests: true, + wantErr: true, + }, { + name: "Nonexistant file", + args: args{ + srcPath: `testdata/nonexistant.go`, + withBenchmark: true, + }, + wantNoTests: true, + wantErr: true, + }, { + name: "Target test file", + args: args{ + srcPath: `testdata/test103_test.go`, + withBenchmark: true, + templateDir: `internal/render/templates/`, + only: regexp.MustCompile("wrapToString"), + subtests: true, + }, + wantNoTests: false, + wantErr: false, + want: mustReadFile(t, `testdata/goldens/target_test_file_with_benchmark.go`), + }, { + name: "Target test file without only flag", + args: args{ + srcPath: `testdata/test103_test.go`, + withBenchmark: true, + subtests: true, + }, + wantNoTests: false, + wantErr: false, + want: mustReadFile(t, `testdata/goldens/target_test_file_with_benchmark.go`), + }, { + name: "No funcs", + args: args{ + srcPath: `testdata/test000.go`, + withBenchmark: true, + }, + wantNoTests: true, + }, { + name: "Function with neither receiver, parameters, nor results", + args: args{ + srcPath: `testdata/test001.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_neither_receiver_parameters_nor_results_with_benchmark.go"), + }, { + name: "Function with anonymous arguments", + args: args{ + srcPath: `testdata/test002.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_anonymous_arguments_with_benchmark.go"), + }, { + name: "Function with named argument", + args: args{ + srcPath: `testdata/test003.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_named_argument_with_benchmark.go"), + }, { + name: "Function with return value", + args: args{ + srcPath: `testdata/test004.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_return_value_with_benchmark.go"), + }, { + name: "Function returning an error", + args: args{ + srcPath: `testdata/test005.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_returning_an_error_with_benchmark.go"), + }, { + name: "Function with multiple arguments", + args: args{ + srcPath: `testdata/test006.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_multiple_arguments_with_benchmark.go"), + }, { + name: "Print inputs with multiple arguments", + args: args{ + srcPath: `testdata/test006.go`, + withBenchmark: true, + printInputs: true, + }, + want: mustReadFile(t, "testdata/goldens/print_inputs_with_multiple_arguments_with_benchmark.go"), + }, { + name: "Method on a struct pointer", + args: args{ + srcPath: `testdata/test007.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/method_on_a_struct_pointer_with_benchmark.go"), + }, { + name: "Print inputs with single argument", + args: args{ + srcPath: `testdata/test007.go`, + withBenchmark: true, + printInputs: true, + }, + want: mustReadFile(t, "testdata/goldens/print_inputs_with_single_argument_with_benchmark.go"), + }, { + name: "Function with struct pointer argument and return type", + args: args{ + srcPath: `testdata/test008.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_struct_pointer_argument_and_return_type_with_benchmark.go"), + }, { + name: "Struct value method with struct value return type", + args: args{ + srcPath: `testdata/test009.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/struct_value_method_with_struct_value_return_type_with_benchmark.go"), + }, { + name: "Function with map argument and return type", + args: args{ + srcPath: `testdata/test010.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_map_argument_and_return_type_with_benchmark.go"), + }, { + name: "Function with slice argument and return type", + args: args{ + srcPath: `testdata/test011.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_slice_argument_and_return_type_with_benchmark.go"), + }, { + name: "Function returning only an error", + args: args{ + srcPath: `testdata/test012.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_returning_only_an_error_with_benchmark.go"), + }, { + name: "Function with a function parameter", + args: args{ + srcPath: `testdata/test013.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_a_function_parameter_with_benchmark.go"), + }, { + name: "Function with a function parameter with its own parameters and result", + args: args{ + srcPath: `testdata/test014.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_a_function_parameter_with_its_own_parameters_and_result_with_benchmark.go"), + }, { + name: "Function with a function parameter that returns two results", + args: args{ + srcPath: `testdata/test015.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_a_function_parameter_that_returns_two_results_with_benchmark.go"), + }, { + name: "Function with defined interface type parameter and result", + args: args{ + srcPath: `testdata/test016.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_defined_interface_type_parameter_and_result_with_benchmark.go"), + }, { + name: "Function with imported interface receiver, parameter, and result", + args: args{ + srcPath: `testdata/test017.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_with_benchmark.go"), + }, { + name: "Function with imported struct receiver, parameter, and result", + args: args{ + srcPath: `testdata/test018.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_with_benchmark.go"), + }, { + name: "Function with multiple parameters of the same type", + args: args{ + srcPath: `testdata/test019.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_multiple_parameters_of_the_same_type_with_benchmark.go"), + }, { + name: "Function with a variadic parameter", + args: args{ + srcPath: `testdata/test020.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_a_variadic_parameter_with_benchmark.go"), + }, { + name: "Function with interface{} parameter and result", + args: args{ + srcPath: `testdata/test021.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_interface_parameter_and_result_with_benchmark.go"), + }, { + name: "Function with named imports", + args: args{ + srcPath: `testdata/test022.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_named_imports_with_benchmark.go"), + }, { + name: "Function with channel parameter and result", + args: args{ + srcPath: `testdata/test023.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_with_channel_parameter_and_result_with_benchmark.go"), + }, { + name: "File with multiple imports", + args: args{ + srcPath: `testdata/test024.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/file_with_multiple_imports_with_benchmark.go"), + }, { + name: "Function returning two results and an error", + args: args{ + srcPath: `testdata/test025.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/function_returning_two_results_and_an_error_with_benchmark.go"), + }, { + name: "Multiple named results", + args: args{ + srcPath: `testdata/test026.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/multiple_named_results_with_benchmark.go"), + }, { + name: "Two different structs with same method name", + args: args{ + srcPath: `testdata/test027.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/two_different_structs_with_same_method_name_with_benchmark.go"), + }, { + name: "Underlying types", + args: args{ + srcPath: `testdata/test028.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/underlying_types_with_benchmark.go"), + }, { + name: "Struct receiver with multiple fields", + args: args{ + srcPath: `testdata/test029.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/struct_receiver_with_multiple_fields_with_benchmark.go"), + }, { + name: "Struct receiver with anonymous fields", + args: args{ + srcPath: `testdata/test030.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/struct_receiver_with_anonymous_fields_with_benchmark.go"), + }, { + name: "io.Writer parameters", + args: args{ + srcPath: `testdata/test031.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/io_writer_parameters_with_benchmark.go"), + }, { + name: "Two structs with same method name", + args: args{ + srcPath: `testdata/test032.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/two_structs_with_same_method_name_with_benchmark.go"), + }, { + name: "Functions and methods with 'name' receivers, parameters, and results", + args: args{ + srcPath: `testdata/test033.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/functions_and_methods_with_name_receivers_parameters_and_results_with_benchmark.go"), + }, { + name: "Receiver struct with reserved field names", + args: args{ + srcPath: `testdata/test034.go`, + withBenchmark: true, + }, + want: mustReadFile(t, "testdata/goldens/receiver_struct_with_reserved_field_names_with_benchmark.go"), + }, + } + tmp, err := ioutil.TempDir("", "gotests_test") + if err != nil { + t.Fatalf("ioutil.TempDir: %v", err) + } + for _, tt := range tests { + gts, err := GenerateTests(tt.args.srcPath, &Options{ + Only: tt.args.only, + Exclude: tt.args.excl, + Exported: tt.args.exported, + PrintInputs: tt.args.printInputs, + Subtests: tt.args.subtests, + Importer: func() types.Importer { return tt.args.importer }, + TemplateDir: tt.args.templateDir, + WithBenchmark: tt.args.withBenchmark, + }) + if (err != nil) != tt.wantErr { + t.Errorf("%q. GenerateTests(%v) error = %v, wantErr %v", tt.name, tt.args.srcPath, err, tt.wantErr) + continue + } + if (len(gts) == 0) != tt.wantNoTests { + t.Errorf("%q. GenerateTests(%v) returned no tests", tt.name, tt.args.srcPath) + continue + } + if (len(gts) > 1) != tt.wantMultipleTests { + t.Errorf("%q. GenerateTests(%v) returned too many tests", tt.name, tt.args.srcPath) + continue + } + if tt.wantNoTests || tt.wantMultipleTests { + continue + } + if got := string(gts[0].Output); ignoreTabs(got) != ignoreTabs(tt.want) { + t.Errorf("%q. GenerateTests(%v) = \n%v, want \n%v", tt.name, tt.args.srcPath, got, tt.want) + outputResult(t, tmp, tt.name, gts[0].Output) + } + } +} func mustReadFile(t *testing.T, filename string) string { b, err := ioutil.ReadFile(filename) if err != nil { diff --git a/internal/input/input.go b/internal/input/input.go index 4496c17..e278a23 100644 --- a/internal/input/input.go +++ b/internal/input/input.go @@ -2,9 +2,9 @@ package input import ( "fmt" + "os" "path" "path/filepath" - "os" "github.com/cweill/gotests/internal/models" ) diff --git a/internal/models/models.go b/internal/models/models.go index 8e58395..52e70a9 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -127,7 +127,18 @@ func (f *Function) FullName() string { } func (f *Function) TestName() string { - if strings.HasPrefix(f.Name, "Test") { + return f.functionName("Test") +} + +func (f *Function) BenchmarkName() string { + return f.functionName("Benchmark") +} + +// functionName will return this function's name depending on +// args t. t is the type of function, t's value is one of "Benchmark" +// "Test" +func (f *Function) functionName(t string) string { + if strings.HasPrefix(f.Name, t) { return f.Name } if f.Receiver != nil { @@ -135,12 +146,12 @@ func (f *Function) TestName() string { if unicode.IsLower([]rune(receiverType)[0]) { receiverType = "_" + receiverType } - return "Test" + receiverType + "_" + f.Name + return t + receiverType + "_" + f.Name } if unicode.IsLower([]rune(f.Name)[0]) { - return "Test_" + f.Name + return t + "_" + f.Name } - return "Test" + f.Name + return t + f.Name } func (f *Function) IsNaked() bool { diff --git a/internal/output/output.go b/internal/output/output.go index 581dff7..16cd9ca 100644 --- a/internal/output/output.go +++ b/internal/output/output.go @@ -15,9 +15,10 @@ import ( ) type Options struct { - PrintInputs bool - Subtests bool - TemplateDir string + PrintInputs bool + Subtests bool + TemplateDir string + WithBenchmark bool } func Process(head *models.Header, funcs []*models.Function, opt *Options) ([]byte, error) { @@ -35,7 +36,7 @@ func Process(head *models.Header, funcs []*models.Function, opt *Options) ([]byt defer tf.Close() defer os.Remove(tf.Name()) b := &bytes.Buffer{} - if err := writeTests(b, head, funcs, opt); err != nil { + if err := writeAll(b, head, funcs, opt); err != nil { return nil, err } out, err := imports.Process(tf.Name(), b.Bytes(), nil) @@ -50,7 +51,9 @@ func IsFileExist(path string) bool { return !os.IsNotExist(err) } -func writeTests(w io.Writer, head *models.Header, funcs []*models.Function, opt *Options) error { +// writeAll write tests, benchmarks, examples to output +// but now support tests and benchmarks +func writeAll(w io.Writer, head *models.Header, funcs []*models.Function, opt *Options) error { b := bufio.NewWriter(w) if err := render.Header(b, head); err != nil { return fmt.Errorf("render.Header: %v", err) @@ -59,6 +62,11 @@ func writeTests(w io.Writer, head *models.Header, funcs []*models.Function, opt if err := render.TestFunction(b, fun, opt.PrintInputs, opt.Subtests); err != nil { return fmt.Errorf("render.TestFunction: %v", err) } + if opt.WithBenchmark { + if err := render.BenchmarkFunction(b, fun, opt.PrintInputs, opt.Subtests); err != nil { + return fmt.Errorf("render.BenchmarkFunction: %v", err) + } + } } return b.Flush() } diff --git a/internal/render/bindata/bindata.go b/internal/render/bindata/bindata.go index 6a0d5f8..dc337ee 100644 --- a/internal/render/bindata/bindata.go +++ b/internal/render/bindata/bindata.go @@ -7,6 +7,7 @@ // templates/inputs.tmpl // templates/message.tmpl // templates/results.tmpl +// templates/benchmark.tmpl // DO NOT EDIT! package bindata @@ -214,6 +215,26 @@ func templatesResultsTmpl() (*asset, error) { return a, nil } +var _templatesBenchmarkTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x56\xc1\x4e\xeb\x38\x14\x5d\x27\x5f\x71\xa9\x00\xa5\xa3\x62\xf6\x45\x5d\x4c\x05\x33\x9a\xc5\xd0\x51\x41\xc3\x62\x34\x7a\x72\xd2\x9b\x62\xe1\xba\x7d\xb6\x03\xaa\x2c\xff\xfb\x93\x1d\x27\x71\xd2\x94\xc7\xe6\xb1\xa0\xcd\x8d\x7d\xcf\xf1\xb9\xe7\x18\x8c\xd9\x60\xc9\x04\xc2\x24\x47\x51\xbc\xee\xa8\x7c\x9b\x58\x9b\x1a\x73\x03\x97\x25\xcc\x17\x40\xac\x4d\xd3\xb2\x12\x05\x18\x43\x96\xcd\x9a\x47\xba\x43\x6b\xb3\x1c\x7e\xd3\xa8\x34\x13\x5b\xb2\x9c\x82\x49\x13\xb7\xef\x83\xe9\x57\x20\x6b\x2c\x90\xbd\xa3\xb4\x36\x4d\x7c\x99\x95\x40\xfe\x52\x4f\x5a\x56\x85\xf6\xc5\xb6\xfa\x07\x43\xbe\x51\x75\x2d\xd1\xc7\x03\x42\xe9\x2b\xa0\xfc\x62\xd7\x37\xac\x96\x54\x6c\x71\xb0\x21\x31\xc6\x3f\x3b\xa6\x8e\xe3\xf3\xf1\x80\xe1\x95\xdb\x82\x62\x13\x9e\x5a\xcc\xa6\x14\x7d\x1f\x7c\x75\xac\x9e\x51\xe9\x7f\xa8\xa4\x3b\xd4\x28\x3d\x98\xa7\x46\xe5\xb6\x47\x2c\xa2\x75\xba\xc3\x03\xfa\xd2\x09\xbb\x08\xb1\x8f\xdf\xce\x41\x39\xf9\xff\xfb\x3f\xc2\x12\x74\x87\x0e\x9b\x89\x6d\xe8\x30\xa2\x75\x73\x00\x2a\x36\x9d\xe0\x03\xcd\x82\xbe\xf5\x47\x2b\x0b\x57\x9d\x70\x4d\xcb\x53\x55\xcf\x28\xf8\x89\x6e\x49\xe2\x45\x73\xbf\x46\xf6\x44\xe2\xad\x51\x55\x5c\xab\x06\xe7\x85\x0a\xfd\x99\x6e\x2d\xe4\x1a\x75\x25\x85\x7a\x90\x72\x1f\x34\xf8\xa0\x42\x3f\x48\x09\xf9\x7e\xcf\x07\x62\x3b\x21\x6f\x6f\xe1\x79\x75\xbf\x9a\xc3\xef\x9b\x0d\xb4\x82\x43\x41\x15\x2a\xe2\x07\x52\xee\x25\x18\xc3\x4a\x10\x7b\xed\x64\x7c\xa4\x6f\xb8\xb1\x16\xbe\xcd\x20\xcf\xdd\x60\x8c\xf1\x0d\x03\xfd\x68\x68\x26\x85\xf0\xd3\xd0\x7b\xaa\x72\x97\x12\x05\xd6\xe6\x64\x5d\x89\x2c\xcf\x89\x1b\xe5\x0c\x5c\xae\x32\xdd\x0f\x11\x04\xb2\x70\xd3\xe9\x3d\x36\xe6\x33\xa1\x3a\x19\x9e\xe7\xea\x07\x73\x3c\xa0\x5f\x4c\xa5\xb5\xd7\x81\x7f\x90\x96\xfc\x4b\x79\x85\xd6\x9a\xa6\xc5\x99\xac\x25\xc6\x90\x3a\xfb\x73\xc8\x73\x52\x1b\x88\x44\x09\x9c\x75\x0d\xba\xe4\x25\x23\x71\x3c\x79\x08\x78\x23\x01\x6a\x8e\xf9\x22\x99\x6e\x4f\xdf\x0b\xd6\x7c\x01\xd7\xf9\x51\xa3\x22\xcb\xaa\x2c\x51\x9a\xaf\x00\x86\x8c\x64\x7e\xc2\x2b\xc1\x8f\xb1\x8d\xa6\xa7\xf5\x95\x40\xaf\xd2\x14\x5a\x66\x1a\x77\x07\x4e\x35\xc2\x44\xd6\xd6\x9d\xc0\x65\xe9\x0d\xdb\xbd\x29\x28\xe7\x75\xf9\x1c\x8b\x11\xff\x26\xac\x0c\x53\x1b\x12\xb3\x16\x50\xca\x7a\xaa\x63\x20\x77\xad\x33\x33\xb7\xee\x62\x01\x82\xf1\xa9\xfb\xcc\x73\xd2\xc4\x22\x8c\x39\x27\xbe\x65\x99\x4d\xe2\x5e\x3b\x54\x8a\x6e\x31\x1c\x05\xdd\x0a\x58\xc0\xd5\xfb\x0c\x9a\xed\x57\xef\x93\x59\x0f\x9e\x89\x43\xd5\x1e\x1e\xa5\x9c\x45\x60\xd3\xce\x11\xcd\xf5\xd0\xcb\xb9\x7f\x37\x88\x89\xf4\x07\x36\xa6\xbe\x92\x8a\xbd\xd0\x4c\x54\x18\x0e\x36\xe6\xb0\x4f\x2d\x75\x0a\x79\xce\x53\x5e\xf5\x3f\xf7\xba\x0b\x4e\xeb\x31\xf2\xe4\xef\xdd\x6c\x7a\x17\x2d\xa9\x55\x8d\x6f\xaa\xce\x77\x5c\x61\xc0\x58\x52\xc5\x8a\xe8\xcf\x52\x3b\xdc\xcb\x72\xcc\x5f\x2e\x94\x3d\x0e\xb1\xce\x9c\x09\x1c\x0e\xfa\xcb\x7c\x7e\x11\xfe\x85\xc4\x92\x63\xa1\xc9\x3d\xe2\xe1\xe1\x7b\x45\x79\xd6\x76\x98\xf5\x09\x4d\x63\x46\xed\xf4\xbe\xe2\xc3\x86\x70\x20\xfb\x77\xc5\x35\x3b\xf0\x1e\xd9\xc0\xa7\xf3\xea\x4f\x8c\x7a\x96\xe4\xf9\x7f\x17\x06\x3e\x05\x77\xa0\xf8\xba\xb6\xa9\x4d\xd3\xc0\xe3\x47\x00\x00\x00\xff\xff\x86\x99\x29\xa5\x5b\x09\x00\x00") + +func templatesBenchmarkTmplBytes() ([]byte, error) { + return bindataRead( + _templatesBenchmarkTmpl, + "templates/benchmark.tmpl", + ) +} + +func templatesBenchmarkTmpl() (*asset, error) { + bytes, err := templatesBenchmarkTmplBytes() + if err != nil { + return nil, err + } + + info := bindataFileInfo{name: "templates/benchmark.tmpl", size: 2396, mode: os.FileMode(420), modTime: time.Unix(1479275664, 0)} + a := &asset{bytes: bytes, info: info} + return a, nil +} + // Asset loads and returns the asset for the given name. // It returns an error if the asset could not be found or // could not be loaded. @@ -266,13 +287,14 @@ func AssetNames() []string { // _bindata is a table, holding each asset generator, mapped to its name. var _bindata = map[string]func() (*asset, error){ - "templates/call.tmpl": templatesCallTmpl, - "templates/function.tmpl": templatesFunctionTmpl, - "templates/header.tmpl": templatesHeaderTmpl, - "templates/inline.tmpl": templatesInlineTmpl, - "templates/inputs.tmpl": templatesInputsTmpl, - "templates/message.tmpl": templatesMessageTmpl, - "templates/results.tmpl": templatesResultsTmpl, + "templates/call.tmpl": templatesCallTmpl, + "templates/function.tmpl": templatesFunctionTmpl, + "templates/header.tmpl": templatesHeaderTmpl, + "templates/inline.tmpl": templatesInlineTmpl, + "templates/inputs.tmpl": templatesInputsTmpl, + "templates/message.tmpl": templatesMessageTmpl, + "templates/results.tmpl": templatesResultsTmpl, + "templates/benchmark.tmpl": templatesBenchmarkTmpl, } // AssetDir returns the file names below a certain @@ -314,15 +336,17 @@ type bintree struct { Func func() (*asset, error) Children map[string]*bintree } + var _bintree = &bintree{nil, map[string]*bintree{ "templates": &bintree{nil, map[string]*bintree{ - "call.tmpl": &bintree{templatesCallTmpl, map[string]*bintree{}}, - "function.tmpl": &bintree{templatesFunctionTmpl, map[string]*bintree{}}, - "header.tmpl": &bintree{templatesHeaderTmpl, map[string]*bintree{}}, - "inline.tmpl": &bintree{templatesInlineTmpl, map[string]*bintree{}}, - "inputs.tmpl": &bintree{templatesInputsTmpl, map[string]*bintree{}}, - "message.tmpl": &bintree{templatesMessageTmpl, map[string]*bintree{}}, - "results.tmpl": &bintree{templatesResultsTmpl, map[string]*bintree{}}, + "call.tmpl": &bintree{templatesCallTmpl, map[string]*bintree{}}, + "function.tmpl": &bintree{templatesFunctionTmpl, map[string]*bintree{}}, + "header.tmpl": &bintree{templatesHeaderTmpl, map[string]*bintree{}}, + "inline.tmpl": &bintree{templatesInlineTmpl, map[string]*bintree{}}, + "inputs.tmpl": &bintree{templatesInputsTmpl, map[string]*bintree{}}, + "message.tmpl": &bintree{templatesMessageTmpl, map[string]*bintree{}}, + "results.tmpl": &bintree{templatesResultsTmpl, map[string]*bintree{}}, + "benchmark.tmpl": &bintree{templatesBenchmarkTmpl, map[string]*bintree{}}, }}, }} @@ -372,4 +396,3 @@ func _filePath(dir, name string) string { cannonicalName := strings.Replace(name, "\\", "/", -1) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) } - diff --git a/internal/render/render.go b/internal/render/render.go index d980b92..42cada8 100644 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -123,7 +123,15 @@ func Header(w io.Writer, h *models.Header) error { } func TestFunction(w io.Writer, f *models.Function, printInputs bool, subtests bool) error { - return tmpls.ExecuteTemplate(w, "function", struct { + return renderFunction(w, f, "function", printInputs, subtests) +} + +func BenchmarkFunction(w io.Writer, f *models.Function, printInputs bool, subtests bool) error { + return renderFunction(w, f, "benchmark", printInputs, subtests) +} + +func renderFunction(w io.Writer, f *models.Function, tmpl string, printInputs bool, subtests bool) error { + return tmpls.ExecuteTemplate(w, tmpl, struct { *models.Function PrintInputs bool Subtests bool diff --git a/internal/render/templates/benchmark.tmpl b/internal/render/templates/benchmark.tmpl new file mode 100644 index 0000000..bc2fb8c --- /dev/null +++ b/internal/render/templates/benchmark.tmpl @@ -0,0 +1,86 @@ +{{define "benchmark"}} +{{- $f := .}} + +func {{.BenchmarkName}}(b *testing.B) { + {{- with .Receiver}} + {{- if .IsStruct}} + {{- if .Fields}} + type fields struct { + {{- range .Fields}} + {{Field .}} {{.Type}} + {{- end}} + } + {{- end}} + {{- end}} + {{- end}} + {{- if .TestParameters}} + type args struct { + {{- range .TestParameters}} + {{Param .}} {{.Type}} + {{- end}} + } + {{- end}} + benchmarks := []struct { + name string + {{- with .Receiver}} + {{- if and .IsStruct .Fields}} + fields fields + {{- else}} + {{Receiver .}} {{.Type}} + {{- end}} + {{- end}} + {{- if .TestParameters}} + args args + {{- end}} + {{- range .TestResults}} + {{Want .}} {{.Type}} + {{- end}} + {{- if .ReturnsError}} + wantErr bool + {{- end}} + }{ + // TODO: Add benchmark cases. + } + for {{if not .IsNaked}} _, bb := {{end}} range benchmarks { + {{- if .Subtests }}b.Run(bb.name, func(t *testing.B) { {{- end -}} + {{- with .Receiver}} + {{- if .IsStruct}} + {{Receiver .}} := {{if .Type.IsStar}}&{{end}}{{.Type.Value}}{ + {{- range .Fields}} + {{.Name}}: bb.fields.{{Field .}}, + {{- end}} + } + {{- end}} + {{- end}} + {{- range .Parameters}} + {{- if .IsWriter}} + {{Param .}} := &bytes.Buffer{} + {{- end}} + {{- end}} + {{- if and (not .OnlyReturnsError) (not .OnlyReturnsOneValue) }} + {{template "results" $f}} {{template "call" $f}} + {{- end}} + {{- if .ReturnsError}} + if {{if .OnlyReturnsError}} err := {{template "call" $f}}; {{end}} (err != nil) != bb.wantErr { + b.Errorf("{{template "message" $f}} error = %v, wantErr %v", {{template "inputs" $f}} err, bb.wantErr) + {{- if .TestResults}} + {{if .Subtests }}return{{else}}continue{{end}} + {{- end}} + } + {{- end}} + {{- range .TestResults}} + {{- if .IsWriter}} + if {{Got .}} := {{Param .}}.String(); {{Got .}} != bb.{{Want .}} { + {{- else if .IsBasicType}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} {{Got .}} != bb.{{Want .}} { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, bb.{{Want .}}) { + {{- end}} + b.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, bb.{{Want .}}) + } + {{- end}} + {{- if .Subtests }} }) {{- end -}} + } +} + +{{end}} diff --git a/testdata/customtemplates/benchmark.tmpl b/testdata/customtemplates/benchmark.tmpl new file mode 100644 index 0000000..bc2fb8c --- /dev/null +++ b/testdata/customtemplates/benchmark.tmpl @@ -0,0 +1,86 @@ +{{define "benchmark"}} +{{- $f := .}} + +func {{.BenchmarkName}}(b *testing.B) { + {{- with .Receiver}} + {{- if .IsStruct}} + {{- if .Fields}} + type fields struct { + {{- range .Fields}} + {{Field .}} {{.Type}} + {{- end}} + } + {{- end}} + {{- end}} + {{- end}} + {{- if .TestParameters}} + type args struct { + {{- range .TestParameters}} + {{Param .}} {{.Type}} + {{- end}} + } + {{- end}} + benchmarks := []struct { + name string + {{- with .Receiver}} + {{- if and .IsStruct .Fields}} + fields fields + {{- else}} + {{Receiver .}} {{.Type}} + {{- end}} + {{- end}} + {{- if .TestParameters}} + args args + {{- end}} + {{- range .TestResults}} + {{Want .}} {{.Type}} + {{- end}} + {{- if .ReturnsError}} + wantErr bool + {{- end}} + }{ + // TODO: Add benchmark cases. + } + for {{if not .IsNaked}} _, bb := {{end}} range benchmarks { + {{- if .Subtests }}b.Run(bb.name, func(t *testing.B) { {{- end -}} + {{- with .Receiver}} + {{- if .IsStruct}} + {{Receiver .}} := {{if .Type.IsStar}}&{{end}}{{.Type.Value}}{ + {{- range .Fields}} + {{.Name}}: bb.fields.{{Field .}}, + {{- end}} + } + {{- end}} + {{- end}} + {{- range .Parameters}} + {{- if .IsWriter}} + {{Param .}} := &bytes.Buffer{} + {{- end}} + {{- end}} + {{- if and (not .OnlyReturnsError) (not .OnlyReturnsOneValue) }} + {{template "results" $f}} {{template "call" $f}} + {{- end}} + {{- if .ReturnsError}} + if {{if .OnlyReturnsError}} err := {{template "call" $f}}; {{end}} (err != nil) != bb.wantErr { + b.Errorf("{{template "message" $f}} error = %v, wantErr %v", {{template "inputs" $f}} err, bb.wantErr) + {{- if .TestResults}} + {{if .Subtests }}return{{else}}continue{{end}} + {{- end}} + } + {{- end}} + {{- range .TestResults}} + {{- if .IsWriter}} + if {{Got .}} := {{Param .}}.String(); {{Got .}} != bb.{{Want .}} { + {{- else if .IsBasicType}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} {{Got .}} != bb.{{Want .}} { + {{- else}} + if {{if $f.OnlyReturnsOneValue}}{{Got .}} := {{template "inline" $f}}; {{end}} !reflect.DeepEqual({{Got .}}, bb.{{Want .}}) { + {{- end}} + b.Errorf("{{template "message" $f}} {{if $f.ReturnsMultiple}}{{Got .}} {{end}}= %v, want %v", {{template "inputs" $f}} {{Got .}}, bb.{{Want .}}) + } + {{- end}} + {{- if .Subtests }} }) {{- end -}} + } +} + +{{end}} diff --git a/testdata/goldens/file_with_multiple_imports_with_benchmark.go b/testdata/goldens/file_with_multiple_imports_with_benchmark.go new file mode 100644 index 0000000..05084f3 --- /dev/null +++ b/testdata/goldens/file_with_multiple_imports_with_benchmark.go @@ -0,0 +1,48 @@ +package testdata + +import ( + "go/ast" + "go/types" + "io" + "testing" +) + +func TestFoo24(t *testing.T) { + type args struct { + r io.Reader + x ast.Expr + t types.Type + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if err := Foo24(tt.args.r, tt.args.x, tt.args.t); (err != nil) != tt.wantErr { + t.Errorf("%q. Foo24() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkFoo24(b *testing.B) { + type args struct { + r io.Reader + x ast.Expr + t types.Type + } + benchmarks := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if err := Foo24(tt.args.r, tt.args.x, tt.args.t); (err != nil) != bb.wantErr { + b.Errorf("%q. Foo24() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/function_returning_an_error_with_benchmark.go b/testdata/goldens/function_returning_an_error_with_benchmark.go new file mode 100644 index 0000000..1563eba --- /dev/null +++ b/testdata/goldens/function_returning_an_error_with_benchmark.go @@ -0,0 +1,43 @@ +package testdata + +import "testing" + +func TestFoo5(t *testing.T) { + tests := []struct { + name string + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo5() + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo5() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Foo5() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo5(b *testing.B) { + benchmarks := []struct { + name string + want string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, err := Foo5() + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo5() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Foo5() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_returning_only_an_error_with_benchmark.go b/testdata/goldens/function_returning_only_an_error_with_benchmark.go new file mode 100644 index 0000000..5726f2a --- /dev/null +++ b/testdata/goldens/function_returning_only_an_error_with_benchmark.go @@ -0,0 +1,39 @@ +package testdata + +import "testing" + +func TestFoo12(t *testing.T) { + type args struct { + str string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if err := Foo12(tt.args.str); (err != nil) != tt.wantErr { + t.Errorf("%q. Foo12() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkFoo12(b *testing.B) { + type args struct { + str string + } + benchmarks := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if err := Foo12(tt.args.str); (err != nil) != bb.wantErr { + b.Errorf("%q. Foo12() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/function_returning_two_results_and_an_error_with_benchmark.go b/testdata/goldens/function_returning_two_results_and_an_error_with_benchmark.go new file mode 100644 index 0000000..609e023 --- /dev/null +++ b/testdata/goldens/function_returning_two_results_and_an_error_with_benchmark.go @@ -0,0 +1,62 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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 !reflect.DeepEqual(got1, tt.want1) { + t.Errorf("%q. Foo25() got1 = %v, want %v", tt.name, got1, tt.want1) + } + } +} + +func BenchmarkFoo25(b *testing.B) { + type args struct { + in0 interface{} + } + benchmarks := []struct { + name string + args args + want string + want1 []byte + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, got1, err := Foo25(tt.args.in0) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo25() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Foo25() got = %v, want %v", tt.name, got, bb.want) + } + if !reflect.DeepEqual(got1, bb.want1) { + b.Errorf("%q. Foo25() got1 = %v, want %v", tt.name, got1, bb.want1) + } + } +} diff --git a/testdata/goldens/function_with_a_function_parameter_that_returns_two_results_with_benchmark.go b/testdata/goldens/function_with_a_function_parameter_that_returns_two_results_with_benchmark.go new file mode 100644 index 0000000..1e4c209 --- /dev/null +++ b/testdata/goldens/function_with_a_function_parameter_that_returns_two_results_with_benchmark.go @@ -0,0 +1,39 @@ +package testdata + +import "testing" + +func TestFoo15(t *testing.T) { + type args struct { + f func(string) (string, error) + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if err := Foo15(tt.args.f); (err != nil) != tt.wantErr { + t.Errorf("%q. Foo15() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkFoo15(b *testing.B) { + type args struct { + f func(string) (string, error) + } + benchmarks := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if err := Foo15(tt.args.f); (err != nil) != bb.wantErr { + b.Errorf("%q. Foo15() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/function_with_a_function_parameter_with_benchmark.go b/testdata/goldens/function_with_a_function_parameter_with_benchmark.go new file mode 100644 index 0000000..9c26ffa --- /dev/null +++ b/testdata/goldens/function_with_a_function_parameter_with_benchmark.go @@ -0,0 +1,39 @@ +package testdata + +import "testing" + +func TestFoo13(t *testing.T) { + type args struct { + f func() + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if err := Foo13(tt.args.f); (err != nil) != tt.wantErr { + t.Errorf("%q. Foo13() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkFoo13(b *testing.B) { + type args struct { + f func() + } + benchmarks := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if err := Foo13(tt.args.f); (err != nil) != bb.wantErr { + b.Errorf("%q. Foo13() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/function_with_a_function_parameter_with_its_own_parameters_and_result_with_benchmark.go b/testdata/goldens/function_with_a_function_parameter_with_its_own_parameters_and_result_with_benchmark.go new file mode 100644 index 0000000..ed40e3c --- /dev/null +++ b/testdata/goldens/function_with_a_function_parameter_with_its_own_parameters_and_result_with_benchmark.go @@ -0,0 +1,39 @@ +package testdata + +import "testing" + +func TestFoo14(t *testing.T) { + type args struct { + f func(string, int) string + } + tests := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if err := Foo14(tt.args.f); (err != nil) != tt.wantErr { + t.Errorf("%q. Foo14() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkFoo14(b *testing.B) { + type args struct { + f func(string, int) string + } + benchmarks := []struct { + name string + args args + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if err := Foo14(tt.args.f); (err != nil) != bb.wantErr { + b.Errorf("%q. Foo14() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/function_with_a_variadic_parameter_with_benchmark.go b/testdata/goldens/function_with_a_variadic_parameter_with_benchmark.go new file mode 100644 index 0000000..91ca952 --- /dev/null +++ b/testdata/goldens/function_with_a_variadic_parameter_with_benchmark.go @@ -0,0 +1,39 @@ +package testdata + +import "testing" + +func TestFoo20(t *testing.T) { + type args struct { + strs []string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo20(tt.args.strs...); got != tt.want { + t.Errorf("%q. Foo20() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo20(b *testing.B) { + type args struct { + strs []string + } + benchmarks := []struct { + name string + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo20(tt.args.strs...); got != bb.want { + b.Errorf("%q. Foo20() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_anonymous_arguments_with_benchmark.go b/testdata/goldens/function_with_anonymous_arguments_with_benchmark.go new file mode 100644 index 0000000..45499b1 --- /dev/null +++ b/testdata/goldens/function_with_anonymous_arguments_with_benchmark.go @@ -0,0 +1,35 @@ +package testdata + +import "testing" + +func TestFoo2(t *testing.T) { + type args struct { + in0 string + in1 int + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + Foo2(tt.args.in0, tt.args.in1) + } +} + +func BenchmarkFoo2(b *testing.B) { + type args struct { + in0 string + in1 int + } + benchmarks := []struct { + name string + args args + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + Foo2(tt.args.in0, tt.args.in1) + } +} diff --git a/testdata/goldens/function_with_benchmark.go b/testdata/goldens/function_with_benchmark.go new file mode 100644 index 0000000..2acb24b --- /dev/null +++ b/testdata/goldens/function_with_benchmark.go @@ -0,0 +1,31 @@ +package testdata + +import "testing" + +func TestFoo4(t *testing.T) { + testCases := []struct { + name string + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range testCases { + if got := Foo4(); got != tt.want { + t.Errorf("%q. Foo4() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo4(b *testing.B) { + benchmarks := []struct { + name string + want bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo4(); got != bb.want { + b.Errorf("%q. Foo4() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_channel_parameter_and_result_with_benchmark.go b/testdata/goldens/function_with_channel_parameter_and_result_with_benchmark.go new file mode 100644 index 0000000..6d9fea9 --- /dev/null +++ b/testdata/goldens/function_with_channel_parameter_and_result_with_benchmark.go @@ -0,0 +1,42 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo23() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo23(b *testing.B) { + type args struct { + ch chan bool + } + benchmarks := []struct { + name string + args args + want chan string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo23(tt.args.ch); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo23() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_defined_interface_type_parameter_and_result_with_benchmark.go b/testdata/goldens/function_with_defined_interface_type_parameter_and_result_with_benchmark.go new file mode 100644 index 0000000..82acc97 --- /dev/null +++ b/testdata/goldens/function_with_defined_interface_type_parameter_and_result_with_benchmark.go @@ -0,0 +1,42 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo16() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo16(b *testing.B) { + type args struct { + in Bazzar + } + benchmarks := []struct { + name string + args args + want Bazzar + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo16(tt.args.in); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo16() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_with_benchmark.go b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_with_benchmark.go new file mode 100644 index 0000000..5a3c266 --- /dev/null +++ b/testdata/goldens/function_with_imported_interface_receiver_parameter_and_result_with_benchmark.go @@ -0,0 +1,43 @@ +package testdata + +import ( + "io" + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo17() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo17(b *testing.B) { + type args struct { + r io.Reader + } + benchmarks := []struct { + name string + args args + want io.Reader + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo17(tt.args.r); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo17() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_with_benchmark.go b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_with_benchmark.go new file mode 100644 index 0000000..bfb7811 --- /dev/null +++ b/testdata/goldens/function_with_imported_struct_receiver_parameter_and_result_with_benchmark.go @@ -0,0 +1,43 @@ +package testdata + +import ( + "os" + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo18() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo18(b *testing.B) { + type args struct { + t *os.File + } + benchmarks := []struct { + name string + args args + want *os.File + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo18(tt.args.t); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo18() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_interface_parameter_and_result_with_benchmark.go b/testdata/goldens/function_with_interface_parameter_and_result_with_benchmark.go new file mode 100644 index 0000000..3619b83 --- /dev/null +++ b/testdata/goldens/function_with_interface_parameter_and_result_with_benchmark.go @@ -0,0 +1,42 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo21() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo21(b *testing.B) { + type args struct { + i interface{} + } + benchmarks := []struct { + name string + args args + want interface{} + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo21(tt.args.i); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo21() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_map_argument_and_return_type_with_benchmark.go b/testdata/goldens/function_with_map_argument_and_return_type_with_benchmark.go new file mode 100644 index 0000000..fd23428 --- /dev/null +++ b/testdata/goldens/function_with_map_argument_and_return_type_with_benchmark.go @@ -0,0 +1,42 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo10() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo10(b *testing.B) { + type args struct { + m map[string]int32 + } + benchmarks := []struct { + name string + args args + want map[string]*Bar + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo10(tt.args.m); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo10() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_multiple_arguments_with_benchmark.go b/testdata/goldens/function_with_multiple_arguments_with_benchmark.go new file mode 100644 index 0000000..4fa2d94 --- /dev/null +++ b/testdata/goldens/function_with_multiple_arguments_with_benchmark.go @@ -0,0 +1,53 @@ +package testdata + +import "testing" + +func TestFoo6(t *testing.T) { + type args struct { + i int + b bool + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo6(tt.args.i, tt.args.b) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo6() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Foo6() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo6(b *testing.B) { + type args struct { + i int + b bool + } + benchmarks := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, err := Foo6(tt.args.i, tt.args.b) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo6() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Foo6() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_multiple_parameters_of_the_same_type_with_benchmark.go b/testdata/goldens/function_with_multiple_parameters_of_the_same_type_with_benchmark.go new file mode 100644 index 0000000..f8795da --- /dev/null +++ b/testdata/goldens/function_with_multiple_parameters_of_the_same_type_with_benchmark.go @@ -0,0 +1,43 @@ +package testdata + +import "testing" + +func TestFoo19(t *testing.T) { + type args struct { + in1 string + in2 string + in3 string + } + tests := []struct { + name string + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo19(tt.args.in1, tt.args.in2, tt.args.in3); got != tt.want { + t.Errorf("%q. Foo19() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo19(b *testing.B) { + type args struct { + in1 string + in2 string + in3 string + } + benchmarks := []struct { + name string + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo19(tt.args.in1, tt.args.in2, tt.args.in3); got != bb.want { + b.Errorf("%q. Foo19() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_named_argument_with_benchmark.go b/testdata/goldens/function_with_named_argument_with_benchmark.go new file mode 100644 index 0000000..c92c6a2 --- /dev/null +++ b/testdata/goldens/function_with_named_argument_with_benchmark.go @@ -0,0 +1,33 @@ +package testdata + +import "testing" + +func TestFoo3(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + args args + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + Foo3(tt.args.s) + } +} + +func BenchmarkFoo3(b *testing.B) { + type args struct { + s string + } + benchmarks := []struct { + name string + args args + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + Foo3(tt.args.s) + } +} diff --git a/testdata/goldens/function_with_named_imports_with_benchmark.go b/testdata/goldens/function_with_named_imports_with_benchmark.go new file mode 100644 index 0000000..13da3e6 --- /dev/null +++ b/testdata/goldens/function_with_named_imports_with_benchmark.go @@ -0,0 +1,43 @@ +package testdata + +import ( + ht "html/template" + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo22() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo22(b *testing.B) { + type args struct { + t *ht.Template + } + benchmarks := []struct { + name string + args args + want *ht.Template + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo22(tt.args.t); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo22() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_neither_receiver_parameters_nor_results_with_benchmark.go b/testdata/goldens/function_with_neither_receiver_parameters_nor_results_with_benchmark.go new file mode 100644 index 0000000..ad8f969 --- /dev/null +++ b/testdata/goldens/function_with_neither_receiver_parameters_nor_results_with_benchmark.go @@ -0,0 +1,25 @@ +package testdata + +import "testing" + +func TestFoo1(t *testing.T) { + tests := []struct { + name string + }{ + // TODO: Add test cases. + } + for range tests { + Foo1() + } +} + +func BenchmarkFoo1(b *testing.B) { + benchmarks := []struct { + name string + }{ + // TODO: Add benchmark cases. + } + for range benchmarks { + Foo1() + } +} diff --git a/testdata/goldens/function_with_return_value_with_benchmark.go b/testdata/goldens/function_with_return_value_with_benchmark.go new file mode 100644 index 0000000..e4c13ed --- /dev/null +++ b/testdata/goldens/function_with_return_value_with_benchmark.go @@ -0,0 +1,31 @@ +package testdata + +import "testing" + +func TestFoo4(t *testing.T) { + tests := []struct { + name string + want bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := Foo4(); got != tt.want { + t.Errorf("%q. Foo4() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo4(b *testing.B) { + benchmarks := []struct { + name string + want bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := Foo4(); got != bb.want { + b.Errorf("%q. Foo4() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_slice_argument_and_return_type_with_benchmark.go b/testdata/goldens/function_with_slice_argument_and_return_type_with_benchmark.go new file mode 100644 index 0000000..c133ec4 --- /dev/null +++ b/testdata/goldens/function_with_slice_argument_and_return_type_with_benchmark.go @@ -0,0 +1,54 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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 !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo11() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo11(b *testing.B) { + type args struct { + strs []string + } + benchmarks := []struct { + name string + args args + want []*Bar + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, err := Foo11(tt.args.strs) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo11() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo11() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/function_with_struct_pointer_argument_and_return_type_with_benchmark.go b/testdata/goldens/function_with_struct_pointer_argument_and_return_type_with_benchmark.go new file mode 100644 index 0000000..0e0b102 --- /dev/null +++ b/testdata/goldens/function_with_struct_pointer_argument_and_return_type_with_benchmark.go @@ -0,0 +1,54 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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 !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Foo8() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFoo8(b *testing.B) { + type args struct { + b *Bar + } + benchmarks := []struct { + name string + args args + want *Bar + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, err := Foo8(tt.args.b) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo8() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Foo8() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/functions_and_methods_with_name_receivers_parameters_and_results_with_benchmark.go b/testdata/goldens/functions_and_methods_with_name_receivers_parameters_and_results_with_benchmark.go new file mode 100644 index 0000000..0f94e28 --- /dev/null +++ b/testdata/goldens/functions_and_methods_with_name_receivers_parameters_and_results_with_benchmark.go @@ -0,0 +1,191 @@ +package testdata + +import "testing" + +func Test_name_Name(t *testing.T) { + type args struct { + n string + } + tests := []struct { + name string + n name + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := tt.n.Name(tt.args.n); got != tt.want { + t.Errorf("%q. name.Name() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func Benchmark_name_Name(b *testing.B) { + type args struct { + n string + } + benchmarks := []struct { + name string + n name + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := tt.n.Name(tt.args.n); got != bb.want { + b.Errorf("%q. name.Name() = %v, want %v", tt.name, got, bb.want) + } + } +} + +func TestName_Name1(t *testing.T) { + type fields struct { + Name string + } + type args struct { + n string + } + tests := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + n := &Name{ + Name: tt.fields.Name, + } + if got := n.Name1(tt.args.n); got != tt.want { + t.Errorf("%q. Name.Name1() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkName_Name1(b *testing.B) { + type fields struct { + Name string + } + type args struct { + n string + } + benchmarks := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + n := &Name{ + Name: bb.fields.Name, + } + if got := n.Name1(tt.args.n); got != bb.want { + b.Errorf("%q. Name.Name1() = %v, want %v", tt.name, got, bb.want) + } + } +} + +func TestName_Name2(t *testing.T) { + type fields struct { + Name string + } + type args struct { + name string + } + tests := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + n := &Name{ + Name: tt.fields.Name, + } + if got := n.Name2(tt.args.name); got != tt.want { + t.Errorf("%q. Name.Name2() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkName_Name2(b *testing.B) { + type fields struct { + Name string + } + type args struct { + name string + } + benchmarks := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + n := &Name{ + Name: bb.fields.Name, + } + if got := n.Name2(tt.args.name); got != bb.want { + b.Errorf("%q. Name.Name2() = %v, want %v", tt.name, got, bb.want) + } + } +} + +func TestName_Name3(t *testing.T) { + type fields struct { + Name string + } + type args struct { + nn string + } + tests := []struct { + name string + fields fields + args args + wantName string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + n := &Name{ + Name: tt.fields.Name, + } + if gotName := n.Name3(tt.args.nn); gotName != tt.wantName { + t.Errorf("%q. Name.Name3() = %v, want %v", tt.name, gotName, tt.wantName) + } + } +} + +func BenchmarkName_Name3(b *testing.B) { + type fields struct { + Name string + } + type args struct { + nn string + } + benchmarks := []struct { + name string + fields fields + args args + wantName string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + n := &Name{ + Name: bb.fields.Name, + } + if gotName := n.Name3(tt.args.nn); gotName != bb.wantName { + b.Errorf("%q. Name.Name3() = %v, want %v", tt.name, gotName, bb.wantName) + } + } +} diff --git a/testdata/goldens/io_writer_parameters_with_benchmark.go b/testdata/goldens/io_writer_parameters_with_benchmark.go new file mode 100644 index 0000000..0f6dd15 --- /dev/null +++ b/testdata/goldens/io_writer_parameters_with_benchmark.go @@ -0,0 +1,174 @@ +package testdata + +import ( + "bytes" + "testing" +) + +func TestBar_Write(t *testing.T) { + tests := []struct { + name string + b *Bar + wantW string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + w := &bytes.Buffer{} + if err := b.Write(w); (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.Write() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if gotW := w.String(); gotW != tt.wantW { + t.Errorf("%q. Bar.Write() = %v, want %v", tt.name, gotW, tt.wantW) + } + } +} + +func BenchmarkBar_Write(b *testing.B) { + benchmarks := []struct { + name string + b *Bar + wantW string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b := &Bar{} + w := &bytes.Buffer{} + if err := b.Write(w); (err != nil) != bb.wantErr { + b.Errorf("%q. Bar.Write() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if gotW := w.String(); gotW != bb.wantW { + b.Errorf("%q. Bar.Write() = %v, want %v", tt.name, gotW, bb.wantW) + } + } +} + +func TestWrite(t *testing.T) { + type args struct { + data string + } + tests := []struct { + name string + args args + wantW string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + w := &bytes.Buffer{} + if err := Write(w, tt.args.data); (err != nil) != tt.wantErr { + t.Errorf("%q. Write() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if gotW := w.String(); gotW != tt.wantW { + t.Errorf("%q. Write() = %v, want %v", tt.name, gotW, tt.wantW) + } + } +} + +func BenchmarkWrite(b *testing.B) { + type args struct { + data string + } + benchmarks := []struct { + name string + args args + wantW string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + w := &bytes.Buffer{} + if err := Write(w, tt.args.data); (err != nil) != bb.wantErr { + b.Errorf("%q. Write() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if gotW := w.String(); gotW != bb.wantW { + b.Errorf("%q. Write() = %v, want %v", tt.name, gotW, bb.wantW) + } + } +} + +func TestMultiWrite(t *testing.T) { + type args struct { + data string + } + tests := []struct { + name string + args args + want int + want1 string + wantW1 string + wantW2 string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + w1 := &bytes.Buffer{} + w2 := &bytes.Buffer{} + got, got1, err := MultiWrite(w1, w2, tt.args.data) + if (err != nil) != tt.wantErr { + t.Errorf("%q. MultiWrite() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. MultiWrite() got = %v, want %v", tt.name, got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("%q. MultiWrite() got1 = %v, want %v", tt.name, got1, tt.want1) + } + if gotW1 := w1.String(); gotW1 != tt.wantW1 { + t.Errorf("%q. MultiWrite() gotW1 = %v, want %v", tt.name, gotW1, tt.wantW1) + } + if gotW2 := w2.String(); gotW2 != tt.wantW2 { + t.Errorf("%q. MultiWrite() gotW2 = %v, want %v", tt.name, gotW2, tt.wantW2) + } + } +} + +func BenchmarkMultiWrite(b *testing.B) { + type args struct { + data string + } + benchmarks := []struct { + name string + args args + want int + want1 string + wantW1 string + wantW2 string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + w1 := &bytes.Buffer{} + w2 := &bytes.Buffer{} + got, got1, err := MultiWrite(w1, w2, tt.args.data) + if (err != nil) != bb.wantErr { + b.Errorf("%q. MultiWrite() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. MultiWrite() got = %v, want %v", tt.name, got, bb.want) + } + if got1 != bb.want1 { + b.Errorf("%q. MultiWrite() got1 = %v, want %v", tt.name, got1, bb.want1) + } + if gotW1 := w1.String(); gotW1 != bb.wantW1 { + b.Errorf("%q. MultiWrite() gotW1 = %v, want %v", tt.name, gotW1, bb.wantW1) + } + if gotW2 := w2.String(); gotW2 != bb.wantW2 { + b.Errorf("%q. MultiWrite() gotW2 = %v, want %v", tt.name, gotW2, bb.wantW2) + } + } +} diff --git a/testdata/goldens/method_on_a_struct_pointer_with_benchmark.go b/testdata/goldens/method_on_a_struct_pointer_with_benchmark.go new file mode 100644 index 0000000..f44cb2a --- /dev/null +++ b/testdata/goldens/method_on_a_struct_pointer_with_benchmark.go @@ -0,0 +1,55 @@ +package testdata + +import "testing" + +func TestBar_Foo7(t *testing.T) { + type args struct { + i int + } + tests := []struct { + name string + b *Bar + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + got, err := b.Foo7(tt.args.i) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.Foo7() error = %v, wantErr %v", tt.name, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Bar.Foo7() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkBar_Foo7(b *testing.B) { + type args struct { + i int + } + benchmarks := []struct { + name string + b *Bar + args args + want string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b := &Bar{} + got, err := b.Foo7(tt.args.i) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Bar.Foo7() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Bar.Foo7() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/multiple_named_results_with_benchmark.go b/testdata/goldens/multiple_named_results_with_benchmark.go new file mode 100644 index 0000000..dd47fe6 --- /dev/null +++ b/testdata/goldens/multiple_named_results_with_benchmark.go @@ -0,0 +1,70 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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 !reflect.DeepEqual(got2, tt.want2) { + t.Errorf("%q. Foo26() got2 = %v, want %v", tt.name, got2, tt.want2) + } + } +} + +func BenchmarkFoo26(b *testing.B) { + type args struct { + v interface{} + } + benchmarks := []struct { + name string + args args + want string + wantI int + want2 []byte + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, gotI, got2, err := Foo26(tt.args.v) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo26() error = %v, wantErr %v", tt.name, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Foo26() got = %v, want %v", tt.name, got, bb.want) + } + if gotI != bb.wantI { + b.Errorf("%q. Foo26() gotI = %v, want %v", tt.name, gotI, bb.wantI) + } + if !reflect.DeepEqual(got2, bb.want2) { + b.Errorf("%q. Foo26() got2 = %v, want %v", tt.name, got2, bb.want2) + } + } +} diff --git a/testdata/goldens/print_inputs_with_multiple_arguments_with_benchmark.go b/testdata/goldens/print_inputs_with_multiple_arguments_with_benchmark.go new file mode 100644 index 0000000..fc73517 --- /dev/null +++ b/testdata/goldens/print_inputs_with_multiple_arguments_with_benchmark.go @@ -0,0 +1,53 @@ +package testdata + +import "testing" + +func TestFoo6(t *testing.T) { + type args struct { + i int + b bool + } + tests := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + got, err := Foo6(tt.args.i, tt.args.b) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Foo6(%v, %v) error = %v, wantErr %v", tt.name, tt.args.i, tt.args.b, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Foo6(%v, %v) = %v, want %v", tt.name, tt.args.i, tt.args.b, got, tt.want) + } + } +} + +func BenchmarkFoo6(b *testing.B) { + type args struct { + i int + b bool + } + benchmarks := []struct { + name string + args args + want string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + got, err := Foo6(tt.args.i, tt.args.b) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Foo6(%v, %v) error = %v, wantErr %v", tt.name, tt.args.i, tt.args.b, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Foo6(%v, %v) = %v, want %v", tt.name, tt.args.i, tt.args.b, got, bb.want) + } + } +} diff --git a/testdata/goldens/print_inputs_with_single_argument_with_benchmark.go b/testdata/goldens/print_inputs_with_single_argument_with_benchmark.go new file mode 100644 index 0000000..1bff314 --- /dev/null +++ b/testdata/goldens/print_inputs_with_single_argument_with_benchmark.go @@ -0,0 +1,55 @@ +package testdata + +import "testing" + +func TestBar_Foo7(t *testing.T) { + type args struct { + i int + } + tests := []struct { + name string + b *Bar + args args + want string + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Bar{} + got, err := b.Foo7(tt.args.i) + if (err != nil) != tt.wantErr { + t.Errorf("%q. Bar.Foo7(%v) error = %v, wantErr %v", tt.name, tt.args.i, err, tt.wantErr) + continue + } + if got != tt.want { + t.Errorf("%q. Bar.Foo7(%v) = %v, want %v", tt.name, tt.args.i, got, tt.want) + } + } +} + +func BenchmarkBar_Foo7(b *testing.B) { + type args struct { + i int + } + benchmarks := []struct { + name string + b *Bar + args args + want string + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b := &Bar{} + got, err := b.Foo7(tt.args.i) + if (err != nil) != bb.wantErr { + b.Errorf("%q. Bar.Foo7(%v) error = %v, wantErr %v", tt.name, tt.args.i, err, bb.wantErr) + continue + } + if got != bb.want { + b.Errorf("%q. Bar.Foo7(%v) = %v, want %v", tt.name, tt.args.i, got, bb.want) + } + } +} diff --git a/testdata/goldens/receiver_struct_with_reserved_field_names_with_benchmark.go b/testdata/goldens/receiver_struct_with_reserved_field_names_with_benchmark.go new file mode 100644 index 0000000..b97dbf5 --- /dev/null +++ b/testdata/goldens/receiver_struct_with_reserved_field_names_with_benchmark.go @@ -0,0 +1,145 @@ +package testdata + +import "testing" + +func TestReserved_DontFail(t *testing.T) { + type fields struct { + Name string + Break string + Default string + Func string + Interface string + Select string + Case string + Defer string + Go string + Map string + Struct string + Chan string + Else string + Goto string + Package string + Switch string + Const string + Fallthrough string + If string + Range string + Type string + Continue string + For string + Import string + Return string + Var string + } + tests := []struct { + name string + fields fields + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + r := &Reserved{ + Name: tt.fields.Name, + Break: tt.fields.Break, + Default: tt.fields.Default, + Func: tt.fields.Func, + Interface: tt.fields.Interface, + Select: tt.fields.Select, + Case: tt.fields.Case, + Defer: tt.fields.Defer, + Go: tt.fields.Go, + Map: tt.fields.Map, + Struct: tt.fields.Struct, + Chan: tt.fields.Chan, + Else: tt.fields.Else, + Goto: tt.fields.Goto, + Package: tt.fields.Package, + Switch: tt.fields.Switch, + Const: tt.fields.Const, + Fallthrough: tt.fields.Fallthrough, + If: tt.fields.If, + Range: tt.fields.Range, + Type: tt.fields.Type, + Continue: tt.fields.Continue, + For: tt.fields.For, + Import: tt.fields.Import, + Return: tt.fields.Return, + Var: tt.fields.Var, + } + if got := r.DontFail(); got != tt.want { + t.Errorf("%q. Reserved.DontFail() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkReserved_DontFail(b *testing.B) { + type fields struct { + Name string + Break string + Default string + Func string + Interface string + Select string + Case string + Defer string + Go string + Map string + Struct string + Chan string + Else string + Goto string + Package string + Switch string + Const string + Fallthrough string + If string + Range string + Type string + Continue string + For string + Import string + Return string + Var string + } + benchmarks := []struct { + name string + fields fields + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + r := &Reserved{ + Name: bb.fields.Name, + Break: bb.fields.Break, + Default: bb.fields.Default, + Func: bb.fields.Func, + Interface: bb.fields.Interface, + Select: bb.fields.Select, + Case: bb.fields.Case, + Defer: bb.fields.Defer, + Go: bb.fields.Go, + Map: bb.fields.Map, + Struct: bb.fields.Struct, + Chan: bb.fields.Chan, + Else: bb.fields.Else, + Goto: bb.fields.Goto, + Package: bb.fields.Package, + Switch: bb.fields.Switch, + Const: bb.fields.Const, + Fallthrough: bb.fields.Fallthrough, + If: bb.fields.If, + Range: bb.fields.Range, + Type: bb.fields.Type, + Continue: bb.fields.Continue, + For: bb.fields.For, + Import: bb.fields.Import, + Return: bb.fields.Return, + Var: bb.fields.Var, + } + if got := r.DontFail(); got != bb.want { + b.Errorf("%q. Reserved.DontFail() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/struct_receiver_with_anonymous_fields_with_benchmark.go b/testdata/goldens/struct_receiver_with_anonymous_fields_with_benchmark.go new file mode 100644 index 0000000..34dfd25 --- /dev/null +++ b/testdata/goldens/struct_receiver_with_anonymous_fields_with_benchmark.go @@ -0,0 +1,65 @@ +package testdata + +import "testing" + +func TestDoctor_SayHello(t *testing.T) { + type fields struct { + Person *Person + ID string + numPatients int + string string + } + type args struct { + r *Person + } + tests := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + d := &Doctor{ + Person: tt.fields.Person, + ID: tt.fields.ID, + numPatients: tt.fields.numPatients, + string: tt.fields.string, + } + if got := d.SayHello(tt.args.r); got != tt.want { + t.Errorf("%q. Doctor.SayHello() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkDoctor_SayHello(b *testing.B) { + type fields struct { + Person *Person + ID string + numPatients int + string string + } + type args struct { + r *Person + } + benchmarks := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + d := &Doctor{ + Person: bb.fields.Person, + ID: bb.fields.ID, + numPatients: bb.fields.numPatients, + string: bb.fields.string, + } + if got := d.SayHello(tt.args.r); got != bb.want { + b.Errorf("%q. Doctor.SayHello() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/struct_receiver_with_multiple_fields_with_benchmark.go b/testdata/goldens/struct_receiver_with_multiple_fields_with_benchmark.go new file mode 100644 index 0000000..474d1e9 --- /dev/null +++ b/testdata/goldens/struct_receiver_with_multiple_fields_with_benchmark.go @@ -0,0 +1,69 @@ +package testdata + +import "testing" + +func TestPerson_SayHello(t *testing.T) { + type fields struct { + FirstName string + LastName string + Age int + Gender string + Siblings []*Person + } + type args struct { + r *Person + } + tests := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + p := &Person{ + FirstName: tt.fields.FirstName, + LastName: tt.fields.LastName, + Age: tt.fields.Age, + Gender: tt.fields.Gender, + Siblings: tt.fields.Siblings, + } + if got := p.SayHello(tt.args.r); got != tt.want { + t.Errorf("%q. Person.SayHello() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkPerson_SayHello(b *testing.B) { + type fields struct { + FirstName string + LastName string + Age int + Gender string + Siblings []*Person + } + type args struct { + r *Person + } + benchmarks := []struct { + name string + fields fields + args args + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + p := &Person{ + FirstName: bb.fields.FirstName, + LastName: bb.fields.LastName, + Age: bb.fields.Age, + Gender: bb.fields.Gender, + Siblings: bb.fields.Siblings, + } + if got := p.SayHello(tt.args.r); got != bb.want { + b.Errorf("%q. Person.SayHello() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/struct_value_method_with_struct_value_return_type_with_benchmark.go b/testdata/goldens/struct_value_method_with_struct_value_return_type_with_benchmark.go new file mode 100644 index 0000000..ab803cc --- /dev/null +++ b/testdata/goldens/struct_value_method_with_struct_value_return_type_with_benchmark.go @@ -0,0 +1,38 @@ +package testdata + +import ( + "reflect" + "testing" +) + +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(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("%q. Bar.Foo9() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkBar_Foo9(b *testing.B) { + benchmarks := []struct { + name string + b Bar + want Bar + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b := Bar{} + if got := b.Foo9(); !reflect.DeepEqual(got, bb.want) { + b.Errorf("%q. Bar.Foo9() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/target_test_file_with_benchmark.go b/testdata/goldens/target_test_file_with_benchmark.go new file mode 100644 index 0000000..1bfa914 --- /dev/null +++ b/testdata/goldens/target_test_file_with_benchmark.go @@ -0,0 +1,95 @@ +package testdata + +import ( + "fmt" + "reflect" + "testing" +) + +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); !reflect.DeepEqual(got, tt.want) { + t.Errorf("wrapToString() = %v, want %v", got, tt.want) + } + }) + } +} + +func Benchmark_wrapToString(b *testing.B) { + type args struct { + in []int + } + benchmarks := []struct { + name string + args args + want []string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b.Run(bb.name, func(t *testing.B) { + if got := wrapToString(tt.args.in); !reflect.DeepEqual(got, bb.want) { + b.Errorf("wrapToString() = %v, want %v", got, bb.want) + } + }) + } +} diff --git a/testdata/goldens/two_different_structs_with_same_method_name_with_benchmark.go b/testdata/goldens/two_different_structs_with_same_method_name_with_benchmark.go new file mode 100644 index 0000000..7138020 --- /dev/null +++ b/testdata/goldens/two_different_structs_with_same_method_name_with_benchmark.go @@ -0,0 +1,99 @@ +package testdata + +import "testing" + +func TestBook_Open(t *testing.T) { + tests := []struct { + name string + b *Book + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + b := &Book{} + if err := b.Open(); (err != nil) != tt.wantErr { + t.Errorf("%q. Book.Open() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func BenchmarkBook_Open(b *testing.B) { + benchmarks := []struct { + name string + b *Book + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + b := &Book{} + if err := b.Open(); (err != nil) != bb.wantErr { + b.Errorf("%q. Book.Open() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} + +func Test_door_Open(t *testing.T) { + tests := []struct { + name string + d *door + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + d := &door{} + if err := d.Open(); (err != nil) != tt.wantErr { + t.Errorf("%q. door.Open() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func Benchmark_door_Open(b *testing.B) { + benchmarks := []struct { + name string + d *door + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + d := &door{} + if err := d.Open(); (err != nil) != bb.wantErr { + b.Errorf("%q. door.Open() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} + +func Test_xml_Open(t *testing.T) { + tests := []struct { + name string + x *xml + wantErr bool + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + x := &xml{} + if err := x.Open(); (err != nil) != tt.wantErr { + t.Errorf("%q. xml.Open() error = %v, wantErr %v", tt.name, err, tt.wantErr) + } + } +} + +func Benchmark_xml_Open(b *testing.B) { + benchmarks := []struct { + name string + x *xml + wantErr bool + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + x := &xml{} + if err := x.Open(); (err != nil) != bb.wantErr { + b.Errorf("%q. xml.Open() error = %v, wantErr %v", tt.name, err, bb.wantErr) + } + } +} diff --git a/testdata/goldens/two_structs_with_same_method_name_with_benchmark.go b/testdata/goldens/two_structs_with_same_method_name_with_benchmark.go new file mode 100644 index 0000000..9fa7aa9 --- /dev/null +++ b/testdata/goldens/two_structs_with_same_method_name_with_benchmark.go @@ -0,0 +1,63 @@ +package testdata + +import "testing" + +func TestCelsius_String(t *testing.T) { + tests := []struct { + name string + c Celsius + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := tt.c.String(); got != tt.want { + t.Errorf("%q. Celsius.String() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkCelsius_String(b *testing.B) { + benchmarks := []struct { + name string + c Celsius + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := tt.c.String(); got != bb.want { + b.Errorf("%q. Celsius.String() = %v, want %v", tt.name, got, bb.want) + } + } +} + +func TestFahrenheit_String(t *testing.T) { + tests := []struct { + name string + f Fahrenheit + want string + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := tt.f.String(); got != tt.want { + t.Errorf("%q. Fahrenheit.String() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkFahrenheit_String(b *testing.B) { + benchmarks := []struct { + name string + f Fahrenheit + want string + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := tt.f.String(); got != bb.want { + b.Errorf("%q. Fahrenheit.String() = %v, want %v", tt.name, got, bb.want) + } + } +} diff --git a/testdata/goldens/underlying_types_with_benchmark.go b/testdata/goldens/underlying_types_with_benchmark.go new file mode 100644 index 0000000..cafa12b --- /dev/null +++ b/testdata/goldens/underlying_types_with_benchmark.go @@ -0,0 +1,72 @@ +package testdata + +import ( + "testing" + "time" +) + +func TestCelsius_ToFahrenheit(t *testing.T) { + tests := []struct { + name string + c Celsius + want Fahrenheit + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := tt.c.ToFahrenheit(); got != tt.want { + t.Errorf("%q. Celsius.ToFahrenheit() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkCelsius_ToFahrenheit(b *testing.B) { + benchmarks := []struct { + name string + c Celsius + want Fahrenheit + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := tt.c.ToFahrenheit(); got != bb.want { + b.Errorf("%q. Celsius.ToFahrenheit() = %v, want %v", tt.name, got, bb.want) + } + } +} + +func TestHourToSecond(t *testing.T) { + type args struct { + h time.Duration + } + tests := []struct { + name string + args args + want time.Duration + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + if got := HourToSecond(tt.args.h); got != tt.want { + t.Errorf("%q. HourToSecond() = %v, want %v", tt.name, got, tt.want) + } + } +} + +func BenchmarkHourToSecond(b *testing.B) { + type args struct { + h time.Duration + } + benchmarks := []struct { + name string + args args + want time.Duration + }{ + // TODO: Add benchmark cases. + } + for _, bb := range benchmarks { + if got := HourToSecond(tt.args.h); got != bb.want { + b.Errorf("%q. HourToSecond() = %v, want %v", tt.name, got, bb.want) + } + } +}