@@ -4,7 +4,7 @@ values in tests. When an assertion fails a helpful error message is printed.
4
4
5
5
# Example usage
6
6
7
- All the assertions in this package use testing.T.Helper to mark themselves as
7
+ All the assertions in this package use [ testing.T.Helper] to mark themselves as
8
8
test helpers. This allows the testing package to print the filename and line
9
9
number of the file function that failed.
10
10
@@ -67,19 +67,19 @@ message is omitted from these examples for brevity.
67
67
68
68
# Assert and Check
69
69
70
- Assert and Check are very similar, they both accept a Comparison, and fail
70
+ [ Assert] and [ Check] are very similar, they both accept a [cmp. Comparison] , and fail
71
71
the test when the comparison fails. The one difference is that Assert uses
72
- testing.T.FailNow to fail the test, which will end the test execution immediately.
73
- Check uses testing.T.Fail to fail the test, which allows it to return the
72
+ [ testing.T.FailNow] to fail the test, which will end the test execution immediately.
73
+ Check uses [ testing.T.Fail] to fail the test, which allows it to return the
74
74
result of the comparison, then proceed with the rest of the test case.
75
75
76
- Like testing.T.FailNow, Assert must be called from the goroutine running the test,
77
- not from other goroutines created during the test. Check is safe to use from any
76
+ Like [ testing.T.FailNow], [ Assert] must be called from the goroutine running the test,
77
+ not from other goroutines created during the test. [ Check] is safe to use from any
78
78
goroutine.
79
79
80
80
# Comparisons
81
81
82
- Package http://pkg.go.dev/ gotest.tools/v3/assert/cmp provides
82
+ Package [ gotest.tools/v3/assert/cmp] provides
83
83
many common comparisons. Additional comparisons can be written to compare
84
84
values in other ways. See the example Assert (CustomComparison).
85
85
@@ -98,11 +98,11 @@ import (
98
98
"gotest.tools/v3/internal/assert"
99
99
)
100
100
101
- // BoolOrComparison can be a bool, cmp.Comparison, or error. See Assert for
101
+ // BoolOrComparison can be a bool, [ cmp.Comparison] , or error. See [ Assert] for
102
102
// details about how this type is used.
103
103
type BoolOrComparison interface {}
104
104
105
- // TestingT is the subset of testing.T used by the assert package.
105
+ // TestingT is the subset of [ testing.T] (see also [testing.TB]) used by the assert package.
106
106
type TestingT interface {
107
107
FailNow ()
108
108
Fail ()
@@ -133,11 +133,11 @@ type helperT interface {
133
133
//
134
134
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
135
135
// may be either a single string, or a format string and args that will be
136
- // passed to fmt.Sprintf.
136
+ // passed to [ fmt.Sprintf] .
137
137
//
138
- // Assert uses t. FailNow to fail the test. Like t.FailNow, Assert must be called
138
+ // Assert uses [testing.TB. FailNow] to fail the test. Like t.FailNow, Assert must be called
139
139
// from the goroutine running the test function, not from other
140
- // goroutines created during the test. Use Check from other goroutines.
140
+ // goroutines created during the test. Use [ Check] from other goroutines.
141
141
func Assert (t TestingT , comparison BoolOrComparison , msgAndArgs ... interface {}) {
142
142
if ht , ok := t .(helperT ); ok {
143
143
ht .Helper ()
@@ -151,7 +151,7 @@ func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{})
151
151
// failed, a failure message is printed, and Check returns false. If the comparison
152
152
// is successful Check returns true. Check may be called from any goroutine.
153
153
//
154
- // See Assert for details about the comparison arg and failure messages.
154
+ // See [ Assert] for details about the comparison arg and failure messages.
155
155
func Check (t TestingT , comparison BoolOrComparison , msgAndArgs ... interface {}) bool {
156
156
if ht , ok := t .(helperT ); ok {
157
157
ht .Helper ()
@@ -166,9 +166,9 @@ func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) b
166
166
// NilError fails the test immediately if err is not nil, and includes err.Error
167
167
// in the failure message.
168
168
//
169
- // NilError uses t. FailNow to fail the test. Like t.FailNow, NilError must be
169
+ // NilError uses [testing.TB. FailNow] to fail the test. Like t.FailNow, NilError must be
170
170
// called from the goroutine running the test function, not from other
171
- // goroutines created during the test. Use Check from other goroutines.
171
+ // goroutines created during the test. Use [ Check] from other goroutines.
172
172
func NilError (t TestingT , err error , msgAndArgs ... interface {}) {
173
173
if ht , ok := t .(helperT ); ok {
174
174
ht .Helper ()
@@ -193,9 +193,9 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
193
193
// the unified diff will be augmented by replacing whitespace characters with
194
194
// visible characters to identify the whitespace difference.
195
195
//
196
- // Equal uses t. FailNow to fail the test. Like t.FailNow, Equal must be
196
+ // Equal uses [testing.T. FailNow] to fail the test. Like t.FailNow, Equal must be
197
197
// called from the goroutine running the test function, not from other
198
- // goroutines created during the test. Use Check with cmp.Equal from other
198
+ // goroutines created during the test. Use [ Check] with [ cmp.Equal] from other
199
199
// goroutines.
200
200
func Equal (t TestingT , x , y interface {}, msgAndArgs ... interface {}) {
201
201
if ht , ok := t .(helperT ); ok {
@@ -206,15 +206,15 @@ func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
206
206
}
207
207
}
208
208
209
- // DeepEqual uses google/go-cmp (https://godoc.org/ github.com/google/go-cmp/cmp)
209
+ // DeepEqual uses [ github.com/google/go-cmp/cmp]
210
210
// to assert two values are equal and fails the test if they are not equal.
211
211
//
212
- // Package http://pkg.go.dev/ gotest.tools/v3/assert/opt provides some additional
212
+ // Package [ gotest.tools/v3/assert/opt] provides some additional
213
213
// commonly used Options.
214
214
//
215
- // DeepEqual uses t. FailNow to fail the test. Like t.FailNow, DeepEqual must be
215
+ // DeepEqual uses [testing.T. FailNow] to fail the test. Like t.FailNow, DeepEqual must be
216
216
// called from the goroutine running the test function, not from other
217
- // goroutines created during the test. Use Check with cmp.DeepEqual from other
217
+ // goroutines created during the test. Use [ Check] with [ cmp.DeepEqual] from other
218
218
// goroutines.
219
219
func DeepEqual (t TestingT , x , y interface {}, opts ... gocmp.Option ) {
220
220
if ht , ok := t .(helperT ); ok {
@@ -227,13 +227,13 @@ func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
227
227
228
228
// Error fails the test if err is nil, or if err.Error is not equal to expected.
229
229
// Both err.Error and expected will be included in the failure message.
230
- // Error performs an exact match of the error text. Use ErrorContains if only
231
- // part of the error message is relevant. Use ErrorType or ErrorIs to compare
230
+ // Error performs an exact match of the error text. Use [ ErrorContains] if only
231
+ // part of the error message is relevant. Use [ ErrorType] or [ ErrorIs] to compare
232
232
// errors by type.
233
233
//
234
- // Error uses t. FailNow to fail the test. Like t.FailNow, Error must be
234
+ // Error uses [testing.T. FailNow] to fail the test. Like t.FailNow, Error must be
235
235
// called from the goroutine running the test function, not from other
236
- // goroutines created during the test. Use Check with cmp.Error from other
236
+ // goroutines created during the test. Use [ Check] with [ cmp.Error] from other
237
237
// goroutines.
238
238
func Error (t TestingT , err error , expected string , msgAndArgs ... interface {}) {
239
239
if ht , ok := t .(helperT ); ok {
@@ -248,9 +248,9 @@ func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
248
248
// contain the expected substring. Both err.Error and the expected substring
249
249
// will be included in the failure message.
250
250
//
251
- // ErrorContains uses t. FailNow to fail the test. Like t.FailNow, ErrorContains
251
+ // ErrorContains uses [testing.T. FailNow] to fail the test. Like t.FailNow, ErrorContains
252
252
// must be called from the goroutine running the test function, not from other
253
- // goroutines created during the test. Use Check with cmp.ErrorContains from other
253
+ // goroutines created during the test. Use [ Check] with [ cmp.ErrorContains] from other
254
254
// goroutines.
255
255
func ErrorContains (t TestingT , err error , substring string , msgAndArgs ... interface {}) {
256
256
if ht , ok := t .(helperT ); ok {
@@ -280,12 +280,12 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
280
280
// reflect.Type
281
281
// The assertion fails if err does not implement the reflect.Type.
282
282
//
283
- // ErrorType uses t. FailNow to fail the test. Like t.FailNow, ErrorType
283
+ // ErrorType uses [testing.T. FailNow] to fail the test. Like t.FailNow, ErrorType
284
284
// must be called from the goroutine running the test function, not from other
285
- // goroutines created during the test. Use Check with cmp.ErrorType from other
285
+ // goroutines created during the test. Use [ Check] with [ cmp.ErrorType] from other
286
286
// goroutines.
287
287
//
288
- // Deprecated: Use ErrorIs
288
+ // Deprecated: Use [ ErrorIs]
289
289
func ErrorType (t TestingT , err error , expected interface {}, msgAndArgs ... interface {}) {
290
290
if ht , ok := t .(helperT ); ok {
291
291
ht .Helper ()
@@ -296,12 +296,12 @@ func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interf
296
296
}
297
297
298
298
// ErrorIs fails the test if err is nil, or the error does not match expected
299
- // when compared using errors.Is. See https://golang.org/pkg/ errors/#Is for
299
+ // when compared using errors.Is. See [ errors.Is] for
300
300
// accepted arguments.
301
301
//
302
- // ErrorIs uses t. FailNow to fail the test. Like t.FailNow, ErrorIs
302
+ // ErrorIs uses [testing.T. FailNow] to fail the test. Like t.FailNow, ErrorIs
303
303
// must be called from the goroutine running the test function, not from other
304
- // goroutines created during the test. Use Check with cmp.ErrorIs from other
304
+ // goroutines created during the test. Use [ Check] with [ cmp.ErrorIs] from other
305
305
// goroutines.
306
306
func ErrorIs (t TestingT , err error , expected error , msgAndArgs ... interface {}) {
307
307
if ht , ok := t .(helperT ); ok {
0 commit comments