turbo-editors/turbo-corepublic Fork 0
v1.0.2
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

🛟 Updated. 28d5985 · on v1.0.2 · k33g · 19h ago
shell_test.go · 41 lines · 1.5 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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")
	}
}