Skip to content

Commit

Permalink
take advantage of Go 1.22
Browse files Browse the repository at this point in the history
cmp.Or and no longer needing to shallow copy range loop vars.

While here, remove an unused parameter as spotted by gopls.
  • Loading branch information
mvdan committed Sep 23, 2024
1 parent 5ce929e commit 4794549
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
9 changes: 3 additions & 6 deletions goproxytest/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package goproxytest
import (
"archive/zip"
"bytes"
"cmp"
"encoding/json"
"fmt"
"io/fs"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions imports/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions internal/os/execpath/lp_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package execpath

import (
"cmp"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion testscript/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
5 changes: 2 additions & 3 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4794549

Please sign in to comment.