Skip to content

Commit

Permalink
allow test args to be specified at the end after a -- arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensayshi committed May 11, 2021
1 parent b313a72 commit 9114a6d
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions courtney.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,31 @@ func main() {
shortFlag := flag.Bool("short", false, "Pass the short flag to the go test command")
timeoutFlag := flag.String("timeout", "", "Pass the timeout flag to the go test command")
outputFlag := flag.String("o", "", "Override coverage file location")
argsFlag := new(argsValue)
flag.Var(argsFlag, "t", "Argument to pass to the 'go test' command. Can be used more than once.")
testArgsFlag := new(argsValue)
flag.Var(testArgsFlag, "t", "Argument to pass to the 'go test' command. Can be used more than once.")
loadFlag := flag.String("l", "", "Load coverage file(s) instead of running 'go test'")
excludeErrNoReturnParamFlag := flag.Bool("excludenoreturn", false, "Exclude error blocks in functions with no return params")
excludePkgsFlag := new(argsValue)
flag.Var(excludePkgsFlag, "ex", "Argument to exclude packages from the cover profile.")

flag.Parse()
args := flag.Args()

// any args after a "--" arg will be considered args for `go test`
testArgs := testArgsFlag.args
pkgArgs := make([]string, 0, len(args))
foundTestArgs := false
for _, arg := range args {
if strings.TrimSpace(arg) == "--" {
foundTestArgs = true
continue
}
if foundTestArgs {
testArgs = append(testArgs, arg)
} else {
pkgArgs = append(pkgArgs, arg)
}
}

setup := &shared.Setup{
Env: env,
Expand All @@ -44,19 +61,19 @@ func main() {
Options: shared.Options{
ExcludeErrNoReturnParam: *excludeErrNoReturnParamFlag,
},
TestArgs: argsFlag.args,
TestArgs: testArgs,
ExcludePkgs: excludePkgsFlag.args,
Load: *loadFlag,
}
if err := Run(setup); err != nil {
if err := Run(setup, pkgArgs); err != nil {
fmt.Printf("%+v", err)
os.Exit(1)
}
}

// Run initiates the command with the provided setup
func Run(setup *shared.Setup) error {
if err := setup.Parse(flag.Args()); err != nil {
func Run(setup *shared.Setup, pkgArgs []string) error {
if err := setup.Parse(pkgArgs); err != nil {
return errors.Wrapf(err, "Parse")
}

Expand Down

0 comments on commit 9114a6d

Please sign in to comment.