Skip to content

Commit 0889b39

Browse files
cuishuanggopherbot
authored andcommitted
testing: add available godoc link
Change-Id: I8f4d097601796f53176d490cddf8832b7caa4c05 Reviewed-on: https://go-review.googlesource.com/c/go/+/539836 Run-TryBot: shuang cui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 5cb0839 commit 0889b39

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

src/testing/benchmark.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type InternalBenchmark struct {
7777
F func(b *B)
7878
}
7979

80-
// B is a type passed to Benchmark functions to manage benchmark
80+
// B is a type passed to [Benchmark] functions to manage benchmark
8181
// timing and to specify the number of iterations to run.
8282
//
8383
// A benchmark ends when its Benchmark function returns or calls any of the methods
@@ -117,7 +117,7 @@ type B struct {
117117

118118
// StartTimer starts timing a test. This function is called automatically
119119
// before a benchmark starts, but it can also be used to resume timing after
120-
// a call to StopTimer.
120+
// a call to [B.StopTimer].
121121
func (b *B) StartTimer() {
122122
if !b.timerOn {
123123
runtime.ReadMemStats(&memStats)
@@ -321,7 +321,7 @@ func (b *B) launch() {
321321

322322
// Elapsed returns the measured elapsed time of the benchmark.
323323
// The duration reported by Elapsed matches the one measured by
324-
// StartTimer, StopTimer, and ResetTimer.
324+
// [B.StartTimer], [B.StopTimer], and [B.ResetTimer].
325325
func (b *B) Elapsed() time.Duration {
326326
d := b.duration
327327
if b.timerOn {
@@ -413,7 +413,7 @@ func (r BenchmarkResult) AllocedBytesPerOp() int64 {
413413
// benchmark name.
414414
// Extra metrics override built-in metrics of the same name.
415415
// String does not include allocs/op or B/op, since those are reported
416-
// by MemString.
416+
// by [BenchmarkResult.MemString].
417417
func (r BenchmarkResult) String() string {
418418
buf := new(strings.Builder)
419419
fmt.Fprintf(buf, "%8d", r.N)
@@ -752,13 +752,13 @@ func (pb *PB) Next() bool {
752752
// RunParallel runs a benchmark in parallel.
753753
// It creates multiple goroutines and distributes b.N iterations among them.
754754
// The number of goroutines defaults to GOMAXPROCS. To increase parallelism for
755-
// non-CPU-bound benchmarks, call SetParallelism before RunParallel.
755+
// non-CPU-bound benchmarks, call [B.SetParallelism] before RunParallel.
756756
// RunParallel is usually used with the go test -cpu flag.
757757
//
758758
// The body function will be run in each goroutine. It should set up any
759759
// goroutine-local state and then iterate until pb.Next returns false.
760-
// It should not use the StartTimer, StopTimer, or ResetTimer functions,
761-
// because they have global effect. It should also not call Run.
760+
// It should not use the [B.StartTimer], [B.StopTimer], or [B.ResetTimer] functions,
761+
// because they have global effect. It should also not call [B.Run].
762762
//
763763
// RunParallel reports ns/op values as wall time for the benchmark as a whole,
764764
// not the sum of wall time or CPU time over each parallel goroutine.
@@ -803,7 +803,7 @@ func (b *B) RunParallel(body func(*PB)) {
803803
}
804804
}
805805

806-
// SetParallelism sets the number of goroutines used by RunParallel to p*GOMAXPROCS.
806+
// SetParallelism sets the number of goroutines used by [B.RunParallel] to p*GOMAXPROCS.
807807
// There is usually no need to call SetParallelism for CPU-bound benchmarks.
808808
// If p is less than 1, this call will have no effect.
809809
func (b *B) SetParallelism(p int) {
@@ -815,8 +815,8 @@ func (b *B) SetParallelism(p int) {
815815
// Benchmark benchmarks a single function. It is useful for creating
816816
// custom benchmarks that do not use the "go test" command.
817817
//
818-
// If f depends on testing flags, then Init must be used to register
819-
// those flags before calling Benchmark and before calling flag.Parse.
818+
// If f depends on testing flags, then [Init] must be used to register
819+
// those flags before calling Benchmark and before calling [flag.Parse].
820820
//
821821
// If f calls Run, the result will be an estimate of running all its
822822
// subbenchmarks that don't call Run in sequence in a single benchmark.

src/testing/fstest/mapfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
//
2020
// The map need not include parent directories for files contained
2121
// in the map; those will be synthesized if needed.
22-
// But a directory can still be included by setting the MapFile.Mode's [fs.ModeDir] bit;
22+
// But a directory can still be included by setting the [MapFile.Mode]'s [fs.ModeDir] bit;
2323
// this may be necessary for detailed control over the directory's [fs.FileInfo]
2424
// or to create an empty directory.
2525
//

src/testing/fuzz.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type InternalFuzzTarget struct {
5959
// by (*F).Add and entries in the testdata/fuzz/<FuzzTestName> directory. After
6060
// any necessary setup and calls to (*F).Add, the fuzz test must then call
6161
// (*F).Fuzz to provide the fuzz target. See the testing package documentation
62-
// for an example, and see the F.Fuzz and F.Add method documentation for
62+
// for an example, and see the [F.Fuzz] and [F.Add] method documentation for
6363
// details.
6464
//
6565
// *F methods can only be called before (*F).Fuzz. Once the test is
@@ -206,7 +206,7 @@ var supportedTypes = map[reflect.Type]bool{
206206
//
207207
// When fuzzing, F.Fuzz does not return until a problem is found, time runs out
208208
// (set with -fuzztime), or the test process is interrupted by a signal. F.Fuzz
209-
// should be called exactly once, unless F.Skip or F.Fail is called beforehand.
209+
// should be called exactly once, unless F.Skip or [F.Fail] is called beforehand.
210210
func (f *F) Fuzz(ff any) {
211211
if f.fuzzCalled {
212212
panic("testing: F.Fuzz called more than once")

src/testing/internal/testdeps/deps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
// TestDeps is an implementation of the testing.testDeps interface,
30-
// suitable for passing to testing.MainStart.
30+
// suitable for passing to [testing.MainStart].
3131
type TestDeps struct{}
3232

3333
var matchPat string

src/testing/iotest/logger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (l *writeLogger) Write(p []byte) (n int, err error) {
2525
}
2626

2727
// NewWriteLogger returns a writer that behaves like w except
28-
// that it logs (using log.Printf) each write to standard error,
28+
// that it logs (using [log.Printf]) each write to standard error,
2929
// printing the prefix and the hexadecimal data written.
3030
func NewWriteLogger(prefix string, w io.Writer) io.Writer {
3131
return &writeLogger{prefix, w}
@@ -47,7 +47,7 @@ func (l *readLogger) Read(p []byte) (n int, err error) {
4747
}
4848

4949
// NewReadLogger returns a reader that behaves like r except
50-
// that it logs (using log.Printf) each read to standard error,
50+
// that it logs (using [log.Printf]) each read to standard error,
5151
// printing the prefix and the hexadecimal data read.
5252
func NewReadLogger(prefix string, r io.Reader) io.Reader {
5353
return &readLogger{prefix, r}

src/testing/iotest/reader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (r *dataErrReader) Read(p []byte) (n int, err error) {
7373
// ErrTimeout is a fake timeout error.
7474
var ErrTimeout = errors.New("timeout")
7575

76-
// TimeoutReader returns ErrTimeout on the second read
76+
// TimeoutReader returns [ErrTimeout] on the second read
7777
// with no data. Subsequent calls to read succeed.
7878
func TimeoutReader(r io.Reader) io.Reader { return &timeoutReader{r, 0} }
7979

@@ -90,7 +90,7 @@ func (r *timeoutReader) Read(p []byte) (int, error) {
9090
return r.r.Read(p)
9191
}
9292

93-
// ErrReader returns an io.Reader that returns 0, err from all Read calls.
93+
// ErrReader returns an [io.Reader] that returns 0, err from all Read calls.
9494
func ErrReader(err error) io.Reader {
9595
return &errReader{err: err}
9696
}
@@ -128,7 +128,7 @@ func (r *smallByteReader) Read(p []byte) (int, error) {
128128

129129
// TestReader tests that reading from r returns the expected file content.
130130
// It does reads of different sizes, until EOF.
131-
// If r implements io.ReaderAt or io.Seeker, TestReader also checks
131+
// If r implements [io.ReaderAt] or [io.Seeker], TestReader also checks
132132
// that those operations behave as they should.
133133
//
134134
// If TestReader finds any misbehaviors, it returns an error reporting them.

src/testing/quick/quick.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func randInt64(rand *rand.Rand) int64 {
5454
const complexSize = 50
5555

5656
// Value returns an arbitrary value of the given type.
57-
// If the type implements the Generator interface, that will be used.
57+
// If the type implements the [Generator] interface, that will be used.
5858
// Note: To create arbitrary values for structs, all the fields must be exported.
5959
func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool) {
6060
return sizedValue(t, rand, complexSize)
@@ -234,7 +234,7 @@ func (s *CheckError) Error() string {
234234
return fmt.Sprintf("#%d: failed on input %s", s.Count, toString(s.In))
235235
}
236236

237-
// A CheckEqualError is the result CheckEqual finding an error.
237+
// A CheckEqualError is the result [CheckEqual] finding an error.
238238
type CheckEqualError struct {
239239
CheckError
240240
Out1 []any
@@ -248,7 +248,7 @@ func (s *CheckEqualError) Error() string {
248248
// Check looks for an input to f, any function that returns bool,
249249
// such that f returns false. It calls f repeatedly, with arbitrary
250250
// values for each argument. If f returns false on a given input,
251-
// Check returns that input as a *CheckError.
251+
// Check returns that input as a *[CheckError].
252252
// For example:
253253
//
254254
// func TestOddMultipleOfThree(t *testing.T) {
@@ -297,7 +297,7 @@ func Check(f any, config *Config) error {
297297

298298
// CheckEqual looks for an input on which f and g return different results.
299299
// It calls f and g repeatedly with arbitrary values for each argument.
300-
// If f and g return different answers, CheckEqual returns a *CheckEqualError
300+
// If f and g return different answers, CheckEqual returns a *[CheckEqualError]
301301
// describing the input and the outputs.
302302
func CheckEqual(f, g any, config *Config) error {
303303
if config == nil {

src/testing/slogtest/slogtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ var cases = []testCase{
231231

232232
// TestHandler tests a [slog.Handler].
233233
// If TestHandler finds any misbehaviors, it returns an error for each,
234-
// combined into a single error with errors.Join.
234+
// combined into a single error with [errors.Join].
235235
//
236236
// TestHandler installs the given Handler in a [slog.Logger] and
237237
// makes several calls to the Logger's output methods.
@@ -241,7 +241,7 @@ var cases = []testCase{
241241
// It should return a slice of map[string]any, one for each call to a Logger output method.
242242
// The keys and values of the map should correspond to the keys and values of the Handler's
243243
// output. Each group in the output should be represented as its own nested map[string]any.
244-
// The standard keys slog.TimeKey, slog.LevelKey and slog.MessageKey should be used.
244+
// The standard keys [slog.TimeKey], [slog.LevelKey] and [slog.MessageKey] should be used.
245245
//
246246
// If the Handler outputs JSON, then calling [encoding/json.Unmarshal] with a `map[string]any`
247247
// will create the right data structure.

src/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ func (c *common) Skipf(format string, args ...any) {
11041104
}
11051105

11061106
// SkipNow marks the test as having been skipped and stops its execution
1107-
// by calling runtime.Goexit.
1107+
// by calling [runtime.Goexit].
11081108
// If a test fails (see Error, Errorf, Fail) and is then skipped,
11091109
// it is still considered to have failed.
11101110
// Execution will continue at the next test or benchmark. See also FailNow.

0 commit comments

Comments
 (0)