Skip to content

Commit

Permalink
testscript: add support for Go master aka 1.18
Browse files Browse the repository at this point in the history
Fuzzing support brought a new parameter to MainStart,
as well as more methods on testDeps.
Use build tags to support those without breaking 1.16 nor 1.17.

While at it, bump CI to test the two latest Go versions.

Fixes rogpeppe#144.
  • Loading branch information
mvdan committed Sep 22, 2021
1 parent 9df06c3 commit 06c74dd
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.15.x, 1.16.x]
go-version: [1.16.x, 1.17.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/rogpeppe/go-internal

go 1.15
go 1.16

require (
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
Expand Down
3 changes: 1 addition & 2 deletions testscript/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"path/filepath"
"runtime"
"strings"
"testing"
)

// TestingM is implemented by *testing.M. It's defined as an interface
Expand Down Expand Up @@ -228,7 +227,7 @@ func runCoverSubcommand(cprof string, mainf func() int) (exitCode int) {

// Run MainStart (recursively, but it we should be ok) with no tests
// so that it writes the coverage profile.
m := testing.MainStart(nopTestDeps{}, nil, nil, nil)
m := mainStart()
if code := m.Run(); code != 0 && exitCode == 0 {
exitCode = code
}
Expand Down
49 changes: 49 additions & 0 deletions testscript/exe_go118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//go:build go1.18

package testscript

import (
"reflect"
"testing"
"time"
)

func mainStart() *testing.M {
return testing.MainStart(nopTestDeps{}, nil, nil, nil, nil)
}

// Note: corpusEntry is an anonymous struct type used by some method stubs.
type corpusEntry = struct {
Parent string
Name string
Data []byte
Values []interface{}
Generation int
IsSeed bool
}

// Note: CoordinateFuzzing was added in Go 1.18.
func (nopTestDeps) CoordinateFuzzing(time.Duration, int64, time.Duration, int64, int, []corpusEntry, []reflect.Type, string, string) error {
return nil
}

// Note: RunFuzzWorker was added in Go 1.18.
func (nopTestDeps) RunFuzzWorker(func(corpusEntry) error) error {
return nil
}

// Note: ReadCorpus was added in Go 1.18.
func (nopTestDeps) ReadCorpus(string, []reflect.Type) ([]corpusEntry, error) {
return nil, nil
}

// Note: CheckCorpus was added in Go 1.18.
func (nopTestDeps) CheckCorpus([]interface{}, []reflect.Type) error {
return nil
}

// Note: ResetCoverage was added in Go 1.18.
func (nopTestDeps) ResetCoverage() {}

// Note: SnapshotCoverage was added in Go 1.18.
func (nopTestDeps) SnapshotCoverage() {}
11 changes: 11 additions & 0 deletions testscript/exe_pre_go1.18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !go1.18

package testscript

import (
"testing"
)

func mainStart() *testing.M {
return testing.MainStart(nopTestDeps{}, nil, nil, nil)
}

0 comments on commit 06c74dd

Please sign in to comment.