From 6f57cb65ddabef05ee46a9d293847bd42d9d68b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 22 Sep 2021 17:25:42 +0100 Subject: [PATCH] testscript: add support for Go master aka 1.18 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. Finally, run 1.17's gofmt, as CI demands it. Fixes #144. --- .github/workflows/test.yml | 2 +- cache/default_unix_test.go | 1 + fmtsort/mapelem.go | 1 + fmtsort/mapelem_1.11.go | 1 + go.mod | 2 +- imports/testdata/import1/x1.go | 7 +-- internal/os/execpath/lp_js.go | 1 + internal/os/execpath/lp_unix.go | 1 + internal/syscall/windows/registry/key.go | 1 + internal/syscall/windows/registry/syscall.go | 1 + internal/syscall/windows/registry/value.go | 1 + .../internal/filelock/filelock_fcntl.go | 1 + .../internal/filelock/filelock_other.go | 1 + .../internal/filelock/filelock_plan9.go | 1 + lockedfile/internal/filelock/filelock_test.go | 1 + lockedfile/internal/filelock/filelock_unix.go | 1 + .../internal/filelock/filelock_windows.go | 1 + lockedfile/lockedfile_filelock.go | 1 + lockedfile/lockedfile_plan9.go | 1 + lockedfile/lockedfile_test.go | 1 + testenv/testenv_cgo.go | 1 + testenv/testenv_notwin.go | 1 + testscript/envvarname.go | 1 + testscript/exe.go | 3 +- testscript/exe_go118.go | 50 +++++++++++++++++++ testscript/exe_pre_go1.18.go | 12 +++++ 26 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 testscript/exe_go118.go create mode 100644 testscript/exe_pre_go1.18.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f1de139..2f00dd63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/cache/default_unix_test.go b/cache/default_unix_test.go index 1458201f..ddc95a5e 100644 --- a/cache/default_unix_test.go +++ b/cache/default_unix_test.go @@ -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 diff --git a/fmtsort/mapelem.go b/fmtsort/mapelem.go index af6124f1..4e4c2945 100644 --- a/fmtsort/mapelem.go +++ b/fmtsort/mapelem.go @@ -1,3 +1,4 @@ +//go:build go1.12 // +build go1.12 package fmtsort diff --git a/fmtsort/mapelem_1.11.go b/fmtsort/mapelem_1.11.go index 6c2b0222..873bf7f5 100644 --- a/fmtsort/mapelem_1.11.go +++ b/fmtsort/mapelem_1.11.go @@ -1,3 +1,4 @@ +//go:build !go1.12 // +build !go1.12 package fmtsort diff --git a/go.mod b/go.mod index 07e2c3c4..ef958134 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/imports/testdata/import1/x1.go b/imports/testdata/import1/x1.go index 6a9594ae..eaaea979 100644 --- a/imports/testdata/import1/x1.go +++ b/imports/testdata/import1/x1.go @@ -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 diff --git a/internal/os/execpath/lp_js.go b/internal/os/execpath/lp_js.go index c96f5bd5..e826c319 100644 --- a/internal/os/execpath/lp_js.go +++ b/internal/os/execpath/lp_js.go @@ -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 diff --git a/internal/os/execpath/lp_unix.go b/internal/os/execpath/lp_unix.go index 76314ea8..cb8e9760 100644 --- a/internal/os/execpath/lp_unix.go +++ b/internal/os/execpath/lp_unix.go @@ -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 diff --git a/internal/syscall/windows/registry/key.go b/internal/syscall/windows/registry/key.go index cc3d0c77..fb89e39a 100644 --- a/internal/syscall/windows/registry/key.go +++ b/internal/syscall/windows/registry/key.go @@ -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. diff --git a/internal/syscall/windows/registry/syscall.go b/internal/syscall/windows/registry/syscall.go index a6525dac..bb612793 100644 --- a/internal/syscall/windows/registry/syscall.go +++ b/internal/syscall/windows/registry/syscall.go @@ -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 diff --git a/internal/syscall/windows/registry/value.go b/internal/syscall/windows/registry/value.go index 71d4e15b..b89bfd82 100644 --- a/internal/syscall/windows/registry/value.go +++ b/internal/syscall/windows/registry/value.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_fcntl.go b/lockedfile/internal/filelock/filelock_fcntl.go index c60a78ed..4e644811 100644 --- a/lockedfile/internal/filelock/filelock_fcntl.go +++ b/lockedfile/internal/filelock/filelock_fcntl.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_other.go b/lockedfile/internal/filelock/filelock_other.go index 107611e1..cfc53386 100644 --- a/lockedfile/internal/filelock/filelock_other.go +++ b/lockedfile/internal/filelock/filelock_other.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_plan9.go b/lockedfile/internal/filelock/filelock_plan9.go index afdffe32..5ae3cc28 100644 --- a/lockedfile/internal/filelock/filelock_plan9.go +++ b/lockedfile/internal/filelock/filelock_plan9.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_test.go b/lockedfile/internal/filelock/filelock_test.go index d28c253a..925f6417 100644 --- a/lockedfile/internal/filelock/filelock_test.go +++ b/lockedfile/internal/filelock/filelock_test.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_unix.go b/lockedfile/internal/filelock/filelock_unix.go index 00c42628..09549efd 100644 --- a/lockedfile/internal/filelock/filelock_unix.go +++ b/lockedfile/internal/filelock/filelock_unix.go @@ -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 diff --git a/lockedfile/internal/filelock/filelock_windows.go b/lockedfile/internal/filelock/filelock_windows.go index 13403a0d..2bd3eb96 100644 --- a/lockedfile/internal/filelock/filelock_windows.go +++ b/lockedfile/internal/filelock/filelock_windows.go @@ -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 diff --git a/lockedfile/lockedfile_filelock.go b/lockedfile/lockedfile_filelock.go index 14cf86cb..6a031739 100644 --- a/lockedfile/lockedfile_filelock.go +++ b/lockedfile/lockedfile_filelock.go @@ -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 diff --git a/lockedfile/lockedfile_plan9.go b/lockedfile/lockedfile_plan9.go index 4a52c949..02221c56 100644 --- a/lockedfile/lockedfile_plan9.go +++ b/lockedfile/lockedfile_plan9.go @@ -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 diff --git a/lockedfile/lockedfile_test.go b/lockedfile/lockedfile_test.go index 16b41515..7daadd4c 100644 --- a/lockedfile/lockedfile_test.go +++ b/lockedfile/lockedfile_test.go @@ -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 diff --git a/testenv/testenv_cgo.go b/testenv/testenv_cgo.go index e3d4d16b..02f08f57 100644 --- a/testenv/testenv_cgo.go +++ b/testenv/testenv_cgo.go @@ -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 diff --git a/testenv/testenv_notwin.go b/testenv/testenv_notwin.go index d8ce6cd3..a1ae92c0 100644 --- a/testenv/testenv_notwin.go +++ b/testenv/testenv_notwin.go @@ -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 diff --git a/testscript/envvarname.go b/testscript/envvarname.go index a4ec1f75..15e41f2b 100644 --- a/testscript/envvarname.go +++ b/testscript/envvarname.go @@ -1,3 +1,4 @@ +//go:build !windows // +build !windows package testscript diff --git a/testscript/exe.go b/testscript/exe.go index fa048c71..1be7d0f6 100644 --- a/testscript/exe.go +++ b/testscript/exe.go @@ -15,7 +15,6 @@ import ( "path/filepath" "runtime" "strings" - "testing" ) // TestingM is implemented by *testing.M. It's defined as an interface @@ -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 } diff --git a/testscript/exe_go118.go b/testscript/exe_go118.go new file mode 100644 index 00000000..c1c840b1 --- /dev/null +++ b/testscript/exe_go118.go @@ -0,0 +1,50 @@ +//go:build go1.18 +// +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() {} diff --git a/testscript/exe_pre_go1.18.go b/testscript/exe_pre_go1.18.go new file mode 100644 index 00000000..e9323a22 --- /dev/null +++ b/testscript/exe_pre_go1.18.go @@ -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) +}