You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Filing this issue to track/ discuss generic function support for gotests.
Currently, gotests produces a table driven test for a function with type parameters, but the test needs to actually be modified to include concrete types (the test file will have build errors).
Example:
typeparams.go:
package typeparams
// SumIntsOrFloats sums the values of map m. It supports both floats and integers
// as map values.
func SumIntsOrFloats[K comparable, V int64 | float64](m map[K]V) V {
var s V
for _, v := range m {
s += v
}
return s
}
typeparams_test.go:
package typeparams
import (
"reflect"
"testing"
)
func TestSumIntsOrFloats(t *testing.T) {
type args struct {
m map[K]V // K and V not defined
}
tests := []struct {
name string
args args
want V
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SumIntsOrFloats(tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("SumIntsOrFloats() = %v, want %v", got, tt.want)
}
})
}
}
Can better table driven tests be generated for functions with type params / should the generated tests make sure there are no build errors?
output.Process: imports.Process: /var/folders/fw/grysx2h56354vh4_30px6_r80000gp/T/gotests_112301585:9:14: all type parameters must be named (and 1 more errors)
Filing this issue to track/ discuss generic function support for gotests.
Currently, gotests produces a table driven test for a function with type parameters, but the test needs to actually be modified to include concrete types (the test file will have build errors).
Example:
typeparams.go:
typeparams_test.go:
Can better table driven tests be generated for functions with type params / should the generated tests make sure there are no build errors?
Related go issue: golang/go#50558
The text was updated successfully, but these errors were encountered: