Skip to content
Open
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
8 changes: 4 additions & 4 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.23.x'
- '1.24.x'
- '1.25.x'
- '1.26.x'
os:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v5
- name: Install Go
uses: actions/setup-go@v5
with:
Expand All @@ -33,7 +33,7 @@ jobs:
go test -race ./...

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

Expand Down
4 changes: 2 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func init() { initEnv() }
func initEnv() {
verify = false
debugHash = false
debug := strings.Split(os.Getenv("GODEBUG"), ",")
for _, f := range debug {
debug := strings.SplitSeq(os.Getenv("GODEBUG"), ",")
for f := range debug {
if f == "gocacheverify=1" {
verify = true
}
Expand Down
4 changes: 2 additions & 2 deletions cache/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Hash struct {
// stripExperiment strips any GOEXPERIMENT configuration from the Go
// version string.
func stripExperiment(version string) string {
if i := strings.Index(version, " X:"); i >= 0 {
return version[:i]
if before, _, ok := strings.Cut(version, " X:"); ok {
return before
}
return version
}
Expand Down
2 changes: 1 addition & 1 deletion fmtsort/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func compare(aVal, bVal reflect.Value) int {
default:
return -1
}
case reflect.Ptr:
case reflect.Pointer:
a, b := aVal.Pointer(), bVal.Pointer()
switch {
case a < b:
Expand Down
42 changes: 21 additions & 21 deletions fmtsort/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ import (
)

var compareTests = [][]reflect.Value{
ct(reflect.TypeOf(int(0)), -1, 0, 1),
ct(reflect.TypeOf(int8(0)), -1, 0, 1),
ct(reflect.TypeOf(int16(0)), -1, 0, 1),
ct(reflect.TypeOf(int32(0)), -1, 0, 1),
ct(reflect.TypeOf(int64(0)), -1, 0, 1),
ct(reflect.TypeOf(uint(0)), 0, 1, 5),
ct(reflect.TypeOf(uint8(0)), 0, 1, 5),
ct(reflect.TypeOf(uint16(0)), 0, 1, 5),
ct(reflect.TypeOf(uint32(0)), 0, 1, 5),
ct(reflect.TypeOf(uint64(0)), 0, 1, 5),
ct(reflect.TypeOf(uintptr(0)), 0, 1, 5),
ct(reflect.TypeOf(string("")), "", "a", "ab"),
ct(reflect.TypeOf(float32(0)), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
ct(reflect.TypeOf(float64(0)), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
ct(reflect.TypeOf(complex64(0+1i)), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
ct(reflect.TypeOf(complex128(0+1i)), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
ct(reflect.TypeOf(false), false, true),
ct(reflect.TypeOf(&ints[0]), &ints[0], &ints[1], &ints[2]),
ct(reflect.TypeOf(chans[0]), chans[0], chans[1], chans[2]),
ct(reflect.TypeOf(toy{}), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
ct(reflect.TypeOf([2]int{}), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
ct(reflect.TypeFor[int](), -1, 0, 1),
ct(reflect.TypeFor[int8](), -1, 0, 1),
ct(reflect.TypeFor[int16](), -1, 0, 1),
ct(reflect.TypeFor[int32](), -1, 0, 1),
ct(reflect.TypeFor[int64](), -1, 0, 1),
ct(reflect.TypeFor[uint](), 0, 1, 5),
ct(reflect.TypeFor[uint8](), 0, 1, 5),
ct(reflect.TypeFor[uint16](), 0, 1, 5),
ct(reflect.TypeFor[uint32](), 0, 1, 5),
ct(reflect.TypeFor[uint64](), 0, 1, 5),
ct(reflect.TypeFor[uintptr](), 0, 1, 5),
ct(reflect.TypeFor[string](), "", "a", "ab"),
ct(reflect.TypeFor[float32](), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
ct(reflect.TypeFor[float64](), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
ct(reflect.TypeFor[complex64](), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
ct(reflect.TypeFor[complex128](), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
ct(reflect.TypeFor[bool](), false, true),
ct(reflect.TypeFor[*int](), &ints[0], &ints[1], &ints[2]),
ct(reflect.TypeFor[chan int](), chans[0], chans[1], chans[2]),
ct(reflect.TypeFor[toy](), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
ct(reflect.TypeFor[[2]int](), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
ct(reflect.TypeOf(any(any(0))), iFace, 1, 2, 3),
}

Expand Down
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.23
go 1.25

require (
golang.org/x/mod v0.21.0
Expand Down
35 changes: 35 additions & 0 deletions goproxytest/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,41 @@ func (srv *Server) handler(w http.ResponseWriter, r *http.Request) {
return
}
path := strings.TrimPrefix(r.URL.Path, "/mod/")
if enc, ok := strings.CutSuffix(path, "/@latest"); ok {
modPath, err := module.UnescapePath(enc)
if err != nil {
srv.logf("go proxy_test: %v\n", err)
http.NotFound(w, r)
return
}
var best string
for _, m := range srv.modList {
if m.Path == modPath && !isPseudoVersion(m.Version) {
if err := module.Check(m.Path, m.Version); err == nil {
if best == "" || semver.Compare(m.Version, best) > 0 {
best = m.Version
}
}
}
}
if best == "" {
http.NotFound(w, r)
return
}
a := srv.readArchive(modPath, best)
if a == nil {
http.NotFound(w, r)
return
}
for _, f := range a.Files {
if f.Name == ".info" {
w.Write(f.Data)
return
}
}
http.NotFound(w, r)
return
}
i := strings.Index(path, "/@v/")
if i < 0 {
http.NotFound(w, r)
Expand Down
29 changes: 29 additions & 0 deletions goproxytest/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package goproxytest_test

import (
"encoding/json"
"io"
"net/http"
"path/filepath"
"testing"

Expand All @@ -30,3 +33,29 @@ func TestScripts(t *testing.T) {
}
testscript.Run(t, p)
}

func TestLatest(t *testing.T) {
srv := goproxytest.NewTestServer(t, filepath.Join("testdata", "mod"), "")

resp, err := http.Get(srv.URL + "/fruit.com/@latest")
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
t.Fatalf("got status %d, want 200", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
var info struct {
Version string
}
if err := json.Unmarshal(body, &info); err != nil {
t.Fatalf("invalid JSON response: %v", err)
}
if info.Version != "v1.1.0" {
t.Fatalf("got version %q, want %q", info.Version, "v1.1.0")
}
}
12 changes: 6 additions & 6 deletions imports/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func matchTags(name string, tags map[string]bool) bool {
if name == "" {
return false
}
if i := strings.Index(name, ","); i >= 0 {
if before, after, ok := strings.Cut(name, ","); ok {
// comma-separated list
ok1 := matchTags(name[:i], tags)
ok2 := matchTags(name[i+1:], tags)
ok1 := matchTags(before, tags)
ok2 := matchTags(after, tags)
return ok1 && ok2
}
if strings.HasPrefix(name, "!!") { // bad syntax, reject always
Expand Down Expand Up @@ -200,13 +200,13 @@ var (
)

func init() {
for _, v := range strings.Fields(goosList) {
for v := range strings.FieldsSeq(goosList) {
KnownOS[v] = true
}
for _, v := range strings.Fields(unixList) {
for v := range strings.FieldsSeq(unixList) {
UnixOS[v] = true
}
for _, v := range strings.Fields(goarchList) {
for v := range strings.FieldsSeq(goarchList) {
KnownArch[v] = true
}
}
Expand Down
7 changes: 0 additions & 7 deletions internal/misspell/misspell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,3 @@ func editDistance(a, b []rune) int {
}
return m
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
2 changes: 1 addition & 1 deletion lockedfile/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestTransform(t *testing.T) {

const maxChunkWords = 8 << 10
buf := make([]byte, 2*maxChunkWords*8)
for i := uint64(0); i < 2*maxChunkWords; i++ {
for i := range uint64(2 * maxChunkWords) {
binary.LittleEndian.PutUint64(buf[i*8:], i)
}
if err := lockedfile.Write(path, bytes.NewReader(buf[:8]), 0666); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions testscript/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ func (ts *TestScript) cmdEnv(neg bool, args []string) {
return
}
for _, env := range args {
i := strings.Index(env, "=")
if i < 0 {
before, after, ok := strings.Cut(env, "=")
if !ok {
// Display value instead of setting it.
ts.Logf("%s=%s\n", env, ts.Getenv(env))
continue
}
ts.Setenv(env[:i], env[i+1:])
ts.Setenv(before, after)
}
}

Expand Down
1 change: 0 additions & 1 deletion testscript/internal/pty/pty.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin
// +build linux darwin

package pty

Expand Down
1 change: 0 additions & 1 deletion testscript/internal/pty/pty_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !linux && !darwin
// +build !linux,!darwin

package pty

Expand Down
8 changes: 4 additions & 4 deletions testscript/testscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ func (ts *TestScript) setup() string {

ts.envMap = make(map[string]string)
for _, kv := range ts.env {
if i := strings.Index(kv, "="); i >= 0 {
ts.envMap[envvarname(kv[:i])] = kv[i+1:]
if before, after, ok := strings.Cut(kv, "="); ok {
ts.envMap[envvarname(before)] = after
}
}
return string(a.Comment)
Expand Down Expand Up @@ -609,8 +609,8 @@ func (ts *TestScript) run() {
// Extract next line.
ts.lineno++
var line string
if i := strings.Index(script, "\n"); i >= 0 {
line, script = script[:i], script[i+1:]
if before, after, ok := strings.Cut(script, "\n"); ok {
line, script = before, after
} else {
line, script = script, ""
}
Expand Down
Loading