package tools import "testing" // The Windows half of the shell choice, testable on every platform because it // is arithmetic on strings. The exec.Cmd it feeds is compiled with GOOS=windows // and has never been run by this project's authors — see README.md. func TestWindowsShellIsComspecOrCmd(t *testing.T) { if got := windowsShell(`C:\Windows\system32\cmd.exe`); got != `C:\Windows\system32\cmd.exe` { t.Errorf("windowsShell(COMSPEC) = %q, want COMSPEC itself", got) } if got := windowsShell(""); got != "cmd.exe" { t.Errorf("windowsShell(\"\") = %q, want cmd.exe", got) } } func TestCmdExeGetsTheCommandVerbatimInsideOnePairOfQuotes(t *testing.T) { // cmd.exe /S /C strips the first and last quote and parses the rest by its // own rules, so a quote inside the command must reach it as a quote and // not as the C runtime's \". got := cmdExeCommandLine(`C:\Windows\system32\cmd.exe`, `echo "hello world" && go test ./...`) want := `"C:\Windows\system32\cmd.exe" /S /C "echo "hello world" && go test ./..."` if got != want { t.Errorf("cmdExeCommandLine() = %s, want %s", got, want) } } func TestTheShellRunsOneCommandLineAndExits(t *testing.T) { // Whatever the platform, the arguments end with the command itself, which // is what lets the terminal package compose the line. args := ShellArgs("go test ./...") if len(args) < 2 || args[len(args)-1] != "go test ./..." { t.Errorf("ShellArgs() = %q, want the command as the last argument after the shell's switch", args) } if Shell() == "" { t.Error("Shell() is empty") } }