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,
and run 1.17's gofmt, as CI demands it.

Finally, make CI also test with Go's master version,
to ensure that we are compatible with it.
We pin a specific commit, since that keeps CI stable.

Fixes #144.

Co-authored-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan and rogpeppe committed Sep 23, 2021
1 parent 9df06c3 commit 86f73c5
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 9 deletions.
29 changes: 28 additions & 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 All @@ -34,3 +34,30 @@ jobs:
test -z "$(gofmt -d .)" || (gofmt -d . && false)
test -z "$(git status --porcelain)" || (git status; git diff && false)
test-gotip:
runs-on: ubuntu-latest
continue-on-error: true # master breaks sometimes
steps:
- name: Install Go
env:
GO_COMMIT: d0dd26a88c019d54f22463daae81e785f5867565 # 2021-09-23
run: |
cd $HOME
mkdir $HOME/gotip
cd $HOME/gotip
wget -O gotip.tar.gz https://go.googlesource.com/go/+archive/${GO_COMMIT}.tar.gz
tar -xf gotip.tar.gz
echo "devel go1.18-${GO_COMMIT}" >VERSION
cd src
./make.bash
echo "GOROOT=$HOME/gotip" >>$GITHUB_ENV
echo "$HOME/gotip/bin" >>$GITHUB_PATH
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: |
go version
go test ./...
1 change: 1 addition & 0 deletions cache/default_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !windows && !darwin && !plan9
// +build !windows,!darwin,!plan9

package cache
Expand Down
1 change: 1 addition & 0 deletions fmtsort/mapelem.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.12
// +build go1.12

package fmtsort
Expand Down
1 change: 1 addition & 0 deletions fmtsort/mapelem_1.11.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !go1.12
// +build !go1.12

package fmtsort
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
7 changes: 2 additions & 5 deletions imports/testdata/import1/x1.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// +build blahblh
// +build linux
// +build !linux
// +build windows
// +build darwin
//go:build blahblh && linux && !linux && windows && darwin
// +build blahblh,linux,!linux,windows,darwin

package x

Expand Down
1 change: 1 addition & 0 deletions internal/os/execpath/lp_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build js && wasm
// +build js,wasm

package execpath
Expand Down
1 change: 1 addition & 0 deletions internal/os/execpath/lp_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build aix || darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd solaris

package execpath
Expand Down
1 change: 1 addition & 0 deletions internal/syscall/windows/registry/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

// Package registry provides access to the Windows registry.
Expand Down
1 change: 1 addition & 0 deletions internal/syscall/windows/registry/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

package registry
Expand Down
1 change: 1 addition & 0 deletions internal/syscall/windows/registry/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

package registry
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_fcntl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build aix || solaris
// +build aix solaris

// This code implements the filelock API using POSIX 'fcntl' locks, which attach
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris && !windows
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!plan9,!solaris,!windows

package filelock
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build plan9
// +build plan9

package filelock
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !nacl && !plan9
// +build !js,!nacl,!plan9

package filelock_test
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
// +build darwin dragonfly freebsd linux netbsd openbsd

package filelock
Expand Down
1 change: 1 addition & 0 deletions lockedfile/internal/filelock/filelock_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

package filelock
Expand Down
1 change: 1 addition & 0 deletions lockedfile/lockedfile_filelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !plan9
// +build !plan9

package lockedfile
Expand Down
1 change: 1 addition & 0 deletions lockedfile/lockedfile_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build plan9
// +build plan9

package lockedfile
Expand Down
1 change: 1 addition & 0 deletions lockedfile/lockedfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

// js and nacl do not support inter-process file locking.
//go:build !js && !nacl
// +build !js,!nacl

package lockedfile_test
Expand Down
1 change: 1 addition & 0 deletions testenv/testenv_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build cgo
// +build cgo

package testenv
Expand Down
1 change: 1 addition & 0 deletions testenv/testenv_notwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !windows
// +build !windows

package testenv
Expand Down
1 change: 1 addition & 0 deletions testscript/envvarname.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package testscript
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
51 changes: 51 additions & 0 deletions testscript/exe_go118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//go:build go1.18
// +build go1.18

package testscript

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

func mainStart() *testing.M {
// Note: testing.MainStart acquired an extra argument in Go 1.18.
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() {}
12 changes: 12 additions & 0 deletions testscript/exe_pre_go1.18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !go1.18
// +build !go1.18

package testscript

import (
"testing"
)

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

0 comments on commit 86f73c5

Please sign in to comment.