report: print frames for exported quicktest API calls
Francesco Banconi
3 years ago
12 | 12 |
"reflect"
|
13 | 13 |
"runtime"
|
14 | 14 |
"strings"
|
|
15 |
"unicode"
|
15 | 16 |
)
|
16 | 17 |
|
17 | 18 |
// reportParams holds parameters for reporting a test error.
|
|
111 | 112 |
thisPackage := reflect.TypeOf(C{}).PkgPath() + "."
|
112 | 113 |
for {
|
113 | 114 |
frame, more := frames.Next()
|
114 | |
if strings.HasPrefix(frame.Function, "testing.") || strings.HasPrefix(frame.Function, thisPackage) {
|
115 | |
// Do not include stdlib test runner and quicktest checker calls.
|
|
115 |
if strings.HasPrefix(frame.Function, "testing.") {
|
|
116 |
// Stop before getting back to stdlib test runner calls.
|
|
117 |
break
|
|
118 |
}
|
|
119 |
if strings.HasPrefix(frame.Function, thisPackage) {
|
|
120 |
if r := rune(frame.Function[len(thisPackage)]); unicode.IsUpper(r) {
|
|
121 |
// Continue without printing frames for quicktest exported API.
|
|
122 |
continue
|
|
123 |
}
|
|
124 |
// Stop when entering quicktest internal calls.
|
|
125 |
// This is useful for instance when using qtsuite.
|
116 | 126 |
break
|
117 | 127 |
}
|
118 | 128 |
fmt.Fprint(w, prefixf(prefix, "%s:%d", frame.File, frame.Line))
|
129 | 129 |
assertReport(t, tt, want)
|
130 | 130 |
}
|
131 | 131 |
|
|
132 |
func TestTopLevelAssertReportOutput(t *testing.T) {
|
|
133 |
tt := &testingT{}
|
|
134 |
qt.Assert(tt, 42, qt.Equals, 47)
|
|
135 |
want := `
|
|
136 |
error:
|
|
137 |
values are not equal
|
|
138 |
got:
|
|
139 |
int(42)
|
|
140 |
want:
|
|
141 |
int(47)
|
|
142 |
stack:
|
|
143 |
$file:135
|
|
144 |
qt.Assert(tt, 42, qt.Equals, 47)
|
|
145 |
`
|
|
146 |
assertReport(t, tt, want)
|
|
147 |
}
|
|
148 |
|
132 | 149 |
func assertReport(t *testing.T, tt *testingT, want string) {
|
133 | 150 |
got := strings.Replace(tt.fatalString(), "\t", " ", -1)
|
134 | 151 |
// go-cmp can include non-breaking spaces in its output.
|