cad2d783b3
release / build-web (push) Has been cancelled
release / build-bundles (aarch64-linux-gnu-gcc, arm64, linux, ubuntu-latest, linux-arm64) (push) Has been cancelled
release / build-bundles (amd64, darwin, macos-13, macos-x64) (push) Has been cancelled
release / build-bundles (amd64, linux, ubuntu-latest, linux-x64) (push) Has been cancelled
release / build-bundles (amd64, windows, windows-latest, windows-x64) (push) Has been cancelled
release / build-bundles (arm64, darwin, macos-14, macos-arm64) (push) Has been cancelled
feat: windows support
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package process
|
|
|
|
import "testing"
|
|
|
|
func TestEscapeArg(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{"empty", "", `""`},
|
|
{"simple", "hello", "hello"},
|
|
{"with space", "hello world", `"hello world"`},
|
|
{"with tab", "hello\tworld", `"hello` + "\t" + `world"`},
|
|
{"with quote", `say "hi"`, `"say \"hi\""`},
|
|
{"backslash no quote", `a\b`, `a\b`},
|
|
{"backslash before quote", `a\"`, `a\\\"` },
|
|
{"trailing backslash with space", `a b\`, `"a b\\"`},
|
|
{"multiple trailing backslashes with space", `a b\\`, `"a b\\\\"`},
|
|
{"only backslashes", `\\`, `\\`},
|
|
{"backslash then quote", `\\"`, `\\\\\"` },
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := escapeArg(tt.in)
|
|
if got != tt.want {
|
|
t.Errorf("escapeArg(%q) = %q, want %q", tt.in, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestBuildCmdLine(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
want string
|
|
}{
|
|
{"single", []string{"cmd.exe"}, "cmd.exe"},
|
|
{"simple args", []string{"git", "status"}, "git status"},
|
|
{"arg with space", []string{"C:\\Program Files\\app.exe", "-f"}, `"C:\Program Files\app.exe" -f`},
|
|
{"arg with quote", []string{"echo", `"hello"`}, `echo \"hello\"`},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := buildCmdLine(tt.args)
|
|
if got != tt.want {
|
|
t.Errorf("buildCmdLine(%v) = %q, want %q", tt.args, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|