summaryrefslogtreecommitdiffhomepage
path: root/test/runtimes/go
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/go
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/go')
-rw-r--r--test/runtimes/go/proctor-go.go43
1 files changed, 15 insertions, 28 deletions
diff --git a/test/runtimes/go/proctor-go.go b/test/runtimes/go/proctor-go.go
index 3751c2c81..3eb24576e 100644
--- a/test/runtimes/go/proctor-go.go
+++ b/test/runtimes/go/proctor-go.go
@@ -40,7 +40,7 @@ var (
// Directories with .dir contain helper files for tests.
// Exclude benchmarks and stress tests.
- exclDirs = regexp.MustCompile(`^.+\/(bench|stress)\/.+$|^.+\.dir.+$`)
+ dirFilter = regexp.MustCompile(`^(bench|stress)\/.+$|^.+\.dir.+$`)
)
type goRunner struct {
@@ -59,36 +59,27 @@ func (g goRunner) ListTests() ([]string, error) {
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
- log.Fatalf("Failed to list: %v", err)
+ return nil, fmt.Errorf("failed to list: %v", err)
}
- var testSlice []string
+ var toolSlice []string
for _, test := range strings.Split(string(out), "\n") {
- testSlice = append(testSlice, test)
+ toolSlice = append(toolSlice, test)
}
// Go tests on disk.
- if err := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error {
- name := filepath.Base(path)
-
- if info.IsDir() {
- return nil
- }
-
- if !testRegEx.MatchString(name) {
- return nil
- }
-
- if exclDirs.MatchString(path) {
- return nil
+ diskSlice, err := common.Search(testDir, testRegEx)
+ if err != nil {
+ return nil, err
+ }
+ // Remove items from /bench/, /stress/ and .dir files
+ diskFiltered := diskSlice[:0]
+ for _, file := range diskSlice {
+ if !dirFilter.MatchString(file) {
+ diskFiltered = append(diskFiltered, file)
}
-
- testSlice = append(testSlice, path)
- return nil
- }); err != nil {
- return nil, fmt.Errorf("walking %q: %v", testDir, err)
}
- return testSlice, nil
+ return append(toolSlice, diskFiltered...), nil
}
func (g goRunner) RunTest(test string) error {
@@ -96,11 +87,7 @@ func (g goRunner) RunTest(test string) error {
// This will determine whether or not it is a Go test on disk.
if strings.HasSuffix(test, ".go") {
// Test has suffix ".go" which indicates a disk test, run it as such.
- relPath, err := filepath.Rel(testDir, test)
- if err != nil {
- return fmt.Errorf("failed to get rel path: %v", err)
- }
- cmd := exec.Command(goBin, "run", "run.go", "-v", "--", relPath)
+ cmd := exec.Command(goBin, "run", "run.go", "-v", "--", test)
cmd.Dir = testDir
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {