File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,18 @@ func (e *Env) Defer(f func()) {
6969 e .ts .Defer (f )
7070}
7171
72+ // T returns the t argument passed to the current test by the T.Run method.
73+ // Note that if the tests were started by calling Run,
74+ // the returned value will implement testing.TB.
75+ // Note that, despite that, the underlying value will not be of type
76+ // *testing.T because *testing.T does not implement T.
77+ //
78+ // If Cleanup is called on the returned value, the function will run
79+ // after any functions passed to Env.Defer.
80+ func (e * Env ) T () T {
81+ return e .ts .t
82+ }
83+
7284// Params holds parameters for a call to Run.
7385type Params struct {
7486 // Dir holds the name of the directory holding the scripts.
Original file line number Diff line number Diff line change @@ -113,6 +113,12 @@ func TestScripts(t *testing.T) {
113113 if ts .Value ("somekey" ) != 1234 {
114114 ts .Fatalf ("test-values did not see expected value" )
115115 }
116+ if ts .Value ("t" ).(T ) != ts .t {
117+ ts .Fatalf ("test-values did not see expected t" )
118+ }
119+ if _ , ok := ts .Value ("t" ).(testing.TB ); ! ok {
120+ ts .Fatalf ("test-values t does not implement testing.TB" )
121+ }
116122 },
117123 "testreadfile" : func (ts * TestScript , neg bool , args []string ) {
118124 if len (args ) != 1 {
@@ -165,6 +171,7 @@ func TestScripts(t *testing.T) {
165171 }
166172 env .Values ["setupFilenames" ] = setupFilenames
167173 env .Values ["somekey" ] = 1234
174+ env .Values ["t" ] = env .T ()
168175 env .Vars = append (env .Vars ,
169176 "GONOSUMDB=*" ,
170177 )
You can’t perform that action at this time.
0 commit comments