test: use generics in Equal function signature

This simplifies comparing a typed value against nil. Previously it was
necessary to case nil into the proper type.
This commit is contained in:
Michael Eischer
2025-11-22 22:10:46 +01:00
parent 24d56fe2a6
commit e1a5550a27
4 changed files with 4 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ func TestParse(t *testing.T) {
u, err := location.Parse(registry, path) u, err := location.Parse(registry, path)
test.OK(t, err) test.OK(t, err)
test.Equals(t, "local", u.Scheme) test.Equals(t, "local", u.Scheme)
test.Equals(t, &testConfig{loc: path}, u.Config) test.Equals(t, any(&testConfig{loc: path}), u.Config)
} }
func TestParseFallback(t *testing.T) { func TestParseFallback(t *testing.T) {

View File

@@ -37,7 +37,7 @@ func TestDefaultLoad(t *testing.T) {
return rd, nil return rd, nil
}, func(ird io.Reader) error { }, func(ird io.Reader) error {
rtest.Equals(t, rd, ird) rtest.Equals(t, io.Reader(rd), ird)
return nil return nil
}) })
rtest.OK(t, err) rtest.OK(t, err)

View File

@@ -48,7 +48,7 @@ func OKs(tb testing.TB, errs []error) {
// Equals fails the test if exp is not equal to act. // Equals fails the test if exp is not equal to act.
// msg is optional message to be printed, first param being format string and rest being arguments. // msg is optional message to be printed, first param being format string and rest being arguments.
func Equals(tb testing.TB, exp, act interface{}, msgs ...string) { func Equals[T any](tb testing.TB, exp, act T, msgs ...string) {
tb.Helper() tb.Helper()
if !reflect.DeepEqual(exp, act) { if !reflect.DeepEqual(exp, act) {
var msgString string var msgString string

View File

@@ -128,7 +128,7 @@ func TestRawInputOutput(t *testing.T) {
defer cancel() defer cancel()
rtest.Equals(t, input, term.InputRaw()) rtest.Equals(t, input, term.InputRaw())
rtest.Equals(t, false, term.InputIsTerminal()) rtest.Equals(t, false, term.InputIsTerminal())
rtest.Equals(t, &output, term.OutputRaw()) rtest.Equals(t, io.Writer(&output), term.OutputRaw())
rtest.Equals(t, false, term.OutputIsTerminal()) rtest.Equals(t, false, term.OutputIsTerminal())
rtest.Equals(t, false, term.CanUpdateStatus()) rtest.Equals(t, false, term.CanUpdateStatus())
} }