From 1a187cb04b3130572a5b3f7513c1e55b0a59fdc2 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Mon, 13 Apr 2026 11:39:36 +0200 Subject: reduce code duplication in benchmark tests --- internal/must/must.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/must/must.go (limited to 'internal') 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 +// 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 + } +} -- cgit v1.2.3