From 0fe1eae5e7eb10bd7014e4ab68a44a165e147f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 20 Sep 2024 13:34:59 +0100 Subject: [PATCH 1/3] drop Go 1.21, add Go 1.23 --- .github/workflows/test.yml | 4 ++-- go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d7234b..5416122 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,8 +12,8 @@ jobs: fail-fast: false matrix: go-version: - - '1.21.x' - '1.22.x' + - '1.23.x' os: - ubuntu-latest - macos-latest @@ -33,7 +33,7 @@ jobs: go test -race ./... - name: Tidy - if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22.x' # no need to do this everywhere + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.23.x' # no need to do this everywhere run: | go mod tidy diff --git a/go.mod b/go.mod index 6b4304f..58d0c9e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rogpeppe/go-internal -go 1.21 +go 1.22 require ( golang.org/x/mod v0.18.0 From 1f14310742fe4beda2fbf71efe13ae67de662902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 20 Sep 2024 13:41:51 +0100 Subject: [PATCH 2/3] take advantage of Go 1.22 cmp.Or and no longer needing to shallow copy range loop vars. While here, remove an unused parameter as spotted by gopls. --- goproxytest/proxy.go | 9 +++------ imports/scan.go | 1 + internal/os/execpath/lp_unix.go | 7 +++---- testscript/exe.go | 1 - testscript/testscript.go | 5 ++--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/goproxytest/proxy.go b/goproxytest/proxy.go index d3fc975..e8fe8a7 100644 --- a/goproxytest/proxy.go +++ b/goproxytest/proxy.go @@ -24,6 +24,7 @@ package goproxytest import ( "archive/zip" "bytes" + "cmp" "encoding/json" "fmt" "io/fs" @@ -76,12 +77,8 @@ func NewServer(dir, addr string) (*Server, error) { } func newServer(dir, addr string, logf func(string, ...any)) (*Server, error) { - if addr == "" { - addr = "localhost:0" - } - if dir == "" { - dir = "testmod" - } + addr = cmp.Or(addr, "localhost:0") + dir = cmp.Or(dir, "testmod") srv := Server{dir: dir, logf: logf} if err := srv.readModList(); err != nil { return nil, fmt.Errorf("cannot read modules: %v", err) diff --git a/imports/scan.go b/imports/scan.go index e69e271..dbed355 100644 --- a/imports/scan.go +++ b/imports/scan.go @@ -85,6 +85,7 @@ Files: var ErrNoGo = fmt.Errorf("no Go source files") +// TODO: replace with maps.Keys from go1.23 func keys(m map[string]bool) []string { var list []string for k := range m { diff --git a/internal/os/execpath/lp_unix.go b/internal/os/execpath/lp_unix.go index 37f18c7..d233a1f 100644 --- a/internal/os/execpath/lp_unix.go +++ b/internal/os/execpath/lp_unix.go @@ -7,6 +7,7 @@ package execpath import ( + "cmp" "os" "path/filepath" "strings" @@ -45,10 +46,8 @@ func Look(file string, getenv func(string) string) (string, error) { } path := getenv("PATH") for _, dir := range filepath.SplitList(path) { - if dir == "" { - // Unix shell semantics: path element "" means "." - dir = "." - } + // Unix shell semantics: path element "" means "." + dir = cmp.Or(dir, ".") path := filepath.Join(dir, file) if err := findExecutable(path); err == nil { return path, nil diff --git a/testscript/exe.go b/testscript/exe.go index 0ccd773..9f9fdc1 100644 --- a/testscript/exe.go +++ b/testscript/exe.go @@ -75,7 +75,6 @@ func RunMain(m TestingM, commands map[string]func() int) (exitCode int) { // We're not in a subcommand. for name := range commands { - name := name // Set up this command in the directory we added to $PATH. binfile := filepath.Join(bindir, name) if runtime.GOOS == "windows" { diff --git a/testscript/testscript.go b/testscript/testscript.go index 1146050..e402483 100644 --- a/testscript/testscript.go +++ b/testscript/testscript.go @@ -320,7 +320,6 @@ func RunT(t T, p Params) { refCount := int32(len(files)) names := make(map[string]bool) for _, file := range files { - file := file name := filepath.Base(file) if name1, ok := strings.CutSuffix(name, ".txt"); ok { name = name1 @@ -737,13 +736,13 @@ func (ts *TestScript) runLine(line string) (runOK bool) { ts.Fatalf("unknown command %q", args[0]) } } - ts.callBuiltinCmd(args[0], func() { + ts.callBuiltinCmd(func() { cmd(ts, neg, args[1:]) }) return true } -func (ts *TestScript) callBuiltinCmd(cmd string, runCmd func()) { +func (ts *TestScript) callBuiltinCmd(runCmd func()) { ts.runningBuiltin = true defer func() { r := recover() From 99e95bbf869d490b93a32fc84381a622a08e2606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 20 Sep 2024 13:49:13 +0100 Subject: [PATCH 3/3] README: update the package list dirhash, modfile, module, and semver simply forward to the upstream packages now, so we should no longer advertise them to users. txtar is very close to that state, but not quite. Add a note. --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bd1b79c..f670356 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,17 @@ Contributions are welcome, but please open an issue for discussion first. Included are the following: -- dirhash: calculate hashes over directory trees the same way that the Go tool does. - goproxytest: a GOPROXY implementation designed for test use. - gotooltest: Use the Go tool inside test scripts (see testscript below) - imports: list of known architectures and OSs, and support for reading import statements. -- modfile: read and write `go.mod` files while preserving formatting and comments. -- module: module paths and versions. - par: do work in parallel. -- semver: semantic version parsing. - testenv: information on the current testing environment. - testscript: script-based testing based on txtar files - txtar: simple text-based file archives for testing. +Note that most users of `txtar` should use https://pkg.go.dev/golang.org/x/tools/txtar instead. +Our package will be replaced by it once https://github.com/golang/go/issues/59264 is fixed. + ### testscript The most popular package here is the [testscript](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) package: