@@ -86,6 +86,36 @@ func (asserter asserter) reportAssertionFault(defaultMsg string, a []any) {
86
86
}
87
87
}
88
88
89
+ func (asserter asserter ) newReportAssertionFault (defaultMsg string , a []any ) {
90
+ if asserter .hasStackTrace () {
91
+ if asserter .isUnitTesting () {
92
+ // Note. that the assert in the test function is printed in
93
+ // reportPanic below
94
+ const stackLvl = 4 // amount of functions before we're here
95
+ debug .PrintStackForTest (os .Stderr , stackLvl )
96
+ } else {
97
+ // amount of functions before we're here, which is different
98
+ // between runtime (this) and test-run (above)
99
+ const stackLvl = 1
100
+ debug .PrintStack (stackLvl )
101
+ }
102
+ }
103
+ if asserter .hasCallerInfo () {
104
+ defaultMsg = asserter .newCallerInfo (defaultMsg )
105
+ }
106
+ if len (a ) > 0 {
107
+ if format , ok := a [0 ].(string ); ok {
108
+ allowDefMsg := ! asserter .isErrorOnly () && defaultMsg != ""
109
+ f := x .Whom (allowDefMsg , defaultMsg + conCatErrStr + format , format )
110
+ asserter .reportPanic (fmt .Sprintf (f , a [1 :]... ))
111
+ } else {
112
+ asserter .reportPanic (fmt .Sprintln (append ([]any {defaultMsg }, a ... )))
113
+ }
114
+ } else {
115
+ asserter .reportPanic (defaultMsg )
116
+ }
117
+ }
118
+
89
119
func (asserter asserter ) reportPanic (s string ) {
90
120
if asserter .isUnitTesting () && asserter .hasCallerInfo () {
91
121
fmt .Fprintln (os .Stderr , officialTestOutputPrefix + s )
@@ -144,6 +174,24 @@ func (asserter asserter) callerInfo(msg string) (info string) {
144
174
return
145
175
}
146
176
177
+ func (asserter asserter ) newCallerInfo (msg string ) (info string ) {
178
+ ourFmtStr := shortFmtStr
179
+ if asserter .hasFormattedCallerInfo () {
180
+ ourFmtStr = longFmtStr
181
+ }
182
+
183
+ const framesToSkip = 4 // how many fn calls there is before FuncName call
184
+ includePath := asserter .isUnitTesting ()
185
+ funcName , filename , line , ok := str .FuncName (framesToSkip , includePath )
186
+ if ok {
187
+ info = fmt .Sprintf (ourFmtStr ,
188
+ filename , line ,
189
+ funcName , msg )
190
+ }
191
+
192
+ return
193
+ }
194
+
147
195
func (asserter asserter ) isErrorOnly () bool {
148
196
return asserter == asserterToError
149
197
}
0 commit comments