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 57a3b42 commit 447d509
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module mvdan.cc/unparam
go 1.22.0

require (
github.com/rogpeppe/go-internal v1.12.0
golang.org/x/tools v0.25.0
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a
golang.org/x/tools v0.26.0
)

require (
golang.org/x/mod v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
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=
18 changes: 4 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,28 @@ import (
)

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

tests = flagSet.Bool("tests", false, "load tests too")
exported = flagSet.Bool("exported", false, "inspect exported functions")
debug = flagSet.Bool("debug", false, "debug prints")
)

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

func main1() int {
flagSet.Usage = func() {
fmt.Fprintln(os.Stderr, "usage: unparam [flags] [package ...]")
flagSet.PrintDefaults()
}
if err := flagSet.Parse(os.Args[1:]); err != nil {
if err != flag.ErrHelp {
fmt.Fprintln(os.Stderr, err)
}
return 1
}
flagSet.Parse(os.Args[1:])
warns, err := check.UnusedParams(*tests, *exported, *debug, flagSet.Args()...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
os.Exit(1)
}
for _, warn := range warns {
fmt.Println(warn)
}
if len(warns) > 0 {
return 1
os.Exit(1)
}
return 0
}
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

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

func TestScript(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion testdata/script/cmds.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! exec unparam -h
exec unparam -h
stderr '^usage: unparam \[flags'
! stderr 'test\.' # don't include flags from testing
! stderr 'command not specified'
Expand Down

0 comments on commit 447d509

Please sign in to comment.