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-java.go | 43 ++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'runsc/test/runtimes/proctor-java.go') diff --git a/runsc/test/runtimes/proctor-java.go b/runsc/test/runtimes/proctor-java.go index 50f3789dc..0177f421d 100644 --- a/runsc/test/runtimes/proctor-java.go +++ b/runsc/test/runtimes/proctor-java.go @@ -44,17 +44,27 @@ 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("Java version: ", os.Getenv("LANG_VER"), " is installed.") return } - runTest(*test) + if *test != "" { + runTest(*test) + return + } + runAllTests() } -func listTests() { +func listTests() ([]string, error) { args := []string{ "-dir:test/jdk", "-ignore:quiet", @@ -69,25 +79,32 @@ func listTests() { cmd.Stderr = os.Stderr out, err := cmd.Output() if err != nil { - log.Fatalf("Failed to list: %v", err) + return nil, fmt.Errorf("jtreg -listtests : %v", err) } - allTests := string(out) - for _, test := range strings.Split(allTests, "\n") { + var testSlice []string + for _, test := range strings.Split(string(out), "\n") { if !exclDirs.MatchString(test) { - fmt.Println(test) + testSlice = append(testSlice, test) } } + return testSlice, nil } func runTest(test string) { - // TODO(brettlandau): Change to use listTests() for running all tests. - cmd := exec.Command("make", "run-test-tier1") - if test != "" { - args := []string{"-dir:test/jdk/", test} - cmd = exec.Command(jtreg, args...) - } + args := []string{"-dir:test/jdk/", test} + cmd := exec.Command(jtreg, 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