Skip to content

Commit

Permalink
fix running precompiled tests via ginkgo CLI on windows (onsi#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
olegch committed Oct 27, 2018
1 parent aec9277 commit 4ca513d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ginkgo/testrunner/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -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...)
Expand Down
15 changes: 11 additions & 4 deletions ginkgo/testsuite/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
)

Expand All @@ -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,
Expand Down

0 comments on commit 4ca513d

Please sign in to comment.