@@ -31,12 +31,12 @@ import (
31
31
"github.com/containerd/nerdctl/mod/tigron/tig"
32
32
)
33
33
34
- // TODO: once debugging output will be cleaned-up, reintroduce hexdump.
35
-
36
34
const (
35
+ markLineLength = 20
37
36
expectedSuccessDecorator = "✅️ does verify:\t \t "
38
- expectedFailDecorator = "❌ does not verify: \t "
37
+ expectedFailDecorator = "❌ FAILED! \t \t "
39
38
receivedDecorator = "👀 testing:\t \t "
39
+ annotationDecorator = "🖊️"
40
40
hyperlinkDecorator = "🔗"
41
41
)
42
42
@@ -205,49 +205,79 @@ func evaluate(testing tig.T, isSuccess bool, actual, expected any, msg ...string
205
205
func decorate (testing tig.T , isSuccess bool , actual , expected any , msg ... string ) {
206
206
testing .Helper ()
207
207
208
- header := "\t "
208
+ if _ , ok := testing .(* silentSuccess ); ! isSuccess || ! ok {
209
+ head := strings .Repeat ("<" , markLineLength )
210
+ footer := strings .Repeat (">" , markLineLength )
211
+ header := "\t "
209
212
210
- hyperlink := getTopFrameFile ()
211
- if hyperlink != "" {
212
- msg = append ([]string {hyperlink + "\n " }, msg ... )
213
- }
213
+ custom := fmt .Sprintf ("\t %s %s" , annotationDecorator , strings .Join (msg , "\n " ))
214
214
215
- msg = append (msg , fmt . Sprintf ( " \t %s`%v`" , receivedDecorator , actual ) )
215
+ msg = append ([] string { " \n " + head }, custom )
216
216
217
- if isSuccess {
218
- msg = append (msg ,
219
- fmt .Sprintf ("\t %s%v" , expectedSuccessDecorator , expected ),
220
- )
221
- } else {
222
- msg = append (msg ,
223
- fmt .Sprintf ("\t %s%v" , expectedFailDecorator , expected ),
224
- )
225
- }
217
+ hyperlink := getTopFrameFile ()
218
+ if hyperlink != "" {
219
+ msg = append ([]string {hyperlink }, msg ... )
220
+ }
226
221
227
- if _ , ok := testing .(* silentSuccess ); ! isSuccess || ! ok {
228
- testing .Log (header + strings .Join (msg , "\n " ) + "\n " )
222
+ msg = append (msg , fmt .Sprintf ("\t %s`%v`" , receivedDecorator , actual ))
223
+
224
+ if isSuccess {
225
+ msg = append (msg ,
226
+ fmt .Sprintf ("\t %s%v" , expectedSuccessDecorator , expected ),
227
+ )
228
+ } else {
229
+ msg = append (msg ,
230
+ fmt .Sprintf ("\t %s%v" , expectedFailDecorator , expected ),
231
+ )
232
+ }
233
+
234
+ testing .Log (header + strings .Join (msg , "\n " ) + "\n " + footer + "\n " )
229
235
}
230
236
}
231
237
238
+ // XXX FIXME #expert
239
+ // Because of how golang testing works, the upper frame is the one from where t.Run is being called,
240
+ // as (presumably) the passed function is starting with its own stack in a go routine.
241
+ // In the case of subtests, t.Run being called from inside Tigron will make it so that the top frame
242
+ // is case.go around line 233 (where we call Command.Run(), which is the one calling assertive).
243
+ // To possibly address this:
244
+ // plan a. just drop entirely OSC8 links and source extracts and trash all of this
245
+ // plan b. get the top frame from the root test, and pass it to subtests on a custom property, the somehow into here
246
+ // plan c. figure out a hack to call t.Run from the test file without ruining the Tigron UX
247
+ // Dereference t.Run? Return a closure to be called from the top? w/o disabling inlining in the right place?
248
+ // Short term, blacklisting /tigron (and /nerdtest) will at least prevent the wrong links from appearing in the output.
232
249
func getTopFrameFile () string {
233
- // Get the frames.
250
+ // Get the frames. Skip the first two frames - current one and caller.
234
251
//nolint:mnd // Whatever mnd...
235
- pc := make ([]uintptr , 20 )
252
+ pc := make ([]uintptr , 40 )
236
253
//nolint:mnd // Whatever mnd...
237
254
n := runtime .Callers (2 , pc )
238
255
callersFrames := runtime .CallersFrames (pc [:n ])
239
256
240
- var file string
257
+ var (
258
+ file string
259
+ lineNumber int
260
+ frame runtime.Frame
261
+ )
241
262
242
- var lineNumber int
263
+ more := true
264
+ for more {
265
+ frame , more = callersFrames .Next ()
243
266
244
- var frame runtime.Frame
245
- for range 20 {
246
- frame , _ = callersFrames .Next ()
267
+ // Once we are in the go main stack, bail out
247
268
if ! strings .Contains (frame .Function , "/" ) {
248
269
break
249
270
}
250
271
272
+ // XXX see note above
273
+ if strings .Contains (frame .File , "/tigron" ) {
274
+ continue
275
+ }
276
+
277
+ if strings .Contains (frame .File , "/nerdtest" ) {
278
+ continue
279
+ }
280
+
251
281
file = frame .File
252
282
lineNumber = frame .Line
253
283
}
@@ -282,6 +312,6 @@ func getTopFrameFile() string {
282
312
return hyperlinkDecorator + " " + (& formatter.OSC8 {
283
313
Text : line ,
284
314
Location : "file://" + file ,
285
- Line : frame . Line ,
315
+ Line : lineNumber ,
286
316
}).String ()
287
317
}
0 commit comments