aboutsummaryrefslogtreecommitdiff
path: root/internal/must/must.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-13 11:39:36 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-13 11:39:38 +0200
commit1a187cb04b3130572a5b3f7513c1e55b0a59fdc2 (patch)
treeb35694f7cbc7b0d2991cb4a7e0bc8f31cf526a88 /internal/must/must.go
parenta23dd12a27237a5e0d6883cd30373408a2f28f6e (diff)
downloadgo-oblast-1a187cb04b3130572a5b3f7513c1e55b0a59fdc2.tar.gz
reduce code duplication in benchmark tests
Diffstat (limited to 'internal/must/must.go')
-rw-r--r--internal/must/must.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/must/must.go b/internal/must/must.go
new file mode 100644
index 0000000..e472579
--- /dev/null
+++ b/internal/must/must.go
@@ -0,0 +1,24 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package must
+
+import "testing"
+
+// Succeed fails the test if err is not nil.
+func Succeed(t testing.TB, err error) {
+ if err != nil {
+ t.Fatal(err.Error())
+ }
+}
+
+// Return wraps a function returning two output values,
+// and either forwards the result value on success, or fails the test on error.
+func Return[V any](value V, err error) func(testing.TB) V {
+ return func(t testing.TB) V {
+ if err != nil {
+ t.Fatal(err.Error())
+ }
+ return value
+ }
+}