summaryrefslogtreecommitdiffhomepage
path: root/test/runtimes/common
diff options
context:
space:
mode:
authorBrett Landau <brettlandau@google.com>2019-08-01 18:49:40 -0700
committergVisor bot <gvisor-bot@google.com>2019-08-01 18:53:35 -0700
commit6a1ac3407743adf7c0493ab9da97a1dff4e4b2ac (patch)
treea22cc3387e64f1dd69f18d50de6f66b113d90615 /test/runtimes/common
parent3eff0531adc6d28eea49be65fa747e2b3163f44d (diff)
Refactor ListTests() to common.Search().
This change removes the filepath.Walk() function from proctor- go, php, and nodejs. The filepath.Walk() is now defined in common.go in Search(). Each proctor binary passes root directory and testFilter arguments to Search(). proctor-python.go no longer uses filepath.Walk() to search for tests. There is a built-in list test function within python's language test suite so that is being used instead. PiperOrigin-RevId: 261242897
Diffstat (limited to 'test/runtimes/common')
-rw-r--r--test/runtimes/common/common.go29
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 {