22 The purpose with this file is to clone the struct alignment of the testing.T struct so we can assign a *testing.T
33 pointer to the *goT to have access to the internal private fields.
44
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)
67*/
78package testing
89
@@ -61,8 +62,8 @@ const maxStackLen = 50
6162//go:linkname matchMutex testing.matchMutex
6263var matchMutex sync.Mutex
6364
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 ))
6667
6768//go:linkname rewrite testing.rewrite
6869func rewrite (s string ) string
@@ -73,14 +74,9 @@ func shouldFailFast() bool
7374//go:linkname (*goMatcher).fullName testing.(*matcher).fullName
7475func (m * goMatcher ) fullName (c * goCommon , subname string ) (name string , ok , partial bool )
7576
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-
8177// we clone the same (*testing.T).Run implementation because the Patch
8278// 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 {
8480 atomic .StoreInt32 (& t .hasSub , 1 )
8581 testName , ok , _ := t .context .match .fullName (& t .goCommon , name )
8682 if ! ok || shouldFailFast () {
@@ -110,7 +106,7 @@ func (t *goT) Run(name string, f func(t *goT)) bool {
110106 fmt .Fprintf (root .w , "=== RUN %s\n " , t .name )
111107 root .mu .Unlock ()
112108 }
113- go tRunner (t , f )
109+ go tRunner (t . ToTestingT () , f )
114110 if ! <- t .signal {
115111 runtime .Goexit ()
116112 }
0 commit comments