Skip to content

Commit

Permalink
Merge pull request #1310 from visualfc/test
Browse files Browse the repository at this point in the history
cmd/gop: test pass flags
  • Loading branch information
xushiwei committed Jun 26, 2022
2 parents adaa150 + f5b6325 commit aae2572
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
}

func runCmd(cmd *base.Command, args []string) {
pass := base.PassBuildFlags(cmd)
pass := PassTestFlags(cmd)
err := flag.Parse(args)
if err != nil {
log.Fatalln("parse input arguments failed:", err)
Expand Down
58 changes: 58 additions & 0 deletions cmd/internal/test/testflag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package test

import (
"github.com/goplus/gop/cmd/internal/base"
)

type boolFlag interface {
IsBoolFlag() bool
}

func PassTestFlags(cmd *base.Command) *base.PassArgs {
p := base.PassBuildFlags(cmd)
p.Bool("c", "i", "cover", "json", "benchmem", "failfast", "short")
p.Var("o", "covermode", "coverpkg", "exec", "vet",
"bench", "benchtime", "blockprofile", "blockprofilerate",
"count", "coverprofile", "cpu", "cpuprofile",
"fuzz", "list", "memprofile", "memprofilerate",
"mutexprofile", "mutexprofilefraction", "outputdir", "parallel",
"run", "timeout", "fuzztime", "fuzzminimizetime",
"trace", "shuffle")
for name := range passFlagToTest {
if b, ok := cmd.Flag.Lookup(name).Value.(boolFlag); ok && b.IsBoolFlag() {
p.Bool("test." + name)
} else {
p.Var("test." + name)
}
}
return p
}

var passFlagToTest = map[string]bool{
"bench": true,
"benchmem": true,
"benchtime": true,
"blockprofile": true,
"blockprofilerate": true,
"count": true,
"coverprofile": true,
"cpu": true,
"cpuprofile": true,
"failfast": true,
"fuzz": true,
"fuzzminimizetime": true,
"fuzztime": true,
"list": true,
"memprofile": true,
"memprofilerate": true,
"mutexprofile": true,
"mutexprofilefraction": true,
"outputdir": true,
"parallel": true,
"run": true,
"short": true,
"shuffle": true,
"timeout": true,
"trace": true,
"v": true,
}

0 comments on commit aae2572

Please sign in to comment.