Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump to Go 1.21, drop Go 1.19, propagate GORACE in testscript #235

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
fail-fast: false
matrix:
go-version:
- '1.19.x'
- '1.20.x'
- '1.21.x'
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v4
with:
Expand All @@ -33,7 +33,7 @@ jobs:
go test -race ./...

- name: Tidy
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.20.x' # no need to do this everywhere
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21.x' # no need to do this everywhere
run: |
go mod tidy

Expand Down
4 changes: 3 additions & 1 deletion cmd/testscript/testdata/noproxy.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# With no .gomodproxy supporting files, we use the GOPROXY from
# the environment.
# Note that Go 1.21 started quoting with single quotes in "go env",
# where older versions used double quotes.
env GOPROXY=0.1.2.3
unquote file.txt
testscript -v file.txt

-- file.txt --
>go env
>[!windows] stdout '^GOPROXY="0.1.2.3"$'
>[!windows] stdout '^GOPROXY=[''"]0.1.2.3[''"]$'
>[windows] stdout '^set GOPROXY=0.1.2.3$'
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.19
go 1.20

require (
golang.org/x/mod v0.9.0
Expand Down
5 changes: 1 addition & 4 deletions gotooltest/testdata/cover.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ stdout 'PASS'
# Then, a 'go test' run with -coverprofile.
# The total coverage after merging profiles should end up being 100%.
# Marking all printlns as covered requires all edge cases to work well.
# Go 1.20 learned to produce and merge multiple coverage profiles,
# so versions before then report a shallow 0% coverage.
go test -vet=off -coverprofile=cover.out -v
stdout 'PASS'
[go1.20] stdout 'coverage: 100\.0%'
[!go1.20] stdout 'coverage: 0\.0%'
stdout 'coverage: 100\.0%'
! stdout 'malformed coverage' # written by "go test" if cover.out is invalid
exists cover.out

Expand Down
2 changes: 1 addition & 1 deletion testscript/testdata/pty.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[!linux] [!darwin] skip
[darwin] [go1.20] skip # https://go.dev/issue/61779
[darwin] skip # https://go.dev/issue/61779

ttyin secretwords.txt
terminalprompt
Expand Down
28 changes: 19 additions & 9 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go/build"
"io"
"io/fs"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -262,14 +261,14 @@ func RunT(t T, p Params) {
}
testTempDir := p.WorkdirRoot
if testTempDir == "" {
testTempDir, err = ioutil.TempDir(os.Getenv("GOTMPDIR"), "go-test-script")
testTempDir, err = os.MkdirTemp(os.Getenv("GOTMPDIR"), "go-test-script")
if err != nil {
t.Fatal(err)
}
} else {
p.TestWork = true
}
// The temp dir returned by ioutil.TempDir might be a sym linked dir (default
// The temp dir returned by os.MkdirTemp might be a sym linked dir (default
// behaviour in macOS). That could mess up matching that includes $WORK if,
// for example, an external program outputs resolved paths. Evaluating the
// dir here will ensure consistency.
Expand Down Expand Up @@ -445,16 +444,27 @@ func (ts *TestScript) setup() string {
"/=" + string(os.PathSeparator),
":=" + string(os.PathListSeparator),
"$=$",

// If we are collecting coverage profiles for merging into the main one,
// ensure the environment variable is forwarded to sub-processes.
"GOCOVERDIR=" + os.Getenv("GOCOVERDIR"),
},
WorkDir: ts.workdir,
Values: make(map[interface{}]interface{}),
Cd: ts.workdir,
ts: ts,
}

// These env vars affect how a Go program behaves at run-time;
// If the user or `go test` wrapper set them, we should propagate them
// so that sub-process commands run via the test binary see them as well.
for _, name := range []string{
// If we are collecting coverage profiles, e.g. `go test -coverprofile`.
"GOCOVERDIR",
// If the user set GORACE when running a command like `go test -race`,
// such as GORACE=atexit_sleep_ms=10 to avoid the default 1s sleeps.
"GORACE",
} {
if val := os.Getenv(name); val != "" {
env.Vars = append(env.Vars, name+"="+val)
}
}
// Must preserve SYSTEMROOT on Windows: https://github.com/golang/go/issues/25513 et al
if runtime.GOOS == "windows" {
env.Vars = append(env.Vars,
Expand Down Expand Up @@ -780,7 +790,7 @@ func (ts *TestScript) applyScriptUpdates() {
panic("script update file not found")
}
}
if err := ioutil.WriteFile(ts.file, txtar.Format(ts.archive), 0o666); err != nil {
if err := os.WriteFile(ts.file, txtar.Format(ts.archive), 0o666); err != nil {
ts.t.Fatal("cannot update script: ", err)
}
ts.Logf("%s updated", ts.file)
Expand Down Expand Up @@ -1174,7 +1184,7 @@ func (ts *TestScript) ReadFile(file string) string {
return ts.ttyout
default:
file = ts.MkAbs(file)
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
ts.Check(err)
return string(data)
}
Expand Down