2
2
The purpose with this file is to clone the struct alignment of the testing.T struct so we can assign a *testing.T
3
3
pointer to the *goT to have access to the internal private fields.
4
4
5
- We use this to create a Run clone method to be called from the subtest auto instrumentation
5
+ We use this to create a Run clone method to be called from the sub test auto instrumentation (because the original
6
+ method is replaced with the Patch)
6
7
*/
7
8
package testing
8
9
@@ -61,8 +62,8 @@ const maxStackLen = 50
61
62
//go:linkname matchMutex testing.matchMutex
62
63
var matchMutex sync.Mutex
63
64
64
- //go:linkname goTRunner testing.tRunner
65
- func goTRunner (t * testing.T , fn func (t * testing.T ))
65
+ //go:linkname tRunner testing.tRunner
66
+ func tRunner (t * testing.T , fn func (t * testing.T ))
66
67
67
68
//go:linkname rewrite testing.rewrite
68
69
func rewrite (s string ) string
@@ -73,14 +74,9 @@ func shouldFailFast() bool
73
74
//go:linkname (*goMatcher).fullName testing.(*matcher).fullName
74
75
func (m * goMatcher ) fullName (c * goCommon , subname string ) (name string , ok , partial bool )
75
76
76
- // this method calls the original testing.tRunner by converting *goT to *testing.T
77
- func tRunner (t * goT , fn func (t * goT )) {
78
- goTRunner (t .ToTestingT (), func (t * testing.T ) { fn (FromTestingT (t )) })
79
- }
80
-
81
77
// we clone the same (*testing.T).Run implementation because the Patch
82
78
// overwrites the original implementation with the jump
83
- func (t * goT ) Run (name string , f func (t * goT )) bool {
79
+ func (t * goT ) Run (name string , f func (t * testing. T )) bool {
84
80
atomic .StoreInt32 (& t .hasSub , 1 )
85
81
testName , ok , _ := t .context .match .fullName (& t .goCommon , name )
86
82
if ! ok || shouldFailFast () {
@@ -110,7 +106,7 @@ func (t *goT) Run(name string, f func(t *goT)) bool {
110
106
fmt .Fprintf (root .w , "=== RUN %s\n " , t .name )
111
107
root .mu .Unlock ()
112
108
}
113
- go tRunner (t , f )
109
+ go tRunner (t . ToTestingT () , f )
114
110
if ! <- t .signal {
115
111
runtime .Goexit ()
116
112
}
0 commit comments