-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchers_not.go
78 lines (64 loc) · 1.49 KB
/
matchers_not.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package justest
import (
"fmt"
. "github.com/arikkfir/justest/internal"
)
type inverseT struct {
parent T
failure *FormatAndArgs
}
//go:noinline
func (t *inverseT) Name() string {
return t.parent.Name()
}
//go:noinline
func (t *inverseT) Cleanup(f func()) { GetHelper(t).Helper(); t.parent.Cleanup(f) }
//go:noinline
func (t *inverseT) Failed() bool {
GetHelper(t.parent).Helper()
return t.failure != nil
}
//go:noinline
func (t *inverseT) Fatalf(format string, args ...any) {
GetHelper(t.parent).Helper()
t.failure = &FormatAndArgs{Format: &format, Args: args}
panic(t)
}
//go:noinline
func (t *inverseT) Log(args ...any) {
GetHelper(t.parent).Helper()
t.parent.Log(args...)
}
//go:noinline
func (t *inverseT) Logf(format string, args ...any) {
GetHelper(t.parent).Helper()
t.parent.Logf(format, args...)
}
//go:noinline
func (t *inverseT) GetParent() T {
return t.parent
}
//go:noinline
func Not(m Matcher) Matcher {
return MatcherFunc(func(t T, actuals ...any) {
GetHelper(t).Helper()
tt := &inverseT{parent: t}
defer func() {
GetHelper(t).Helper()
if r := recover(); r != nil {
if r == tt {
// Matcher failed - good!
} else if err, ok := r.(error); ok {
// Unexpected panic - bubble it up
panic(fmt.Errorf("unexpected panic: %w", err))
} else {
// Unexpected panic - bubble it up
panic(fmt.Errorf("unexpected panic: %+v", r))
}
} else {
t.Fatalf("Expected mismatch did not happen")
}
}()
m.Assert(tt, actuals...)
})
}