Skip to content

Commit

Permalink
Allow assert.Assert to use msg + args format like Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Apr 13, 2023
1 parent 04155c1 commit 4a0337c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ func CheckEquals(t *testing.T, actual interface{}, expected interface{}, msg int

// Assert is similar to True() under a different name and earlier
// fortio/stats test implementation.
func Assert(t *testing.T, cond bool, msg interface{}) {
func Assert(t *testing.T, cond bool, msg string, rest ...interface{}) {
if !cond {
_, file, line, _ := runtime.Caller(1)
file = file[strings.LastIndex(file, "/")+1:]
fmt.Printf("%s:%d assert failure: %+v\n", file, line, msg)
m := fmt.Sprintf(msg, rest...)
fmt.Printf("%s:%d assert failure: %s\n", file, line, m)
t.Fail()
}
}
Expand Down

0 comments on commit 4a0337c

Please sign in to comment.