Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix running precompiled tests via ginkgo CLI on windows (#529) #531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion ginkgo/testrunner/test_runner.go
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move assign value in else block to packageName declaration?

packageName = strings.TrimSuffix(filepath.Base(path), filepath.Ext(path))
}

return TestSuite{
Path: dir,
Expand Down