Skip to content

Commit a80f057

Browse files
authored
Merge pull request #262 from dolmen-go/add-godoc-links
doc: add godoc links
2 parents 684bd43 + fb6d0f6 commit a80f057

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

assert/assert.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ values in tests. When an assertion fails a helpful error message is printed.
44
55
# Example usage
66
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
88
test helpers. This allows the testing package to print the filename and line
99
number of the file function that failed.
1010
@@ -67,19 +67,19 @@ message is omitted from these examples for brevity.
6767
6868
# Assert and Check
6969
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
7171
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
7474
result of the comparison, then proceed with the rest of the test case.
7575
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
7878
goroutine.
7979
8080
# Comparisons
8181
82-
Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides
82+
Package [gotest.tools/v3/assert/cmp] provides
8383
many common comparisons. Additional comparisons can be written to compare
8484
values in other ways. See the example Assert (CustomComparison).
8585
@@ -98,11 +98,11 @@ import (
9898
"gotest.tools/v3/internal/assert"
9999
)
100100

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
102102
// details about how this type is used.
103103
type BoolOrComparison interface{}
104104

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.
106106
type TestingT interface {
107107
FailNow()
108108
Fail()
@@ -133,11 +133,11 @@ type helperT interface {
133133
//
134134
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
135135
// 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].
137137
//
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
139139
// 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.
141141
func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) {
142142
if ht, ok := t.(helperT); ok {
143143
ht.Helper()
@@ -151,7 +151,7 @@ func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{})
151151
// failed, a failure message is printed, and Check returns false. If the comparison
152152
// is successful Check returns true. Check may be called from any goroutine.
153153
//
154-
// See Assert for details about the comparison arg and failure messages.
154+
// See [Assert] for details about the comparison arg and failure messages.
155155
func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) bool {
156156
if ht, ok := t.(helperT); ok {
157157
ht.Helper()
@@ -166,9 +166,9 @@ func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) b
166166
// NilError fails the test immediately if err is not nil, and includes err.Error
167167
// in the failure message.
168168
//
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
170170
// 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.
172172
func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
173173
if ht, ok := t.(helperT); ok {
174174
ht.Helper()
@@ -193,9 +193,9 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
193193
// the unified diff will be augmented by replacing whitespace characters with
194194
// visible characters to identify the whitespace difference.
195195
//
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
197197
// 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
199199
// goroutines.
200200
func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
201201
if ht, ok := t.(helperT); ok {
@@ -206,15 +206,15 @@ func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
206206
}
207207
}
208208

209-
// DeepEqual uses google/go-cmp (https://godoc.org/github.com/google/go-cmp/cmp)
209+
// DeepEqual uses [github.com/google/go-cmp/cmp]
210210
// to assert two values are equal and fails the test if they are not equal.
211211
//
212-
// Package http://pkg.go.dev/gotest.tools/v3/assert/opt provides some additional
212+
// Package [gotest.tools/v3/assert/opt] provides some additional
213213
// commonly used Options.
214214
//
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
216216
// 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
218218
// goroutines.
219219
func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
220220
if ht, ok := t.(helperT); ok {
@@ -227,13 +227,13 @@ func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) {
227227

228228
// Error fails the test if err is nil, or if err.Error is not equal to expected.
229229
// 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
232232
// errors by type.
233233
//
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
235235
// 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
237237
// goroutines.
238238
func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
239239
if ht, ok := t.(helperT); ok {
@@ -248,9 +248,9 @@ func Error(t TestingT, err error, expected string, msgAndArgs ...interface{}) {
248248
// contain the expected substring. Both err.Error and the expected substring
249249
// will be included in the failure message.
250250
//
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
252252
// 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
254254
// goroutines.
255255
func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interface{}) {
256256
if ht, ok := t.(helperT); ok {
@@ -280,12 +280,12 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
280280
// reflect.Type
281281
// The assertion fails if err does not implement the reflect.Type.
282282
//
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
284284
// 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
286286
// goroutines.
287287
//
288-
// Deprecated: Use ErrorIs
288+
// Deprecated: Use [ErrorIs]
289289
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
290290
if ht, ok := t.(helperT); ok {
291291
ht.Helper()
@@ -296,12 +296,12 @@ func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interf
296296
}
297297

298298
// 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
300300
// accepted arguments.
301301
//
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
303303
// 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
305305
// goroutines.
306306
func ErrorIs(t TestingT, err error, expected error, msgAndArgs ...interface{}) {
307307
if ht, ok := t.(helperT); ok {

assert/cmd/gty-migrate-from-testify/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Command gty-migrate-from-testify migrates packages from
3-
testify/assert and testify/require to gotest.tools/v3/assert.
3+
testify/assert and testify/require to [gotest.tools/v3/assert].
44
55
$ go get gotest.tools/v3/assert/cmd/gty-migrate-from-testify
66

assert/cmp/compare.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ import (
1212
"gotest.tools/v3/internal/format"
1313
)
1414

15-
// Comparison is a function which compares values and returns ResultSuccess if
15+
// Comparison is a function which compares values and returns [ResultSuccess] if
1616
// the actual value matches the expected value. If the values do not match the
17-
// Result will contain a message about why it failed.
17+
// [Result] will contain a message about why it failed.
1818
type Comparison func() Result
1919

20-
// DeepEqual compares two values using google/go-cmp
21-
// (https://godoc.org/github.com/google/go-cmp/cmp)
20+
// DeepEqual compares two values using [github.com/google/go-cmp/cmp]
2221
// and succeeds if the values are equal.
2322
//
2423
// The comparison can be customized using comparison Options.
25-
// Package http://pkg.go.dev/gotest.tools/v3/assert/opt provides some additional
24+
// Package [gotest.tools/v3/assert/opt] provides some additional
2625
// commonly used Options.
2726
func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison {
2827
return func() (result Result) {
@@ -61,7 +60,7 @@ func toResult(success bool, msg string) Result {
6160
return ResultFailure(msg)
6261
}
6362

64-
// RegexOrPattern may be either a *regexp.Regexp or a string that is a valid
63+
// RegexOrPattern may be either a [*regexp.Regexp] or a string that is a valid
6564
// regexp pattern.
6665
type RegexOrPattern interface{}
6766

@@ -95,7 +94,7 @@ func Regexp(re RegexOrPattern, v string) Comparison {
9594
}
9695
}
9796

98-
// Equal succeeds if x == y. See assert.Equal for full documentation.
97+
// Equal succeeds if x == y. See [gotest.tools/v3/assert.Equal] for full documentation.
9998
func Equal(x, y interface{}) Comparison {
10099
return func() Result {
101100
switch {
@@ -159,10 +158,10 @@ func Len(seq interface{}, expected int) Comparison {
159158
// slice, or array.
160159
//
161160
// If collection is a string, item must also be a string, and is compared using
162-
// strings.Contains().
161+
// [strings.Contains].
163162
// If collection is a Map, contains will succeed if item is a key in the map.
164163
// If collection is a slice or array, item is compared to each item in the
165-
// sequence using reflect.DeepEqual().
164+
// sequence using [reflect.DeepEqual].
166165
func Contains(collection interface{}, item interface{}) Comparison {
167166
return func() Result {
168167
colValue := reflect.ValueOf(collection)
@@ -259,7 +258,7 @@ func formatErrorMessage(err error) string {
259258

260259
// Nil succeeds if obj is a nil interface, pointer, or function.
261260
//
262-
// Use NilError() for comparing errors. Use Len(obj, 0) for comparing slices,
261+
// Use [gotest.tools/v3/assert.NilError] for comparing errors. Use Len(obj, 0) for comparing slices,
263262
// maps, and channels.
264263
func Nil(obj interface{}) Comparison {
265264
msgFunc := func(value reflect.Value) string {
@@ -306,9 +305,9 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
306305
//
307306
// reflect.Type
308307
//
309-
// Fails if err does not implement the reflect.Type.
308+
// Fails if err does not implement the [reflect.Type].
310309
//
311-
// Deprecated: Use ErrorIs
310+
// Deprecated: Use [ErrorIs]
312311
func ErrorType(err error, expected interface{}) Comparison {
313312
return func() Result {
314313
switch expectedType := expected.(type) {
@@ -383,7 +382,7 @@ var (
383382
)
384383

385384
// ErrorIs succeeds if errors.Is(actual, expected) returns true. See
386-
// https://golang.org/pkg/errors/#Is for accepted argument values.
385+
// [errors.Is] for accepted argument values.
387386
func ErrorIs(actual error, expected error) Comparison {
388387
return func() Result {
389388
if errors.Is(actual, expected) {

assert/cmp/result.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"gotest.tools/v3/internal/source"
1111
)
1212

13-
// A Result of a Comparison.
13+
// A Result of a [Comparison].
1414
type Result interface {
1515
Success() bool
1616
}
1717

18-
// StringResult is an implementation of Result that reports the error message
18+
// StringResult is an implementation of [Result] that reports the error message
1919
// string verbatim and does not provide any templating or formatting of the
2020
// message.
2121
type StringResult struct {
@@ -34,16 +34,16 @@ func (r StringResult) FailureMessage() string {
3434
return r.message
3535
}
3636

37-
// ResultSuccess is a constant which is returned by a ComparisonWithResult to
37+
// ResultSuccess is a constant which is returned by a [Comparison] to
3838
// indicate success.
3939
var ResultSuccess = StringResult{success: true}
4040

41-
// ResultFailure returns a failed Result with a failure message.
41+
// ResultFailure returns a failed [Result] with a failure message.
4242
func ResultFailure(message string) StringResult {
4343
return StringResult{message: message}
4444
}
4545

46-
// ResultFromError returns ResultSuccess if err is nil. Otherwise ResultFailure
46+
// ResultFromError returns [ResultSuccess] if err is nil. Otherwise [ResultFailure]
4747
// is returned with the error message as the failure message.
4848
func ResultFromError(err error) Result {
4949
if err == nil {
@@ -74,7 +74,7 @@ func (r templatedResult) UpdatedExpected(stackIndex int) error {
7474
return source.UpdateExpectedValue(stackIndex+1, r.data["x"], r.data["y"])
7575
}
7676

77-
// ResultFailureTemplate returns a Result with a template string and data which
77+
// ResultFailureTemplate returns a [Result] with a template string and data which
7878
// can be used to format a failure message. The template may access data from .Data,
7979
// the comparison args with the callArg function, and the formatNode function may
8080
// be used to format the call args.

assert/opt/opt.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
gocmp "github.com/google/go-cmp/cmp"
1212
)
1313

14-
// DurationWithThreshold returns a gocmp.Comparer for comparing time.Duration. The
14+
// DurationWithThreshold returns a [gocmp.Comparer] for comparing [time.Duration]. The
1515
// Comparer returns true if the difference between the two Duration values is
1616
// within the threshold and neither value is zero.
1717
func DurationWithThreshold(threshold time.Duration) gocmp.Option {
@@ -28,7 +28,7 @@ func cmpDuration(threshold time.Duration) func(x, y time.Duration) bool {
2828
}
2929
}
3030

31-
// TimeWithThreshold returns a gocmp.Comparer for comparing time.Time. The
31+
// TimeWithThreshold returns a [gocmp.Comparer] for comparing [time.Time]. The
3232
// Comparer returns true if the difference between the two Time values is
3333
// within the threshold and neither value is zero.
3434
func TimeWithThreshold(threshold time.Duration) gocmp.Option {
@@ -45,12 +45,12 @@ func cmpTime(threshold time.Duration) func(x, y time.Time) bool {
4545
}
4646
}
4747

48-
// PathString is a gocmp.FilterPath filter that returns true when path.String()
48+
// PathString is a [gocmp.FilterPath] filter that returns true when path.String()
4949
// matches any of the specs.
5050
//
5151
// The path spec is a dot separated string where each segment is a field name.
5252
// Slices, Arrays, and Maps are always matched against every element in the
53-
// sequence. gocmp.Indirect, gocmp.Transform, and gocmp.TypeAssertion are always
53+
// sequence. [gocmp.Indirect], [gocmp.Transform], and [gocmp.TypeAssertion] are always
5454
// ignored.
5555
//
5656
// Note: this path filter is not type safe. Incorrect paths will be silently
@@ -66,7 +66,7 @@ func PathString(specs ...string) func(path gocmp.Path) bool {
6666
}
6767
}
6868

69-
// PathDebug is a gocmp.FilerPath filter that always returns false. It prints
69+
// PathDebug is a [gocmp.FilterPath] filter that always returns false. It prints
7070
// each path it receives. It can be used to debug path matching problems.
7171
func PathDebug(path gocmp.Path) bool {
7272
fmt.Printf("PATH string=%s gostring=%s\n", path, path.GoString())
@@ -95,7 +95,7 @@ func stepTypeFields(step gocmp.PathStep) string {
9595
return ""
9696
}
9797

98-
// PathField is a gocmp.FilerPath filter that matches a struct field by name.
98+
// PathField is a [gocmp.FilterPath] filter that matches a struct field by name.
9999
// PathField will match every instance of the field in a recursive or nested
100100
// structure.
101101
func PathField(structType interface{}, field string) func(gocmp.Path) bool {

0 commit comments

Comments
 (0)