github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/should/pass.go (about) 1 package should 2 3 import ( 4 "github.com/v2pro/plz/test" 5 "runtime" 6 "github.com/davecgh/go-spew/spew" 7 ) 8 9 //go:noinline 10 func Assert(result bool, kv ...interface{}) { 11 if !result { 12 t := test.CurrentT() 13 test.Helper() 14 _, file, line, ok := runtime.Caller(1) 15 if !ok { 16 t.Error("check failed") 17 return 18 } 19 for i := 0; i < len(kv); i+=2 { 20 key := kv[i].(string) 21 t.Errorf("%s: %s", key, spew.Sdump(kv[i+1])) 22 } 23 t.Error(test.ExtractFailedLines(file, line)) 24 } 25 } 26 27 //go:noinline 28 func Pass(result bool, kv ...interface{}) { 29 if !result { 30 t := test.CurrentT() 31 test.Helper() 32 _, file, line, ok := runtime.Caller(1) 33 if !ok { 34 t.Error("check failed") 35 return 36 } 37 for i := 0; i < len(kv); i+=2 { 38 key := kv[i].(string) 39 t.Errorf("%s: %s", key, spew.Sdump(kv[i+1])) 40 } 41 t.Error(test.ExtractFailedLines(file, line)) 42 } 43 }