Skip to content

Commit 45ac288

Browse files
committed
rename
1 parent 3687a64 commit 45ac288

File tree

1 file changed

+52
-47
lines changed
  • internal/testing/hack

1 file changed

+52
-47
lines changed

internal/testing/hack/t.go

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import (
1111
"time"
1212
)
1313

14-
// T is a replacement for github.com/mitchellh/go-testing-interface.T.
14+
// BaseT is a replacement for github.com/mitchellh/go-testing-interface.T.
1515
//
16-
// RuntimeT and tshim are two implementations of T. RuntimeT can be used to
17-
// test a test framework without the testing.T side effects of stopping
18-
// goroutine execution. tshim can be used as an adapter around a standard
19-
// testing.T.
20-
type T interface {
16+
// RuntimeT and StandardT are two implementations of BaseT. MetaT can be used
17+
// to test a testing.T-based test framework without the side effects of
18+
// stopping goroutine execution. StandardT can be used as an adapter around a
19+
// standard testing.T.
20+
//
21+
// Precedent for StandardT: the unexported tshim type in
22+
// github.com/rogpeppe/go-internal/testscript.
23+
type BaseT interface {
2124
Cleanup(func())
2225
Error(args ...interface{})
2326
Errorf(format string, args ...interface{})
@@ -46,54 +49,54 @@ type T interface {
4649
TempDir() string
4750
}
4851

49-
var _ T = RuntimeT{}
52+
var _ BaseT = MetaT{}
5053

51-
type RuntimeT struct {
54+
type MetaT struct {
5255
fail bool
5356
skip bool
5457
}
5558

56-
// Attr satisfies [T] and does nothing.
57-
func (t RuntimeT) Attr(key string, value string) {
59+
// Attr satisfies [BaseT] and does nothing.
60+
func (t MetaT) Attr(key string, value string) {
5861
}
5962

60-
// Chdir satisfies [T] and does nothing.
61-
func (r RuntimeT) Chdir(dir string) {
63+
// Chdir satisfies [BaseT] and does nothing.
64+
func (r MetaT) Chdir(dir string) {
6265
}
6366

64-
// Cleanup satisfies [T] and does nothing.
65-
func (r RuntimeT) Cleanup(_ func()) {
67+
// Cleanup satisfies [BaseT] and does nothing.
68+
func (r MetaT) Cleanup(_ func()) {
6669
}
6770

68-
// Context satisfies [T] and returns context.TODO()
69-
func (r RuntimeT) Context() context.Context {
71+
// Context satisfies [BaseT] and returns context.TODO()
72+
func (r MetaT) Context() context.Context {
7073
return context.TODO()
7174
}
7275

73-
// Deadline satisfies [T] and returns zero-values.
74-
func (r RuntimeT) Deadline() (deadline time.Time, ok bool) {
76+
// Deadline satisfies [BaseT] and returns zero-values.
77+
func (r MetaT) Deadline() (deadline time.Time, ok bool) {
7578
return time.Time{}, false
7679
}
7780

7881
// Error is equivalent to Log followed by Fail.
79-
func (t RuntimeT) Error(args ...interface{}) {
82+
func (t MetaT) Error(args ...interface{}) {
8083
t.Log(args)
8184
t.Fail()
8285
}
8386

8487
// Errorf is equivalent to Logf followed by Fail.
85-
func (t RuntimeT) Errorf(format string, args ...interface{}) {
88+
func (t MetaT) Errorf(format string, args ...interface{}) {
8689
t.Logf(format, args...)
8790
t.Fail()
8891
}
8992

9093
// Fail marks the function as having failed but continues execution.
91-
func (t RuntimeT) Fail() {
94+
func (t MetaT) Fail() {
9295
t.fail = true
9396
}
9497

9598
// Failed reports whether the function has failed.
96-
func (t RuntimeT) Failed() bool {
99+
func (t MetaT) Failed() bool {
97100
return t.fail
98101
}
99102

@@ -102,99 +105,101 @@ func (t RuntimeT) Failed() bool {
102105
//
103106
// For compatibility, it mimics the string argument from
104107
// mitchellg/go-testing-interface.
105-
func (t RuntimeT) FailNow() {
108+
func (t MetaT) FailNow() {
106109
panic("testing.T failed, see logs for output")
107110
}
108111

109112
// Fatal is equivalent to Log followed by FailNow.
110-
func (t RuntimeT) Fatal(args ...interface{}) {
113+
func (t MetaT) Fatal(args ...interface{}) {
111114
t.Log(args)
112115
t.FailNow()
113116
}
114117

115118
// Fatalf is equivalent to Logf followed by FailNow.
116-
func (t RuntimeT) Fatalf(format string, args ...interface{}) {
119+
func (t MetaT) Fatalf(format string, args ...interface{}) {
117120
t.Logf(format, args...)
118121
t.FailNow()
119122
}
120123

121124
// Log formats its arguments using default formatting, analogous to
122125
// fmt.Println,, and records the text to standard output.
123-
func (t RuntimeT) Log(args ...interface{}) {
126+
func (t MetaT) Log(args ...interface{}) {
124127
fmt.Println(fmt.Sprintf("%v", args))
125128
}
126129

127130
// Logf formats its arguments according to the format, analogous to fmt.Printf,
128131
// and records the text to standard output.
129-
func (t RuntimeT) Logf(format string, args ...interface{}) {
132+
func (t MetaT) Logf(format string, args ...interface{}) {
130133
fmt.Println(fmt.Sprintf(format, args...))
131134
}
132135

133-
// Helper satisfies [T] and does nothing.
134-
func (r RuntimeT) Helper() {
136+
// Helper satisfies [BaseT] and does nothing.
137+
func (r MetaT) Helper() {
135138
}
136139

137-
// Name satisfies [T] and returns an empty string.
138-
func (r RuntimeT) Name() string {
140+
// Name satisfies [BaseT] and returns an empty string.
141+
func (r MetaT) Name() string {
139142
return ""
140143
}
141144

142-
// Output satisfied [T] and returns io.Discard.
143-
func (r RuntimeT) Output() io.Writer {
145+
// Output satisfied [BaseT] and returns io.Discard.
146+
func (r MetaT) Output() io.Writer {
144147
return io.Discard
145148
}
146149

147-
// Parallel satisfies [T] and does nothing.
148-
func (r RuntimeT) Parallel() {
150+
// Parallel satisfies [BaseT] and does nothing.
151+
func (r MetaT) Parallel() {
149152
panic("parallel not implemented") // TODO: Implement
150153
}
151154

152-
// Setenv satisfies [T] and does nothing.
153-
func (r RuntimeT) Setenv(key string, value string) {
155+
// Setenv satisfies [BaseT] and does nothing.
156+
func (r MetaT) Setenv(key string, value string) {
154157
}
155158

156159
// SkipNow marks the test as having been skipped.
157160
//
158161
// As a practical consideration, this does not stop execution in the way that
159162
// [testing.T.SkipNow] does -- RuntimeT.Run does not run its function in a
160163
// separate goroutine.
161-
func (t RuntimeT) SkipNow() {
164+
func (t MetaT) SkipNow() {
162165
t.Skip()
163166
}
164167

165168
// Skipf is equivalent to Logf followed by SkipNow.
166-
func (t RuntimeT) Skipf(format string, args ...interface{}) {
169+
func (t MetaT) Skipf(format string, args ...interface{}) {
167170
t.Logf(format, args...)
168171
t.Skip()
169172
}
170173

171-
// TempDir satisfies [T] and returns "/dev/null".
172-
func (r RuntimeT) TempDir() string {
174+
// TempDir satisfies [BaseT] and returns "/dev/null".
175+
func (r MetaT) TempDir() string {
173176
return "/dev/null"
174177
}
175178

176179
// Skip is equivalent to Log followed by SkipNow.
177-
func (t RuntimeT) Skip(args ...interface{}) {
180+
func (t MetaT) Skip(args ...interface{}) {
178181
t.Log(args)
179182
t.skip = true
180183
}
181184

182185
// Skipped reports whether the test was skipped.
183-
func (t RuntimeT) Skipped() bool {
186+
func (t MetaT) Skipped() bool {
184187
return t.skip
185188
}
186189

187-
// tshim embeds a [testing.T] and satisfies [T].
188-
type tshim struct {
190+
var _ BaseT = StandardT{}
191+
192+
// StandardT embeds a [testing.T] and satisfies [BaseT].
193+
type StandardT struct {
189194
*testing.T
190195
}
191196

192197
// Run runs f as a subtest of t.
193198
//
194199
// As practical consideration, this does nsot run its function in a separate
195200
// goroutine and the name is not used.
196-
func (t tshim) Run(name string, f func(T)) bool {
201+
func (t StandardT) Run(name string, f func(BaseT)) bool {
197202
return t.T.Run(name, func(t *testing.T) {
198-
f(tshim{t})
203+
f(StandardT{t})
199204
})
200205
}

0 commit comments

Comments
 (0)