Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/check/ut: support pattern matching on test names #33020

Merged
merged 7 commits into from
Mar 23, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions tools/check/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"os/exec"
"path"
"regexp"
"runtime"
"sort"
"strings"
Expand Down Expand Up @@ -101,7 +102,7 @@ func cmdList(args ...string) bool {
}

// list test case of a single package
if len(args) == 1 {
if len(args) == 1 || len(args) == 2 {
pkg := args[0]
pkgs = filter(pkgs, func(s string) bool { return s == pkg })
if len(pkgs) != 1 {
Expand Down Expand Up @@ -129,8 +130,22 @@ func cmdList(args ...string) bool {
fmt.Println("list test cases for package error", err)
return false
}
if len(args) == 1 {
// List all the tests.
for _, x := range res {
fmt.Println(x.test)
}
return true
}
regEx, err := regexp.Compile(args[1])
if err != nil {
fmt.Println("list test cases regex error", err)
return false
}
for _, x := range res {
fmt.Println(x.test)
if regEx.MatchString(x.test) {
fmt.Println(x.test)
}
}
}
return true
Expand Down Expand Up @@ -252,7 +267,11 @@ func cmdRun(args ...string) bool {
// filter the test case to run
tmp := tasks[:0]
for _, task := range tasks {
if strings.Contains(task.test, args[1]) {
r, err := regexp.Compile(args[1])
if err != nil {
fmt.Println("regex error", err)
}
if r.MatchString(task.test) {
tmp = append(tmp, task)
}
}
Expand Down