From 60c7553e515122774fecb600197b0910435e7aaa Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 11 Feb 2025 08:28:34 -0300 Subject: src/gobang.go: Add generic function Must() --- tests/gobang.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/gobang.go') 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() -- cgit v1.2.3