From edcc60b931232d5bea4254af31965da126f07a68 Mon Sep 17 00:00:00 2001 From: Brett Landau Date: Wed, 31 Jul 2019 11:34:34 -0700 Subject: Refactor proctor binaries to implement testRunner interface. Shared code among proctor-*.go files has been refactored into common/common.go. The common package is imported in each proctor binary and a struct is created to implement the testRunner interface defined in common.go. This allows for the proctor binaries to be updated without having to copy/paste the same code across all files. There are no usage or functionality changes. PiperOrigin-RevId: 260967080 --- test/runtimes/php/BUILD | 1 + test/runtimes/php/proctor-php.go | 53 +++++++++------------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) (limited to 'test/runtimes/php') diff --git a/test/runtimes/php/BUILD b/test/runtimes/php/BUILD index 22aef7ba4..31799b77a 100644 --- a/test/runtimes/php/BUILD +++ b/test/runtimes/php/BUILD @@ -5,4 +5,5 @@ package(licenses = ["notice"]) go_binary( name = "proctor-php", srcs = ["proctor-php.go"], + deps = ["//test/runtimes/common"], ) diff --git a/test/runtimes/php/proctor-php.go b/test/runtimes/php/proctor-php.go index 9dfb33b04..3ee4cf056 100644 --- a/test/runtimes/php/proctor-php.go +++ b/test/runtimes/php/proctor-php.go @@ -16,53 +16,31 @@ package main import ( - "flag" "fmt" "log" "os" "os/exec" "path/filepath" "regexp" + + "gvisor.dev/gvisor/test/runtimes/common" ) var ( - list = flag.Bool("list", false, "list all available tests") - test = flag.String("test", "", "run a single test from the list of available tests") - version = flag.Bool("v", false, "print out the version of node that is installed") - dir = os.Getenv("LANG_DIR") testRegEx = regexp.MustCompile(`^.+\.phpt$`) ) -func main() { - flag.Parse() +type phpRunner struct { +} - if *list && *test != "" { - flag.PrintDefaults() - os.Exit(1) - } - if *list { - 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 - } - if *test != "" { - runTest(*test) - return +func main() { + if err := common.LaunchFunc(phpRunner{}); err != nil { + log.Fatalf("Failed to start: %v", err) } - runAllTests() } -func listTests() ([]string, error) { +func (p phpRunner) ListTests() ([]string, error) { var testSlice []string err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { @@ -87,21 +65,12 @@ func listTests() ([]string, error) { return testSlice, nil } -func runTest(test string) { +func (p phpRunner) RunTest(test string) error { 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) + return fmt.Errorf("failed to run: %v", err) } + return nil } -- cgit v1.2.3