aboutsummaryrefslogtreecommitdiff
path: root/internal/must/must.go
blob: 7a137c68c75324ae99bae7cde25c2b365a8e5af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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) {
	t.Helper()
	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 {
		t.Helper()
		if err != nil {
			t.Fatal(err.Error())
		}
		return value
	}
}