diff options
author | EuAndreh <eu@euandre.org> | 2025-02-11 08:28:34 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-02-11 08:28:34 -0300 |
commit | 60c7553e515122774fecb600197b0910435e7aaa (patch) | |
tree | 53eefcf7303d5db068ef175bd69d9327ca69b357 /tests/gobang.go | |
parent | src/gobang.go: Add "assertion failed: " prefix to assert error message (diff) | |
download | gobang-60c7553e515122774fecb600197b0910435e7aaa.tar.gz gobang-60c7553e515122774fecb600197b0910435e7aaa.tar.xz |
src/gobang.go: Add generic function Must()
Diffstat (limited to 'tests/gobang.go')
-rw-r--r-- | tests/gobang.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/gobang.go b/tests/gobang.go index b6039af..c1286cd 100644 --- a/tests/gobang.go +++ b/tests/gobang.go @@ -15,6 +15,32 @@ import ( +func test_Must() { + TestStart("Must()") + + myErr := errors.New("test error") + f := func(shouldError bool) (string, error) { + if shouldError { + return "UNSEEN", myErr + } + + return "no error", nil + } + + + Testing("value when error is nil", func() { + TAssertEqual(Must(f(false)), "no error") + }) + + Testing("panic when we have an error", func() { + defer func() { + TAssertEqual(recover(), myErr) + }() + Must(f(true)) + TErrorNil(nil) + }) +} + func test_Clamp() { TestStart("Clamp()") @@ -1307,6 +1333,7 @@ func test_setHostname() { func MainTest() { Init() + test_Must() test_Clamp() test_ValidateSQLTablePrefix() test_WrapErrors() |