-
Notifications
You must be signed in to change notification settings - Fork 0
/
actually_util.go
84 lines (68 loc) · 1.57 KB
/
actually_util.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
79
80
81
82
83
84
package actually
// internal utils
import (
"fmt"
"os"
"regexp"
"strings"
w "github.com/bayashi/actually/witness"
)
func (a *testingA) fail(w *w.Witness, reason string) *testingA {
a.t.Helper()
a.doFail(w, reason)
return a
}
func (a *testingA) failf(w *w.Witness, reasonFormat string, args ...any) *testingA {
a.t.Helper()
a.doFail(w, fmt.Sprintf(reasonFormat, args...))
return a
}
var regexpMine = regexp.MustCompile(`github\.com/bayashi/actually(@v[0-9][0-9\.]+[0-9])?/`)
var skipMine = func(filepath string) bool {
return regexpMine.FindStringSubmatch(filepath) != nil
}
var funcFail = func(a *testingA, w *w.Witness, reason string) {
a.t.Helper()
if a.failNow != nil && !*a.failNow {
w.Fail(a.t, reason, skipMine)
} else if (a.failNow != nil && *a.failNow) || len(os.Getenv(envKey_FailNow)) > 0 {
w.FailNow(a.t, reason, skipMine)
} else {
w.Fail(a.t, reason, skipMine)
}
}
func (a *testingA) doFail(w *w.Witness, reason string) {
a.t.Helper()
a.failed = true
funcFail(a, w, reason)
}
func (a *testingA) naming(testNames ...string) string {
if a.name != "" {
if len(testNames) > 0 {
n := []string{a.name}
n = append(n, testNames...)
return strings.Join(n, ".")
} else {
return a.name
}
} else {
return strings.Join(testNames, ".")
}
}
func invalidCall(a *testingA) {
if !a.setGot {
panic(panicReason_NotCalledGot)
}
}
func (a *testingA) wi() *w.Witness {
wi := w.New()
wi.Name(a.name)
if len(a.debugInfo) > 0 {
for _, di := range a.debugInfo {
for lable, info := range di {
wi.Debug(lable, info...)
}
}
}
return wi
}