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: Support working directories containing whitespace #646

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"regexp"
"runtime"
"strings"
"time"

"dario.cat/mergo"
Expand Down Expand Up @@ -307,6 +308,7 @@ func (c *Config) preprocess() error {
if c.TestDataDir == "" {
c.TestDataDir = "testdata"
}

ed := c.Build.ExcludeDir
for i := range ed {
ed[i] = cleanPath(ed[i])
Expand All @@ -327,6 +329,9 @@ func (c *Config) preprocess() error {
// CMD will not recognize relative path like ./tmp/server
c.Build.Bin, err = filepath.Abs(c.Build.Bin)

// Account for spaces in filepath
c.Build.Bin = fmt.Sprintf("%q", c.Build.Bin)

Choose a reason for hiding this comment

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

I think this is causing an error on Windows, the exe can't be found and the path includes escape characters like this:

'\"c:\\go\\hello\\tmp\\hello.exe\"' is not recognized as an internal or external command,
operable program or batch file.

When if it was actually missing the error would be: this when the exe is missing and I run it from a command prompt

'c:\go\hello\tmp\hello.exe' is not recognized as an internal or external command,
operable program or batch file.


return err
}

Expand Down Expand Up @@ -362,7 +367,8 @@ func (c *Config) killDelay() time.Duration {
}

func (c *Config) binPath() string {
return filepath.Join(c.Root, c.Build.Bin)
bin := strings.Trim(c.Build.Bin, "\"")
return fmt.Sprintf("%q", filepath.Join(c.Root, bin))
}

func (c *Config) tmpPath() string {
Expand Down
51 changes: 42 additions & 9 deletions runner/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,49 @@ func TestReadConfByName(t *testing.T) {
}

func TestConfPreprocess(t *testing.T) {
t.Setenv(airWd, "_testdata/toml")
df := defaultConfig()
err := df.preprocess()
if err != nil {
t.Fatalf("preprocess error %v", err)
tests := []struct {
name string
space bool
suffix string
}{
{
name: "no spaces",
space: false,
suffix: "/_testdata/toml/tmp/main\"",
},
{
name: "with spaces",
space: true,
suffix: "/_testdata/toml/tmp space/main\"",
},
}
suffix := "/_testdata/toml/tmp/main"
binPath := df.Build.Bin
if !strings.HasSuffix(binPath, suffix) {
t.Fatalf("bin path is %s, but not have suffix %s.", binPath, suffix)

for _, tt := range tests {

oWD, err := os.Getwd()
if err != nil {
t.Fatalf("failed to get currWD: %v", err)
}

t.Setenv(airWd, "_testdata/toml")
df := defaultConfig()
if tt.space {
df.Build.Bin = "./tmp space/main"
}
err = df.preprocess()
if err != nil {
t.Fatalf("%s: preprocess error %v", tt.name, err)
}

binPath := df.Build.Bin
if !strings.HasSuffix(binPath, tt.suffix) {
t.Fatalf("%s: bin path is %s, but not have suffix %s.", tt.name, binPath, tt.suffix)
}

err = os.Chdir(oWD)
if err != nil {
t.Fatalf("failed to change back to original WD: %v", err)
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion runner/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ func TestRebuildWhenRunCmdUsingDLV(t *testing.T) {
dlvPort, f := GetPort()
f()
engine.config.Build.FullBin = fmt.Sprintf("dlv exec --accept-multiclient --log --headless --continue --listen :%d --api-version 2 ./tmp/main", dlvPort)
_ = engine.config.preprocess()
err = engine.config.preprocess()
if err != nil {
t.Fatal("config preprocess fialed! - Error: ", err)
}
go func() {
engine.Run()
}()
Expand Down
Loading