26 lines
689 B
Go
26 lines
689 B
Go
//go:build !assert_disable
|
|
|
|
package assert
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
)
|
|
|
|
// That panics if condition is false, reporting msg as the violated invariant.
|
|
func That(condition bool, msg string) {
|
|
if !condition {
|
|
_, file, line, _ := runtime.Caller(1)
|
|
panic(fmt.Sprintf("assertion violated at %s:%d: %s", file, line, msg))
|
|
}
|
|
}
|
|
|
|
// Thatf panics if condition is false, reporting a formatted string as the
|
|
// violated invariant. Arguments are formatted as in [fmt.Sprintf].
|
|
func Thatf(condition bool, format string, args ...any) {
|
|
if !condition {
|
|
_, file, line, _ := runtime.Caller(1)
|
|
panic(fmt.Sprintf("assertion violated at %s:%d: %s", file, line, fmt.Sprintf(format, args...)))
|
|
}
|
|
}
|