github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/test/Assert.go (about) 1 package test 2 3 import "testing" 4 5 func True(t *testing.T, value bool) { 6 if !value { 7 t.Error("expect true, but actual is false") 8 } 9 } 10 11 func TrueErr(t *testing.T, value bool, errMsg string) { 12 if !value { 13 t.Errorf("expect true, but actual is false, error: %v", errMsg) 14 } 15 } 16 17 func False(t *testing.T, value bool) { 18 if value { 19 t.Error("expect false, but actual is true") 20 } 21 } 22 23 func FalseErr(t *testing.T, value bool, errMsg string) { 24 if value { 25 t.Errorf("expect false, but actual is true, error: %v", errMsg) 26 } else { 27 t.Logf("error: %v", errMsg) 28 } 29 } 30 31 // Equal 参数为act-expect-act-expect-...结构,其中expect为期望值,act为实际值 32 func Equal(t *testing.T, objects ...any) { 33 if len(objects)%2 != 0 { 34 t.Error("参数个数必须为偶数") 35 } 36 37 for i := 0; i < len(objects); i += 2 { 38 if objects[i] != objects[i+1] { 39 t.Errorf("\n期望:\n%v\n实际:\n%v", objects[i+1], objects[i]) 40 } 41 } 42 } 43 44 func Err(t *testing.T, err error) { 45 t.Errorf("系统异常:%v", err) 46 }