Feature: add assert panic and not panic #3

Merged
naslevente merged 1 commits from testing_additions into master 2024-10-15 16:52:48 -04:00

View File

@@ -73,3 +73,33 @@ func AssertNotNil[T any](t *testing.T, expected *T) {
}
t.Errorf("❌ [%T](%+v) != [%T](%+v)", expected, expected, nil, nil)
}
func internalAssertPanic(f func()) (b bool) {
b = true
defer func() {
_ = recover()
}()
f()
return false
}
func AssertPanic(t *testing.T, f func()) {
t.Helper()
x := internalAssertPanic(f)
if x {
t.Log("✅ Code correctly panicked!")
} else {
t.Error("❌ Code was supposed to panic!")
}
}
func AssertNotPanic(t *testing.T, f func()) {
t.Helper()
x := internalAssertPanic(f)
if !x {
t.Log("✅ Code correctly did not panic!")
} else {
t.Error("❌ Code panicked!")
}
}