From e6d3a6f9faa0b762d91db93916a4c64b3835fc95 Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Thu, 19 Sep 2024 18:43:28 -0500 Subject: [PATCH 1/7] encapsulate paths with quotes to escape spaces --- runner/config.go | 11 ++++++---- runner/config_test.go | 51 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/runner/config.go b/runner/config.go index 78a4eaa5..afe354c0 100644 --- a/runner/config.go +++ b/runner/config.go @@ -9,6 +9,7 @@ import ( "reflect" "regexp" "runtime" + "strings" "time" "dario.cat/mergo" @@ -305,9 +306,7 @@ func (c *Config) preprocess() error { if c.TestDataDir == "" { c.TestDataDir = "testdata" } - if err != nil { - return err - } + ed := c.Build.ExcludeDir for i := range ed { ed[i] = cleanPath(ed[i]) @@ -328,6 +327,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) + return err } @@ -363,7 +365,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 { diff --git a/runner/config_test.go b/runner/config_test.go index 97a1bd2a..75a91825 100644 --- a/runner/config_test.go +++ b/runner/config_test.go @@ -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) + } } } From 6f6391d5ebe606ed0165f3289abd3fd822a7366d Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Thu, 19 Sep 2024 18:43:28 -0500 Subject: [PATCH 2/7] encapsulate paths with quotes to escape spaces --- runner/config.go | 11 ++++++---- runner/config_test.go | 51 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/runner/config.go b/runner/config.go index 78a4eaa5..afe354c0 100644 --- a/runner/config.go +++ b/runner/config.go @@ -9,6 +9,7 @@ import ( "reflect" "regexp" "runtime" + "strings" "time" "dario.cat/mergo" @@ -305,9 +306,7 @@ func (c *Config) preprocess() error { if c.TestDataDir == "" { c.TestDataDir = "testdata" } - if err != nil { - return err - } + ed := c.Build.ExcludeDir for i := range ed { ed[i] = cleanPath(ed[i]) @@ -328,6 +327,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) + return err } @@ -363,7 +365,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 { diff --git a/runner/config_test.go b/runner/config_test.go index 97a1bd2a..75a91825 100644 --- a/runner/config_test.go +++ b/runner/config_test.go @@ -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) + } } } From 8572333a67bf59765cffb02c9358995cc54656cb Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Sun, 22 Sep 2024 14:47:53 -0500 Subject: [PATCH 3/7] preprocess error in test --- runner/engine_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runner/engine_test.go b/runner/engine_test.go index df181902..f416e119 100644 --- a/runner/engine_test.go +++ b/runner/engine_test.go @@ -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() }() From 9e0ce8dbb70ed5b52e44973bd1b0fc3892a0f958 Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Tue, 15 Oct 2024 14:33:52 -0500 Subject: [PATCH 4/7] alt escape for windows --- runner/config.go | 6 +++--- runner/config_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runner/config.go b/runner/config.go index 8aa4c91f..01dea156 100644 --- a/runner/config.go +++ b/runner/config.go @@ -330,7 +330,7 @@ func (c *Config) preprocess() error { c.Build.Bin, err = filepath.Abs(c.Build.Bin) // Account for spaces in filepath - c.Build.Bin = fmt.Sprintf("%q", c.Build.Bin) + // c.Build.Bin = fmt.Sprintf("'%s'", c.Build.Bin) return err } @@ -367,8 +367,8 @@ func (c *Config) killDelay() time.Duration { } func (c *Config) binPath() string { - bin := strings.Trim(c.Build.Bin, "\"") - return fmt.Sprintf("%q", filepath.Join(c.Root, bin)) + bin := strings.Trim(c.Build.Bin, "'") + return fmt.Sprintf("'%s'", filepath.Join(c.Root, bin)) } func (c *Config) tmpPath() string { diff --git a/runner/config_test.go b/runner/config_test.go index 75a91825..de853e0a 100644 --- a/runner/config_test.go +++ b/runner/config_test.go @@ -125,12 +125,12 @@ func TestConfPreprocess(t *testing.T) { { name: "no spaces", space: false, - suffix: "/_testdata/toml/tmp/main\"", + suffix: "/_testdata/toml/tmp/main'", }, { name: "with spaces", space: true, - suffix: "/_testdata/toml/tmp space/main\"", + suffix: "/_testdata/toml/tmp space/main'", }, } @@ -153,7 +153,7 @@ func TestConfPreprocess(t *testing.T) { 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) + t.Fatalf("%s: bin path is %q, but not have suffix %q", tt.name, binPath, tt.suffix) } err = os.Chdir(oWD) From 08f015f2f97c9dd49e9290a0345d6501ecc0d894 Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Tue, 15 Oct 2024 14:47:34 -0500 Subject: [PATCH 5/7] works on linux --- runner/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/config.go b/runner/config.go index 01dea156..57cf6962 100644 --- a/runner/config.go +++ b/runner/config.go @@ -330,7 +330,7 @@ func (c *Config) preprocess() error { c.Build.Bin, err = filepath.Abs(c.Build.Bin) // Account for spaces in filepath - // c.Build.Bin = fmt.Sprintf("'%s'", c.Build.Bin) + c.Build.Bin = fmt.Sprintf("'%s'", c.Build.Bin) return err } From a0e05c596499b108af695bee9bf82bee72f67e70 Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Tue, 15 Oct 2024 16:15:20 -0500 Subject: [PATCH 6/7] exclude windows --- runner/config.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/runner/config.go b/runner/config.go index 57cf6962..35154b75 100644 --- a/runner/config.go +++ b/runner/config.go @@ -330,8 +330,9 @@ func (c *Config) preprocess() error { c.Build.Bin, err = filepath.Abs(c.Build.Bin) // Account for spaces in filepath - c.Build.Bin = fmt.Sprintf("'%s'", c.Build.Bin) - + if runtime.GOOS != "windows" { + c.Build.Bin = fmt.Sprintf("'%s'", c.Build.Bin) + } return err } @@ -367,8 +368,13 @@ func (c *Config) killDelay() time.Duration { } func (c *Config) binPath() string { - bin := strings.Trim(c.Build.Bin, "'") - return fmt.Sprintf("'%s'", filepath.Join(c.Root, bin)) + + if runtime.GOOS != "windows" { + bin := strings.Trim(c.Build.Bin, "'") + return fmt.Sprintf("'%s'", filepath.Join(c.Root, bin)) + } + + return filepath.Join(c.Root, c.Build.Bin) } func (c *Config) tmpPath() string { From 40febc1b92afdbfffd85e98e0bc306555f35fef2 Mon Sep 17 00:00:00 2001 From: Scott Osteen Date: Tue, 15 Oct 2024 16:23:27 -0500 Subject: [PATCH 7/7] typo fixed --- runner/engine_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/engine_test.go b/runner/engine_test.go index f416e119..f7204cee 100644 --- a/runner/engine_test.go +++ b/runner/engine_test.go @@ -723,7 +723,7 @@ func TestRebuildWhenRunCmdUsingDLV(t *testing.T) { engine.config.Build.FullBin = fmt.Sprintf("dlv exec --accept-multiclient --log --headless --continue --listen :%d --api-version 2 ./tmp/main", dlvPort) err = engine.config.preprocess() if err != nil { - t.Fatal("config preprocess fialed! - Error: ", err) + t.Fatal("config preprocess failed! - Error: ", err) } go func() { engine.Run()