diff options
author | Brett Landau <brettlandau@google.com> | 2019-07-23 13:31:30 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-23 13:32:43 -0700 |
commit | 57745994384ee1ff94fc7bed4f814ba75e39d48e (patch) | |
tree | b1a4cc396b095259b66e8689e9046fd3a5e5de5e /runsc/test/runtimes/proctor-php.go | |
parent | 12c256568ba784c07cf73822359faac2971e8306 (diff) |
Make runAllTests() consistent with listTests().
This change has the listTests() function return
a string slice of all the tests. Originally, I
planned not to modify the listTests() function
and instead capture the output of it and then
iterate through the captured output. I decided
against this approach as most of the test binaries
already produce a slice as they collect tests
through filepath.Walk(). Now I use this slice
and return it so that I can iterate through in
runAllTests() and also when printing out the tests.
PiperOrigin-RevId: 259599782
Diffstat (limited to 'runsc/test/runtimes/proctor-php.go')
-rw-r--r-- | runsc/test/runtimes/proctor-php.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/runsc/test/runtimes/proctor-php.go b/runsc/test/runtimes/proctor-php.go index 3d305c709..9dfb33b04 100644 --- a/runsc/test/runtimes/proctor-php.go +++ b/runsc/test/runtimes/proctor-php.go @@ -42,18 +42,28 @@ func main() { os.Exit(1) } if *list { - listTests() + tests, err := listTests() + if err != nil { + log.Fatalf("Failed to list tests: %v", err) + } + for _, test := range tests { + fmt.Println(test) + } return } if *version { fmt.Println("PHP version: ", os.Getenv("LANG_VER"), " is installed.") return } - runTest(*test) + if *test != "" { + runTest(*test) + return + } + runAllTests() } -func listTests() { - var files []string +func listTests() ([]string, error) { + var testSlice []string err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { name := filepath.Base(path) @@ -66,27 +76,32 @@ func listTests() { if err != nil { return err } - files = append(files, relPath) + testSlice = append(testSlice, relPath) return nil }) if err != nil { - log.Fatalf("Failed to walk %q: %v", dir, err) + return nil, fmt.Errorf("walking %q: %v", dir, err) } - for _, file := range files { - fmt.Println(file) - } + return testSlice, nil } func runTest(test string) { - args := []string{"test", "TESTS="} - if test != "" { - args[1] = args[1] + test - } + args := []string{"test", "TESTS=" + test} cmd := exec.Command("make", args...) cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr if err := cmd.Run(); err != nil { log.Fatalf("Failed to run: %v", err) } } + +func runAllTests() { + tests, err := listTests() + if err != nil { + log.Fatalf("Failed to list tests: %v", err) + } + for _, test := range tests { + runTest(test) + } +} |