Use any instead of interface{}

Signed-off-by: chenyahui <cyhone@qq.com>
This commit is contained in:
chenyahui
2023-09-17 17:41:58 +08:00
parent fb8a315be6
commit c0aa3b613b
61 changed files with 227 additions and 227 deletions

View File

@ -21,20 +21,20 @@ import (
"github.com/stretchr/testify/assert"
)
func copyToInterface(msg ...string) []interface{} {
newMsg := make([]interface{}, len(msg))
func copyToInterface(msg ...string) []any {
newMsg := make([]any, len(msg))
for i, v := range msg {
newMsg[i] = v
}
return newMsg
}
func AssertNil(t *testing.T, v interface{}) {
func AssertNil(t *testing.T, v any) {
t.Helper()
assert.Nil(t, v)
}
func AssertNotNil(t *testing.T, v interface{}) {
func AssertNotNil(t *testing.T, v any) {
t.Helper()
if v == nil {
t.Fatalf("expected non-nil, got %+v", v)
@ -53,7 +53,7 @@ func AssertFalse(t *testing.T, v bool, msg ...string) {
assert.Equal(t, false, v, newMsg)
}
func isNil(v interface{}) bool {
func isNil(v any) bool {
if v == nil {
return true
}

View File

@ -23,7 +23,7 @@ import (
type Action struct {
Name string
Params []interface{}
Params []any
}
type Recorder interface {

View File

@ -23,18 +23,18 @@ import (
// We cannot implement testing.TB due to protection, so we expose this simplified interface.
type TB interface {
Cleanup(func())
Error(args ...interface{})
Errorf(format string, args ...interface{})
Error(args ...any)
Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Logf(format string, args ...interface{})
Fatal(args ...any)
Fatalf(format string, args ...any)
Logf(format string, args ...any)
Name() string
TempDir() string
Helper()
Skip(args ...interface{})
Skip(args ...any)
}
// NewTestingTBProthesis creates a fake variant of testing.TB implementation.
@ -59,20 +59,20 @@ func (t *testingTBProthesis) Helper() {
// Ignored
}
func (t *testingTBProthesis) Skip(args ...interface{}) {
t.Log(append([]interface{}{"Skipping due to: "}, args...))
func (t *testingTBProthesis) Skip(args ...any) {
t.Log(append([]any{"Skipping due to: "}, args...))
}
func (t *testingTBProthesis) Cleanup(f func()) {
t.cleanups = append(t.cleanups, f)
}
func (t *testingTBProthesis) Error(args ...interface{}) {
func (t *testingTBProthesis) Error(args ...any) {
log.Println(args...)
t.Fail()
}
func (t *testingTBProthesis) Errorf(format string, args ...interface{}) {
func (t *testingTBProthesis) Errorf(format string, args ...any) {
log.Printf(format, args...)
t.Fail()
}
@ -90,19 +90,19 @@ func (t *testingTBProthesis) Failed() bool {
return t.failed
}
func (t *testingTBProthesis) Fatal(args ...interface{}) {
func (t *testingTBProthesis) Fatal(args ...any) {
log.Fatalln(args...)
}
func (t *testingTBProthesis) Fatalf(format string, args ...interface{}) {
func (t *testingTBProthesis) Fatalf(format string, args ...any) {
log.Fatalf(format, args...)
}
func (t *testingTBProthesis) Logf(format string, args ...interface{}) {
func (t *testingTBProthesis) Logf(format string, args ...any) {
log.Printf(format, args...)
}
func (t *testingTBProthesis) Log(args ...interface{}) {
func (t *testingTBProthesis) Log(args ...any) {
log.Println(args...)
}