-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers_succeed.go
44 lines (36 loc) · 971 Bytes
/
matchers_succeed.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
package justest
import (
"reflect"
)
var (
succeedValueExtractor = NewValueExtractor(ExtractSameValue)
)
func init() {
succeedValueExtractor[reflect.Chan] = NewChannelExtractor(succeedValueExtractor, true)
succeedValueExtractor[reflect.Func] = NewFuncExtractor(succeedValueExtractor, true)
}
//go:noinline
func Succeed() Matcher {
return MatcherFunc(func(t T, actuals ...any) {
GetHelper(t).Helper()
resolvedActuals := make([]any, 0, len(actuals))
for _, actual := range actuals {
resolvedActual, found := succeedValueExtractor.ExtractValue(t, actual)
if found {
resolvedActuals = append(resolvedActuals, resolvedActual)
}
}
l := len(resolvedActuals)
if l == 0 {
return
}
last := succeedValueExtractor.MustExtractValue(t, resolvedActuals[l-1])
if last == nil {
return
}
lastRT := reflect.TypeOf(last)
if lastRT.AssignableTo(reflect.TypeOf((*error)(nil)).Elem()) {
t.Fatalf("Error occurred: %+v", last)
}
})
}