aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/testing
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.gz
go-2580d0e08d5e9f979b943758d3c49877fb2324cb.zip
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/allocs_test.go2
-rw-r--r--src/testing/example.go2
-rw-r--r--src/testing/fstest/mapfs.go4
-rw-r--r--src/testing/fstest/testfs.go2
-rw-r--r--src/testing/fuzz.go10
-rw-r--r--src/testing/internal/testdeps/deps.go2
-rw-r--r--src/testing/quick/quick.go18
-rw-r--r--src/testing/testing.go50
8 files changed, 45 insertions, 45 deletions
diff --git a/src/testing/allocs_test.go b/src/testing/allocs_test.go
index 5b346aaf83..bbd3ae79c8 100644
--- a/src/testing/allocs_test.go
+++ b/src/testing/allocs_test.go
@@ -6,7 +6,7 @@ package testing_test
import "testing"
-var global interface{}
+var global any
var allocsPerRunTests = []struct {
name string
diff --git a/src/testing/example.go b/src/testing/example.go
index 0217c5d242..f33e8d2f92 100644
--- a/src/testing/example.go
+++ b/src/testing/example.go
@@ -64,7 +64,7 @@ func sortLines(output string) string {
// If recovered is non-nil, it'll panic with that value.
// If the test panicked with nil, or invoked runtime.Goexit, it'll be
// made to fail and panic with errNilPanicOrGoexit
-func (eg *InternalExample) processRunResult(stdout string, timeSpent time.Duration, finished bool, recovered interface{}) (passed bool) {
+func (eg *InternalExample) processRunResult(stdout string, timeSpent time.Duration, finished bool, recovered any) (passed bool) {
passed = true
dstr := fmtDuration(timeSpent)
var fail string
diff --git a/src/testing/fstest/mapfs.go b/src/testing/fstest/mapfs.go
index 056ef133fa..4595b7313d 100644
--- a/src/testing/fstest/mapfs.go
+++ b/src/testing/fstest/mapfs.go
@@ -37,7 +37,7 @@ type MapFile struct {
Data []byte // file content
Mode fs.FileMode // FileInfo.Mode
ModTime time.Time // FileInfo.ModTime
- Sys interface{} // FileInfo.Sys
+ Sys any // FileInfo.Sys
}
var _ fs.FS = MapFS(nil)
@@ -156,7 +156,7 @@ func (i *mapFileInfo) Mode() fs.FileMode { return i.f.Mode }
func (i *mapFileInfo) Type() fs.FileMode { return i.f.Mode.Type() }
func (i *mapFileInfo) ModTime() time.Time { return i.f.ModTime }
func (i *mapFileInfo) IsDir() bool { return i.f.Mode&fs.ModeDir != 0 }
-func (i *mapFileInfo) Sys() interface{} { return i.f.Sys }
+func (i *mapFileInfo) Sys() any { return i.f.Sys }
func (i *mapFileInfo) Info() (fs.FileInfo, error) { return i, nil }
// An openMapFile is a regular (non-directory) fs.File open for reading.
diff --git a/src/testing/fstest/testfs.go b/src/testing/fstest/testfs.go
index 5c4f30af16..9a65fbbd0b 100644
--- a/src/testing/fstest/testfs.go
+++ b/src/testing/fstest/testfs.go
@@ -105,7 +105,7 @@ type fsTester struct {
}
// errorf adds an error line to errText.
-func (t *fsTester) errorf(format string, args ...interface{}) {
+func (t *fsTester) errorf(format string, args ...any) {
if len(t.errText) > 0 {
t.errText = append(t.errText, '\n')
}
diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go
index 19ff39947b..18f2b2f319 100644
--- a/src/testing/fuzz.go
+++ b/src/testing/fuzz.go
@@ -91,7 +91,7 @@ type corpusEntry = struct {
Parent string
Path string
Data []byte
- Values []interface{}
+ Values []any
Generation int
IsSeed bool
}
@@ -149,8 +149,8 @@ func (f *F) Skipped() bool {
// Add will add the arguments to the seed corpus for the fuzz test. This will be
// a no-op if called after or within the fuzz target, and args must match the
// arguments for the fuzz target.
-func (f *F) Add(args ...interface{}) {
- var values []interface{}
+func (f *F) Add(args ...any) {
+ var values []any
for i := range args {
if t := reflect.TypeOf(args[i]); !supportedTypes[t] {
panic(fmt.Sprintf("testing: unsupported type to Add %v", t))
@@ -207,7 +207,7 @@ var supportedTypes = map[reflect.Type]bool{
// When fuzzing, F.Fuzz does not return until a problem is found, time runs out
// (set with -fuzztime), or the test process is interrupted by a signal. F.Fuzz
// should be called exactly once, unless F.Skip or F.Fail is called beforehand.
-func (f *F) Fuzz(ff interface{}) {
+func (f *F) Fuzz(ff any) {
if f.fuzzCalled {
panic("testing: F.Fuzz called more than once")
}
@@ -638,7 +638,7 @@ func fRunner(f *F, fn func(*F)) {
// If we recovered a panic or inappropriate runtime.Goexit, fail the test,
// flush the output log up to the root, then panic.
- doPanic := func(err interface{}) {
+ doPanic := func(err any) {
f.Fail()
if r := f.runCleanup(recoverAndReturnPanic); r != nil {
f.Logf("cleanup panicked with %v", r)
diff --git a/src/testing/internal/testdeps/deps.go b/src/testing/internal/testdeps/deps.go
index c612355a00..2e85a41b07 100644
--- a/src/testing/internal/testdeps/deps.go
+++ b/src/testing/internal/testdeps/deps.go
@@ -186,7 +186,7 @@ func (TestDeps) ReadCorpus(dir string, types []reflect.Type) ([]fuzz.CorpusEntry
return fuzz.ReadCorpus(dir, types)
}
-func (TestDeps) CheckCorpus(vals []interface{}, types []reflect.Type) error {
+func (TestDeps) CheckCorpus(vals []any, types []reflect.Type) error {
return fuzz.CheckCorpus(vals, types)
}
diff --git a/src/testing/quick/quick.go b/src/testing/quick/quick.go
index 777338bb37..e73d307c13 100644
--- a/src/testing/quick/quick.go
+++ b/src/testing/quick/quick.go
@@ -227,7 +227,7 @@ func (s SetupError) Error() string { return string(s) }
// A CheckError is the result of Check finding an error.
type CheckError struct {
Count int
- In []interface{}
+ In []any
}
func (s *CheckError) Error() string {
@@ -237,8 +237,8 @@ func (s *CheckError) Error() string {
// A CheckEqualError is the result CheckEqual finding an error.
type CheckEqualError struct {
CheckError
- Out1 []interface{}
- Out2 []interface{}
+ Out1 []any
+ Out2 []any
}
func (s *CheckEqualError) Error() string {
@@ -260,7 +260,7 @@ func (s *CheckEqualError) Error() string {
// t.Error(err)
// }
// }
-func Check(f interface{}, config *Config) error {
+func Check(f any, config *Config) error {
if config == nil {
config = &defaultConfig
}
@@ -299,7 +299,7 @@ func Check(f interface{}, config *Config) error {
// It calls f and g repeatedly with arbitrary values for each argument.
// If f and g return different answers, CheckEqual returns a *CheckEqualError
// describing the input and the outputs.
-func CheckEqual(f, g interface{}, config *Config) error {
+func CheckEqual(f, g any, config *Config) error {
if config == nil {
config = &defaultConfig
}
@@ -358,7 +358,7 @@ func arbitraryValues(args []reflect.Value, f reflect.Type, config *Config, rand
return
}
-func functionAndType(f interface{}) (v reflect.Value, t reflect.Type, ok bool) {
+func functionAndType(f any) (v reflect.Value, t reflect.Type, ok bool) {
v = reflect.ValueOf(f)
ok = v.Kind() == reflect.Func
if !ok {
@@ -368,15 +368,15 @@ func functionAndType(f interface{}) (v reflect.Value, t reflect.Type, ok bool) {
return
}
-func toInterfaces(values []reflect.Value) []interface{} {
- ret := make([]interface{}, len(values))
+func toInterfaces(values []reflect.Value) []any {
+ ret := make([]any, len(values))
for i, v := range values {
ret[i] = v.Interface()
}
return ret
}
-func toString(interfaces []interface{}) string {
+func toString(interfaces []any) string {
s := make([]string, len(interfaces))
for i, v := range interfaces {
s[i] = fmt.Sprintf("%#v", v)
diff --git a/src/testing/testing.go b/src/testing/testing.go
index e4b7aa30e5..7bd13a850c 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -453,7 +453,7 @@ func newChattyPrinter(w io.Writer) *chattyPrinter {
// Updatef prints a message about the status of the named test to w.
//
// The formatted message must include the test name itself.
-func (p *chattyPrinter) Updatef(testName, format string, args ...interface{}) {
+func (p *chattyPrinter) Updatef(testName, format string, args ...any) {
p.lastNameMu.Lock()
defer p.lastNameMu.Unlock()
@@ -467,7 +467,7 @@ func (p *chattyPrinter) Updatef(testName, format string, args ...interface{}) {
// Printf prints a message, generated by the named test, that does not
// necessarily mention that tests's name itself.
-func (p *chattyPrinter) Printf(testName, format string, args ...interface{}) {
+func (p *chattyPrinter) Printf(testName, format string, args ...any) {
p.lastNameMu.Lock()
defer p.lastNameMu.Unlock()
@@ -680,7 +680,7 @@ func (c *common) decorate(s string, skip int) string {
// flushToParent writes c.output to the parent after first writing the header
// with the given format and arguments.
-func (c *common) flushToParent(testName, format string, args ...interface{}) {
+func (c *common) flushToParent(testName, format string, args ...any) {
p := c.parent
p.mu.Lock()
defer p.mu.Unlock()
@@ -743,21 +743,21 @@ func fmtDuration(d time.Duration) string {
// TB is the interface common to T, B, and F.
type TB interface {
Cleanup(func())
- Error(args ...interface{})
- Errorf(format string, args ...interface{})
+ Error(args ...any)
+ Errorf(format string, args ...any)
Fail()
FailNow()
Failed() bool
- Fatal(args ...interface{})
- Fatalf(format string, args ...interface{})
+ Fatal(args ...any)
+ Fatalf(format string, args ...any)
Helper()
- Log(args ...interface{})
- Logf(format string, args ...interface{})
+ Log(args ...any)
+ Logf(format string, args ...any)
Name() string
Setenv(key, value string)
- Skip(args ...interface{})
+ Skip(args ...any)
SkipNow()
- Skipf(format string, args ...interface{})
+ Skipf(format string, args ...any)
Skipped() bool
TempDir() string
@@ -906,7 +906,7 @@ func (c *common) logDepth(s string, depth int) {
// and records the text in the error log. For tests, the text will be printed only if
// the test fails or the -test.v flag is set. For benchmarks, the text is always
// printed to avoid having performance depend on the value of the -test.v flag.
-func (c *common) Log(args ...interface{}) {
+func (c *common) Log(args ...any) {
c.checkFuzzFn("Log")
c.log(fmt.Sprintln(args...))
}
@@ -916,48 +916,48 @@ func (c *common) Log(args ...interface{}) {
// tests, the text will be printed only if the test fails or the -test.v flag is
// set. For benchmarks, the text is always printed to avoid having performance
// depend on the value of the -test.v flag.
-func (c *common) Logf(format string, args ...interface{}) {
+func (c *common) Logf(format string, args ...any) {
c.checkFuzzFn("Logf")
c.log(fmt.Sprintf(format, args...))
}
// Error is equivalent to Log followed by Fail.
-func (c *common) Error(args ...interface{}) {
+func (c *common) Error(args ...any) {
c.checkFuzzFn("Error")
c.log(fmt.Sprintln(args...))
c.Fail()
}
// Errorf is equivalent to Logf followed by Fail.
-func (c *common) Errorf(format string, args ...interface{}) {
+func (c *common) Errorf(format string, args ...any) {
c.checkFuzzFn("Errorf")
c.log(fmt.Sprintf(format, args...))
c.Fail()
}
// Fatal is equivalent to Log followed by FailNow.
-func (c *common) Fatal(args ...interface{}) {
+func (c *common) Fatal(args ...any) {
c.checkFuzzFn("Fatal")
c.log(fmt.Sprintln(args...))
c.FailNow()
}
// Fatalf is equivalent to Logf followed by FailNow.
-func (c *common) Fatalf(format string, args ...interface{}) {
+func (c *common) Fatalf(format string, args ...any) {
c.checkFuzzFn("Fatalf")
c.log(fmt.Sprintf(format, args...))
c.FailNow()
}
// Skip is equivalent to Log followed by SkipNow.
-func (c *common) Skip(args ...interface{}) {
+func (c *common) Skip(args ...any) {
c.checkFuzzFn("Skip")
c.log(fmt.Sprintln(args...))
c.SkipNow()
}
// Skipf is equivalent to Logf followed by SkipNow.
-func (c *common) Skipf(format string, args ...interface{}) {
+func (c *common) Skipf(format string, args ...any) {
c.checkFuzzFn("Skipf")
c.log(fmt.Sprintf(format, args...))
c.SkipNow()
@@ -1141,7 +1141,7 @@ const (
// runCleanup is called at the end of the test.
// If catchPanic is true, this will catch panics, and return the recovered
// value if any.
-func (c *common) runCleanup(ph panicHandling) (panicVal interface{}) {
+func (c *common) runCleanup(ph panicHandling) (panicVal any) {
if ph == recoverAndReturnPanic {
defer func() {
panicVal = recover()
@@ -1340,7 +1340,7 @@ func tRunner(t *T, fn func(t *T)) {
t.signal <- signal
}()
- doPanic := func(err interface{}) {
+ doPanic := func(err any) {
t.Fail()
if r := t.runCleanup(recoverAndReturnPanic); r != nil {
t.Logf("cleanup panicked with %v", r)
@@ -1554,9 +1554,9 @@ func (f matchStringOnly) RunFuzzWorker(func(corpusEntry) error) error { return e
func (f matchStringOnly) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) {
return nil, errMain
}
-func (f matchStringOnly) CheckCorpus([]interface{}, []reflect.Type) error { return nil }
-func (f matchStringOnly) ResetCoverage() {}
-func (f matchStringOnly) SnapshotCoverage() {}
+func (f matchStringOnly) CheckCorpus([]any, []reflect.Type) error { return nil }
+func (f matchStringOnly) ResetCoverage() {}
+func (f matchStringOnly) SnapshotCoverage() {}
// Main is an internal function, part of the implementation of the "go test" command.
// It was exported because it is cross-package and predates "internal" packages.
@@ -1602,7 +1602,7 @@ type testDeps interface {
CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error
RunFuzzWorker(func(corpusEntry) error) error
ReadCorpus(string, []reflect.Type) ([]corpusEntry, error)
- CheckCorpus([]interface{}, []reflect.Type) error
+ CheckCorpus([]any, []reflect.Type) error
ResetCoverage()
SnapshotCoverage()
}