Support go1.18, drop support for <go1.8

Change-Id: I676aabbd7173e6ae523e6fcedfaafcd44ba85c3a
This commit is contained in:
Dan Willemsen 2021-12-14 15:07:20 -08:00
parent a0ec53a770
commit 6dd6868dec

View file

@ -42,7 +42,7 @@ type data struct {
Tests []string Tests []string
Examples []*doc.Example Examples []*doc.Example
HasMain bool HasMain bool
MainStartTakesInterface bool MainStartTakesFuzzers bool
} }
func findTests(srcs []string) (tests []string, examples []*doc.Example, hasMain bool) { func findTests(srcs []string) (tests []string, examples []*doc.Example, hasMain bool) {
@ -68,10 +68,9 @@ func findTests(srcs []string) (tests []string, examples []*doc.Example, hasMain
return return
} }
// Returns true for go1.8+, where testing.MainStart takes an interface instead of a function // Returns true for go1.18+, where testing.MainStart takes an extra slice of fuzzers.
// as its first argument. func mainStartTakesFuzzers() bool {
func mainStartTakesInterface() bool { return reflect.TypeOf(testing.MainStart).NumIn() > 4
return reflect.TypeOf(testing.MainStart).In(0).Kind() == reflect.Interface
} }
func main() { func main() {
@ -92,7 +91,7 @@ func main() {
Tests: tests, Tests: tests,
Examples: examples, Examples: examples,
HasMain: hasMain, HasMain: hasMain,
MainStartTakesInterface: mainStartTakesInterface(), MainStartTakesFuzzers: mainStartTakesFuzzers(),
} }
err := testMainTmpl.Execute(buf, d) err := testMainTmpl.Execute(buf, d)
@ -114,8 +113,10 @@ import (
{{if not .HasMain}} {{if not .HasMain}}
"os" "os"
{{end}} {{end}}
"reflect"
"regexp" "regexp"
"testing" "testing"
"time"
pkg "{{.Package}}" pkg "{{.Package}}"
) )
@ -185,11 +186,44 @@ func (matchString) SetPanicOnExit0(bool) {
panic("shouldn't get here") panic("shouldn't get here")
} }
func (matchString) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error {
panic("shouldn't get here")
}
func (matchString) RunFuzzWorker(func(corpusEntry) error) error {
panic("shouldn't get here")
}
func (matchString) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) {
panic("shouldn't get here")
}
func (matchString) CheckCorpus([]interface{}, []reflect.Type) error {
panic("shouldn't get here")
}
func (matchString) ResetCoverage() {
panic("shouldn't get here")
}
func (matchString) SnapshotCoverage() {
panic("shouldn't get here")
}
type corpusEntry = struct {
Parent string
Path string
Data []byte
Values []interface{}
Generation int
IsSeed bool
}
func main() { func main() {
{{if .MainStartTakesInterface}} {{if .MainStartTakesFuzzers }}
m := testing.MainStart(matchString{}, t, nil, e) m := testing.MainStart(matchString{}, t, nil, nil, e)
{{else}} {{else}}
m := testing.MainStart(MatchString, t, nil, e) m := testing.MainStart(matchString{}, t, nil, e)
{{end}} {{end}}
{{if .HasMain}} {{if .HasMain}}
pkg.TestMain(m) pkg.TestMain(m)