MCPcopy Create free account
hub / github.com/github/gh-aw / TestDetectShell

Function TestDetectShell

pkg/cli/shell_completion_test.go:14–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestDetectShell(t *testing.T) {
15 // Save original environment
16 originalShell := os.Getenv("SHELL")
17 originalBashVersion := os.Getenv("BASH_VERSION")
18 originalZshVersion := os.Getenv("ZSH_VERSION")
19 originalFishVersion := os.Getenv("FISH_VERSION")
20
21 // Restore environment after test
22 defer func() {
23 os.Setenv("SHELL", originalShell)
24 os.Setenv("BASH_VERSION", originalBashVersion)
25 os.Setenv("ZSH_VERSION", originalZshVersion)
26 os.Setenv("FISH_VERSION", originalFishVersion)
27 }()
28
29 tests := []struct {
30 name string
31 shellEnv string
32 bashVersion string
33 zshVersion string
34 fishVersion string
35 expectedType ShellType
36 }{
37 {
38 name: "detect bash from BASH_VERSION",
39 shellEnv: "/bin/bash",
40 bashVersion: "5.0.0",
41 zshVersion: "",
42 fishVersion: "",
43 expectedType: ShellBash,
44 },
45 {
46 name: "detect zsh from ZSH_VERSION",
47 shellEnv: "/bin/zsh",
48 bashVersion: "",
49 zshVersion: "5.8",
50 fishVersion: "",
51 expectedType: ShellZsh,
52 },
53 {
54 name: "detect fish from FISH_VERSION",
55 shellEnv: "/usr/bin/fish",
56 bashVersion: "",
57 zshVersion: "",
58 fishVersion: "3.1.2",
59 expectedType: ShellFish,
60 },
61 {
62 name: "detect bash from SHELL path",
63 shellEnv: "/bin/bash",
64 bashVersion: "",
65 zshVersion: "",
66 fishVersion: "",
67 expectedType: ShellBash,
68 },
69 {
70 name: "detect zsh from SHELL path",
71 shellEnv: "/usr/local/bin/zsh",

Callers

nothing calls this directly

Calls 4

DetectShellFunction · 0.85
GetenvMethod · 0.80
SetenvMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected