Support go1.18, drop support for <go1.8 am: 6dd6868dec

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1923364

Change-Id: Idd41d4bfbc32f36677443c505011804e308d38bc
This commit is contained in:
Dan Willemsen 2021-12-15 01:41:47 +00:00 committed by Automerger Merge Worker
commit 63279c6fd0

View file

@ -38,11 +38,11 @@ var (
)
type data struct {
Package string
Tests []string
Examples []*doc.Example
HasMain bool
MainStartTakesInterface bool
Package string
Tests []string
Examples []*doc.Example
HasMain bool
MainStartTakesFuzzers 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
}
// Returns true for go1.8+, where testing.MainStart takes an interface instead of a function
// as its first argument.
func mainStartTakesInterface() bool {
return reflect.TypeOf(testing.MainStart).In(0).Kind() == reflect.Interface
// Returns true for go1.18+, where testing.MainStart takes an extra slice of fuzzers.
func mainStartTakesFuzzers() bool {
return reflect.TypeOf(testing.MainStart).NumIn() > 4
}
func main() {
@ -88,11 +87,11 @@ func main() {
tests, examples, hasMain := findTests(flag.Args())
d := data{
Package: *pkg,
Tests: tests,
Examples: examples,
HasMain: hasMain,
MainStartTakesInterface: mainStartTakesInterface(),
Package: *pkg,
Tests: tests,
Examples: examples,
HasMain: hasMain,
MainStartTakesFuzzers: mainStartTakesFuzzers(),
}
err := testMainTmpl.Execute(buf, d)
@ -114,8 +113,10 @@ import (
{{if not .HasMain}}
"os"
{{end}}
"reflect"
"regexp"
"testing"
"time"
pkg "{{.Package}}"
)
@ -185,11 +186,44 @@ func (matchString) SetPanicOnExit0(bool) {
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() {
{{if .MainStartTakesInterface}}
m := testing.MainStart(matchString{}, t, nil, e)
{{if .MainStartTakesFuzzers }}
m := testing.MainStart(matchString{}, t, nil, nil, e)
{{else}}
m := testing.MainStart(MatchString, t, nil, e)
m := testing.MainStart(matchString{}, t, nil, e)
{{end}}
{{if .HasMain}}
pkg.TestMain(m)