File tree 2 files changed +39
-8
lines changed
2 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,38 @@ func TestTBHelperParallel(t *T) {
71
71
}
72
72
}
73
73
74
+ func TestTBHelperLineNumer (t * T ) {
75
+ var buf bytes.Buffer
76
+ ctx := newTestContext (1 , newMatcher (regexp .MatchString , "" , "" ))
77
+ t1 := & T {
78
+ common : common {
79
+ signal : make (chan bool ),
80
+ w : & buf ,
81
+ },
82
+ context : ctx ,
83
+ }
84
+ t1 .Run ("Test" , func (t * T ) {
85
+ helperA := func (t * T ) {
86
+ t .Helper ()
87
+ t .Run ("subtest" , func (t * T ) {
88
+ t .Helper ()
89
+ t .Fatal ("fatal error message" )
90
+ })
91
+ }
92
+ helperA (t )
93
+ })
94
+
95
+ want := "helper_test.go:92: fatal error message"
96
+ got := ""
97
+ lines := strings .Split (strings .TrimSpace (buf .String ()), "\n " )
98
+ if len (lines ) > 0 {
99
+ got = strings .TrimSpace (lines [len (lines )- 1 ])
100
+ }
101
+ if got != want {
102
+ t .Errorf ("got output:\n \n %v\n want:\n \n %v" , got , want )
103
+ }
104
+ }
105
+
74
106
type noopWriter int
75
107
76
108
func (nw * noopWriter ) Write (b []byte ) (int , error ) { return len (b ), nil }
Original file line number Diff line number Diff line change @@ -509,6 +509,13 @@ func (c *common) frameSkip(skip int) runtime.Frame {
509
509
}
510
510
return prevFrame
511
511
}
512
+ // If more helper PCs have been added since we last did the conversion
513
+ if c .helperNames == nil {
514
+ c .helperNames = make (map [string ]struct {})
515
+ for pc := range c .helperPCs {
516
+ c .helperNames [pcToName (pc )] = struct {}{}
517
+ }
518
+ }
512
519
if _ , ok := c .helperNames [frame .Function ]; ! ok {
513
520
// Found a frame that wasn't inside a helper function.
514
521
return frame
@@ -521,14 +528,6 @@ func (c *common) frameSkip(skip int) runtime.Frame {
521
528
// and inserts the final newline if needed and indentation spaces for formatting.
522
529
// This function must be called with c.mu held.
523
530
func (c * common ) decorate (s string , skip int ) string {
524
- // If more helper PCs have been added since we last did the conversion
525
- if c .helperNames == nil {
526
- c .helperNames = make (map [string ]struct {})
527
- for pc := range c .helperPCs {
528
- c .helperNames [pcToName (pc )] = struct {}{}
529
- }
530
- }
531
-
532
531
frame := c .frameSkip (skip )
533
532
file := frame .File
534
533
line := frame .Line
You can’t perform that action at this time.
0 commit comments