aboutsummaryrefslogtreecommitdiff
path: root/internal/must/must.go
blob: e472579b95f185e182f40ad66dca2a4e58ddef35 (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
// 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
	}
}