mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-09-10 22:49:30 +00:00
all: modernize (#5498)
* modernize string cut usage * modernize string cut prefix usage * modernize slices helper usage * modernize min and max usage * modernize loop variable copies * modernize integer range loops * modernize map copy loops * modernize go types iterator usage * modernize empty interface usage * modernize atomic type usage * modernize string builders * modernize string split iteration * modernize remaining loop variable copies * modernize usb cdc min usage * modernize src integer range loops * modernize example empty interface usage * modernize src min and max usage * modernize src integer range loops * modernize src empty interface usage * modernize src atomic type usage * modernize reflect type lookups * modernize review nits
This commit is contained in:
@@ -170,20 +170,6 @@ func (b *B) runN(n int) {
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func min(x, y int64) int64 {
|
||||
if x > y {
|
||||
return y
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func max(x, y int64) int64 {
|
||||
if x < y {
|
||||
return y
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// run1 runs the first iteration of benchFunc. It reports whether more
|
||||
// iterations of this benchmarks should be run.
|
||||
func (b *B) run1() bool {
|
||||
|
||||
+20
-20
@@ -53,7 +53,7 @@ type corpusEntry = struct {
|
||||
Parent string
|
||||
Path string
|
||||
Data []byte
|
||||
Values []interface{}
|
||||
Values []any
|
||||
Generation int
|
||||
IsSeed bool
|
||||
}
|
||||
@@ -61,8 +61,8 @@ type corpusEntry = struct {
|
||||
// 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))
|
||||
@@ -74,23 +74,23 @@ func (f *F) Add(args ...interface{}) {
|
||||
|
||||
// supportedTypes represents all of the supported types which can be fuzzed.
|
||||
var supportedTypes = map[reflect.Type]bool{
|
||||
reflect.TypeOf(([]byte)("")): true,
|
||||
reflect.TypeOf((string)("")): true,
|
||||
reflect.TypeFor[[]byte](): true,
|
||||
reflect.TypeFor[string](): true,
|
||||
reflect.TypeOf((bool)(false)): true,
|
||||
reflect.TypeOf((byte)(0)): true,
|
||||
reflect.TypeOf((rune)(0)): true,
|
||||
reflect.TypeOf((float32)(0)): true,
|
||||
reflect.TypeOf((float64)(0)): true,
|
||||
reflect.TypeOf((int)(0)): true,
|
||||
reflect.TypeOf((int8)(0)): true,
|
||||
reflect.TypeOf((int16)(0)): true,
|
||||
reflect.TypeOf((int32)(0)): true,
|
||||
reflect.TypeOf((int64)(0)): true,
|
||||
reflect.TypeOf((uint)(0)): true,
|
||||
reflect.TypeOf((uint8)(0)): true,
|
||||
reflect.TypeOf((uint16)(0)): true,
|
||||
reflect.TypeOf((uint32)(0)): true,
|
||||
reflect.TypeOf((uint64)(0)): true,
|
||||
reflect.TypeFor[byte](): true,
|
||||
reflect.TypeFor[rune](): true,
|
||||
reflect.TypeFor[float32](): true,
|
||||
reflect.TypeFor[float64](): true,
|
||||
reflect.TypeFor[int](): true,
|
||||
reflect.TypeFor[int8](): true,
|
||||
reflect.TypeFor[int16](): true,
|
||||
reflect.TypeFor[int32](): true,
|
||||
reflect.TypeFor[int64](): true,
|
||||
reflect.TypeFor[uint](): true,
|
||||
reflect.TypeFor[uint8](): true,
|
||||
reflect.TypeFor[uint16](): true,
|
||||
reflect.TypeFor[uint32](): true,
|
||||
reflect.TypeFor[uint64](): true,
|
||||
}
|
||||
|
||||
// Fuzz runs the fuzz function, ff, for fuzz testing. If ff fails for a set of
|
||||
@@ -119,7 +119,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) {
|
||||
f.failed = true
|
||||
f.result.N = 0
|
||||
f.result.T = 0
|
||||
|
||||
+19
-19
@@ -137,7 +137,7 @@ func Testing() bool {
|
||||
|
||||
// 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) {
|
||||
if c.parent == nil {
|
||||
// The fake top-level test doesn't want a FAIL or PASS banner.
|
||||
// Not quite sure how this works upstream.
|
||||
@@ -157,21 +157,21 @@ func fmtDuration(d time.Duration) string {
|
||||
type TB interface {
|
||||
Cleanup(func())
|
||||
Context() context.Context
|
||||
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
|
||||
}
|
||||
@@ -238,47 +238,47 @@ func (c *common) log(s string) {
|
||||
// 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{}) { c.log(fmt.Sprintln(args...)) }
|
||||
func (c *common) Log(args ...any) { c.log(fmt.Sprintln(args...)) }
|
||||
|
||||
// Logf formats its arguments according to the format, analogous to Printf, and
|
||||
// records the text in the error log. A final newline is added if not provided. 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) Logf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) }
|
||||
func (c *common) Logf(format string, args ...any) { 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.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.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.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.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.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.log(fmt.Sprintf(format, args...))
|
||||
c.SkipNow()
|
||||
}
|
||||
@@ -672,7 +672,7 @@ func (t *T) report() {
|
||||
// Not implemented.
|
||||
func AllocsPerRun(runs int, f func()) (avg float64) {
|
||||
f()
|
||||
for i := 0; i < runs; i++ {
|
||||
for range runs {
|
||||
f()
|
||||
}
|
||||
return 0
|
||||
@@ -688,7 +688,7 @@ type InternalExample struct {
|
||||
// MainStart is meant for use by tests generated by 'go test'.
|
||||
// It is not meant to be called directly and is not subject to the Go 1 compatibility document.
|
||||
// It may change signature from release to release.
|
||||
func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, fuzzTargets []InternalFuzzTarget, examples []InternalExample) *M {
|
||||
func MainStart(deps any, tests []InternalTest, benchmarks []InternalBenchmark, fuzzTargets []InternalFuzzTarget, examples []InternalExample) *M {
|
||||
Init()
|
||||
return &M{
|
||||
Tests: tests,
|
||||
|
||||
Reference in New Issue
Block a user