Skip to content

Commit

Permalink
update testscript to drop func() int
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Dec 26, 2024
1 parent 7c954b2 commit 4abb552
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module mvdan.cc/benchinit

go 1.22
go 1.22.0

require (
github.com/rogpeppe/go-internal v1.12.0
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
)

require (
golang.org/x/sys v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/tools v0.26.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a h1:w3tdWGKbLGBPtR/8/oO74W6hmz0qE5q0z9aqSAewaaM=
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a/go.mod h1:S8kfXMp+yh77OxPD4fdM6YUknrZpQxLhvxzS4gDHENY=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
19 changes: 6 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,21 @@ type benchmainPackage struct {
//go:embed benchmain_test.go
var benchmainSource string

func main() { os.Exit(main1()) }

func main1() int {
func main() {
buildflags, testflags, rest := filterFlags(os.Args[1:])
flagSet.Usage = usage
if err := flagSet.Parse(rest); err != nil {
if err == flag.ErrHelp {
return 2
}
}
flagSet.Parse(rest)
pkgs, err := listPackages(flagSet.Args(), buildflags)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
os.Exit(1)
}

// From this point onwards, errors are straightforward.
if err := doBench(pkgs, buildflags, testflags); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
os.Exit(1)
}
return 0
}

func doBench(pkgs []*Package, buildflags, testflags []string) error {
Expand Down Expand Up @@ -240,10 +233,10 @@ func doBench(pkgs []*Package, buildflags, testflags []string) error {
return nil
}

var flagSet = flag.NewFlagSet("benchinit", flag.ContinueOnError)
var flagSet = flag.NewFlagSet("benchinit", flag.ExitOnError)

func usage() {
fmt.Fprintf(os.Stderr, `
fmt.Fprint(os.Stderr, `
Usage of benchinit:
benchinit [benchinit flags] [go test flags] [packages]
Expand Down
7 changes: 3 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package main

import (
"os"
"path/filepath"
"testing"

Expand All @@ -13,9 +12,9 @@ import (
)

func TestMain(m *testing.M) {
os.Exit(testscript.RunMain(m, map[string]func() int{
"benchinit": main1,
}))
testscript.Main(m, map[string]func(){
"benchinit": main,
})
}

func TestScripts(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions testdata/script/flags.txtar
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

! exec benchinit -benchtime=10x -h
exec benchinit -benchtime=10x -h
! stderr 'flag provided but not defined'
stderr 'Usage of benchinit'
stderr 'For example' # definitely includes our help text
Expand Down

0 comments on commit 4abb552

Please sign in to comment.