From 4ca513da5cd98707ef883a164b4a17e75826e762 Mon Sep 17 00:00:00 2001 From: Oleg Chunikhin Date: Sat, 27 Oct 2018 18:26:35 -0400 Subject: [PATCH] fix running precompiled tests via ginkgo CLI on windows (#529) --- ginkgo/testrunner/test_runner.go | 7 ++++++- ginkgo/testsuite/test_suite.go | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ginkgo/testrunner/test_runner.go b/ginkgo/testrunner/test_runner.go index a0113e136..76a8449de 100644 --- a/ginkgo/testrunner/test_runner.go +++ b/ginkgo/testrunner/test_runner.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strconv" "strings" "syscall" @@ -425,7 +426,11 @@ func (t *TestRunner) cmd(ginkgoArgs []string, stream io.Writer, node int) *exec. path := t.compilationTargetPath if t.Suite.Precompiled { - path, _ = filepath.Abs(filepath.Join(t.Suite.Path, fmt.Sprintf("%s.test", t.Suite.PackageName))) + windowsExt := "" + if runtime.GOOS == "windows" { + windowsExt = ".exe" + } + path, _ = filepath.Abs(filepath.Join(t.Suite.Path, fmt.Sprintf("%s.test%s", t.Suite.PackageName, windowsExt))) } cmd := exec.Command(path, args...) diff --git a/ginkgo/testsuite/test_suite.go b/ginkgo/testsuite/test_suite.go index 9de8c2bb4..da3a6b3e2 100644 --- a/ginkgo/testsuite/test_suite.go +++ b/ginkgo/testsuite/test_suite.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "regexp" + "runtime" "strings" ) @@ -26,16 +27,22 @@ func PrecompiledTestSuite(path string) (TestSuite, error) { return TestSuite{}, errors.New("this is a directory, not a file") } - if filepath.Ext(path) != ".test" { - return TestSuite{}, errors.New("this is not a .test binary") + if (runtime.GOOS != "windows" && filepath.Ext(path) != ".test") || + (runtime.GOOS == "windows" && !strings.HasSuffix(path, ".test.exe")) { + return TestSuite{}, errors.New("this is not a .test (.test.exe) binary") } - if info.Mode()&0111 == 0 { + if runtime.GOOS != "windows" && info.Mode()&0111 == 0 { return TestSuite{}, errors.New("this is not executable") } dir := relPath(filepath.Dir(path)) - packageName := strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)) + var packageName string + if strings.HasSuffix(path, ".test.exe") { + packageName = strings.TrimSuffix(filepath.Base(path), ".test.exe") + } else { + packageName = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)) + } return TestSuite{ Path: dir,