Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Go, update the README #273

Merged
merged 3 commits into from
Sep 23, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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.21
go 1.22

require (
golang.org/x/mod v0.18.0
Expand Down
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