provide a generic assert function

This commit is contained in:
ahrtr 2022-05-13 10:50:19 +08:00
parent 5fd69102ce
commit 4fc9721fa6

View File

@ -15,6 +15,7 @@
package verify
import (
"fmt"
"os"
"strings"
)
@ -70,3 +71,10 @@ func Verify(f func()) {
f()
}
}
// Assert will panic with a given formatted message if the given condition is false.
func Assert(condition bool, msg string, v ...interface{}) {
if !condition {
panic(fmt.Sprintf("assertion failed: "+msg, v...))
}
}