From 57745994384ee1ff94fc7bed4f814ba75e39d48e Mon Sep 17 00:00:00 2001 From: Brett Landau Date: Tue, 23 Jul 2019 13:31:30 -0700 Subject: 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 --- runsc/test/runtimes/proctor-php.go | 41 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'runsc/test/runtimes/proctor-php.go') 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) + } +} -- cgit v1.2.3