Codebase list golang-github-frankban-quicktest / 36f9ce6
report: print frames for exported quicktest API calls Francesco Banconi 3 years ago
2 changed file(s) with 29 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1212 "reflect"
1313 "runtime"
1414 "strings"
15 "unicode"
1516 )
1617
1718 // reportParams holds parameters for reporting a test error.
111112 thisPackage := reflect.TypeOf(C{}).PkgPath() + "."
112113 for {
113114 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.
116126 break
117127 }
118128 fmt.Fprint(w, prefixf(prefix, "%s:%d", frame.File, frame.Line))
129129 assertReport(t, tt, want)
130130 }
131131
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
132149 func assertReport(t *testing.T, tt *testingT, want string) {
133150 got := strings.Replace(tt.fatalString(), "\t", " ", -1)
134151 // go-cmp can include non-breaking spaces in its output.