From 6a1ac3407743adf7c0493ab9da97a1dff4e4b2ac Mon Sep 17 00:00:00 2001 From: Brett Landau Date: Thu, 1 Aug 2019 18:49:40 -0700 Subject: 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 --- test/runtimes/go/proctor-go.go | 43 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'test/runtimes/go') 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 { -- cgit v1.2.3