Merge pull request #14036 from ahrtr/add_assert

Provide a generic assert function
This commit is contained in:
Piotr Tabor 2022-05-13 11:38:33 +02:00 committed by GitHub
commit 30daf4e3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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...))
}
}