Avoid Start-Process errors for Windows full_bin (#872)

This commit is contained in:
xiantang
2026-01-21 22:55:51 +08:00
committed by GitHub
parent c8a381f662
commit 2ecf4acf7a
2 changed files with 50 additions and 5 deletions
-5
View File
@@ -303,8 +303,6 @@ func adaptToVariousPlatforms(c *Config) {
// Fix the default configuration is not used in Windows
// Use the unix configuration on Windows
if runtime.GOOS == PlatformWindows {
runName := "start"
extName := ".exe"
originBin := c.Build.Bin
@@ -313,9 +311,6 @@ func adaptToVariousPlatforms(c *Config) {
if !strings.HasSuffix(c.Build.FullBin, extName) {
c.Build.FullBin += extName
}
if !strings.HasPrefix(c.Build.FullBin, runName) {
c.Build.FullBin = runName + " /wait /b " + c.Build.FullBin
}
}
// bin=/tmp/main cmd=go build -o ./tmp/main.exe main.go
+50
View File
@@ -0,0 +1,50 @@
package runner
import (
"runtime"
"strings"
"testing"
)
func TestAdaptToVariousPlatformsFullBinWindows(t *testing.T) {
if runtime.GOOS != PlatformWindows {
t.Skip("windows-only behavior")
}
t.Parallel()
tests := []struct {
name string
fullBin string
expected string
}{
{
name: "exe already",
fullBin: `.\tmp\main.exe`,
expected: `.\tmp\main.exe`,
},
{
name: "append exe",
fullBin: `.\tmp\main`,
expected: `.\tmp\main.exe`,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
config := &Config{
Build: cfgBuild{
FullBin: tt.fullBin,
},
}
adaptToVariousPlatforms(config)
if config.Build.FullBin != tt.expected {
t.Fatalf("expected full_bin %q, got %q", tt.expected, config.Build.FullBin)
}
if strings.HasPrefix(strings.ToLower(config.Build.FullBin), "start ") {
t.Fatalf("unexpected start prefix in full_bin: %q", config.Build.FullBin)
}
})
}
}