diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4d7234b2..5416122c 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/README.md b/README.md index bd1b79cb..f6703565 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: diff --git a/go.mod b/go.mod index 6b4304f2..58d0c9ef 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 diff --git a/goproxytest/proxy.go b/goproxytest/proxy.go index d3fc975a..e8fe8a7c 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 e69e271e..dbed3553 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 37f18c79..d233a1f5 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 0ccd7738..9f9fdc14 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 11460502..e4024837 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()