-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
44 lines (39 loc) · 832 Bytes
/
error.go
File metadata and controls
44 lines (39 loc) · 832 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package assert
import (
"testing"
)
// NoError checks if there was no error provided.
func NoError(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
}
// NoErrorR checks if there was no error provided and returns a value.
func NoErrorR[T any](t *testing.T) func(T, error) T {
t.Helper()
return func(r T, err error) T {
t.Helper()
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
return r
}
}
// Error checks if there was an error provided.
func Error(t *testing.T, err error) {
t.Helper()
if err == nil {
t.Fatalf("No error returned")
}
}
// ErrorR checks if there was an error provided.
func ErrorR(t *testing.T) func(any, error) {
t.Helper()
return func(r any, err error) {
t.Helper()
if err == nil {
t.Fatalf("No error returned")
}
}
}