diff options
Diffstat (limited to 'test/runtimes/common/common.go')
-rw-r--r-- | test/runtimes/common/common.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/runtimes/common/common.go b/test/runtimes/common/common.go index 3f289d459..0ff87fa8b 100644 --- a/test/runtimes/common/common.go +++ b/test/runtimes/common/common.go @@ -19,6 +19,8 @@ import ( "flag" "fmt" "os" + "path/filepath" + "regexp" ) var ( @@ -71,6 +73,33 @@ func LaunchFunc(tr TestRunner) error { return nil } +// Search uses filepath.Walk to perform a search of the disk for test files +// and returns a string slice of tests. +func Search(root string, testFilter *regexp.Regexp) ([]string, error) { + var testSlice []string + + err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { + name := filepath.Base(path) + + if info.IsDir() || !testFilter.MatchString(name) { + return nil + } + + relPath, err := filepath.Rel(root, path) + if err != nil { + return err + } + testSlice = append(testSlice, relPath) + return nil + }) + + if err != nil { + return nil, fmt.Errorf("walking %q: %v", root, err) + } + + return testSlice, nil +} + func runAllTests(tr TestRunner) error { tests, err := tr.ListTests() if err != nil { |