Skip to content

Commit

Permalink
care -tags flag to list test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed May 22, 2022
1 parent e28019f commit 9d45c88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ func (c *cmdRegexp) run(ctx context.Context, argv []string, outStream io.Writer,
return fmt.Errorf("invalid index: %s", err)
}

str, err := getOut(pkgs, total, idx)
str, err := getOut(pkgs, detectTags(argv), total, idx)
if err != nil {
return err
}
_, err = fmt.Fprintln(outStream, str)
return err
}

func getOut(pkgs []string, total, idx int) (string, error) {
func getOut(pkgs []string, tags string, total, idx int) (string, error) {
if total < 1 {
return "", fmt.Errorf("invalid total: %d", total)
}
if idx >= total {
return "", fmt.Errorf("index shoud be between 0 to total-1, but: %d (total:%d)", idx, total)
}
testLists, err := getTestListsFromPkgs(pkgs)
testLists, err := getTestListsFromPkgs(pkgs, tags)
if err != nil {
return "", err
}
Expand Down
8 changes: 6 additions & 2 deletions gotesplit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ Options:
return run(ctx, *total, *index, *junitDir, argv, outStream, errStream)
}

func getTestListsFromPkgs(pkgs []string) ([]testList, error) {
args := append([]string{"test", "-list", "."}, pkgs...)
func getTestListsFromPkgs(pkgs []string, tags string) ([]testList, error) {
args := []string{"test", "-list"}
if tags != "" {
args = append(args, tags)
}
args = append(append(args, "."), pkgs...)
buf := &bytes.Buffer{}
c := exec.Command("go", args...)
c.Stdout = buf
Expand Down
2 changes: 1 addition & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func run(ctx context.Context, total, idx uint, junitDir string, argv []string, o
}
}

testLists, err := getTestListsFromPkgs(pkgs)
testLists, err := getTestListsFromPkgs(pkgs, detectTags(argv))
if err != nil {
return err
}
Expand Down

0 comments on commit 9d45c88

Please sign in to comment.