Skip to content

Commit 4794549

Browse files
committed
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.
1 parent 5ce929e commit 4794549

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

goproxytest/proxy.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package goproxytest
2424
import (
2525
"archive/zip"
2626
"bytes"
27+
"cmp"
2728
"encoding/json"
2829
"fmt"
2930
"io/fs"
@@ -76,12 +77,8 @@ func NewServer(dir, addr string) (*Server, error) {
7677
}
7778

7879
func newServer(dir, addr string, logf func(string, ...any)) (*Server, error) {
79-
if addr == "" {
80-
addr = "localhost:0"
81-
}
82-
if dir == "" {
83-
dir = "testmod"
84-
}
80+
addr = cmp.Or(addr, "localhost:0")
81+
dir = cmp.Or(dir, "testmod")
8582
srv := Server{dir: dir, logf: logf}
8683
if err := srv.readModList(); err != nil {
8784
return nil, fmt.Errorf("cannot read modules: %v", err)

imports/scan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Files:
8585

8686
var ErrNoGo = fmt.Errorf("no Go source files")
8787

88+
// TODO: replace with maps.Keys from go1.23
8889
func keys(m map[string]bool) []string {
8990
var list []string
9091
for k := range m {

internal/os/execpath/lp_unix.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package execpath
88

99
import (
10+
"cmp"
1011
"os"
1112
"path/filepath"
1213
"strings"
@@ -45,10 +46,8 @@ func Look(file string, getenv func(string) string) (string, error) {
4546
}
4647
path := getenv("PATH")
4748
for _, dir := range filepath.SplitList(path) {
48-
if dir == "" {
49-
// Unix shell semantics: path element "" means "."
50-
dir = "."
51-
}
49+
// Unix shell semantics: path element "" means "."
50+
dir = cmp.Or(dir, ".")
5251
path := filepath.Join(dir, file)
5352
if err := findExecutable(path); err == nil {
5453
return path, nil

testscript/exe.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func RunMain(m TestingM, commands map[string]func() int) (exitCode int) {
7575

7676
// We're not in a subcommand.
7777
for name := range commands {
78-
name := name
7978
// Set up this command in the directory we added to $PATH.
8079
binfile := filepath.Join(bindir, name)
8180
if runtime.GOOS == "windows" {

testscript/testscript.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ func RunT(t T, p Params) {
320320
refCount := int32(len(files))
321321
names := make(map[string]bool)
322322
for _, file := range files {
323-
file := file
324323
name := filepath.Base(file)
325324
if name1, ok := strings.CutSuffix(name, ".txt"); ok {
326325
name = name1
@@ -737,13 +736,13 @@ func (ts *TestScript) runLine(line string) (runOK bool) {
737736
ts.Fatalf("unknown command %q", args[0])
738737
}
739738
}
740-
ts.callBuiltinCmd(args[0], func() {
739+
ts.callBuiltinCmd(func() {
741740
cmd(ts, neg, args[1:])
742741
})
743742
return true
744743
}
745744

746-
func (ts *TestScript) callBuiltinCmd(cmd string, runCmd func()) {
745+
func (ts *TestScript) callBuiltinCmd(runCmd func()) {
747746
ts.runningBuiltin = true
748747
defer func() {
749748
r := recover()

0 commit comments

Comments
 (0)