Skip to content

Commit ad0c799

Browse files
committed
fix: enhance getShell function to prioritize pwsh over powershell, update tests accordingly
1 parent 2d47ec5 commit ad0c799

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/internal/lib/task_runner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ func getShell(shell string) []string {
171171
case "/bin/zsh", "zsh":
172172
return []string{"zsh", "-c"}
173173
case "powershell", "pwsh", "ps":
174+
if _, err := exec.LookPath("pwsh"); err == nil {
175+
return []string{"pwsh", "-Command"}
176+
}
174177
return []string{"powershell", "-Command"}
175178
case "cmd":
176179
return []string{"cmd", "/c"}

src/internal/lib/task_runner_test.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,23 @@ func TestGetShell_defaults(t *testing.T) {
7575
}
7676

7777
func TestGetShell_powershell(t *testing.T) {
78-
tests := []struct {
79-
input string
80-
want []string
81-
}{
82-
{"powershell", []string{"powershell", "-Command"}},
83-
{"pwsh", []string{"powershell", "-Command"}},
84-
{"ps", []string{"powershell", "-Command"}},
78+
// The resolved binary is "pwsh" when available, "powershell" otherwise.
79+
wantBin := "powershell"
80+
if _, err := exec.LookPath("pwsh"); err == nil {
81+
wantBin = "pwsh"
8582
}
8683

87-
for _, tt := range tests {
88-
t.Run(tt.input, func(t *testing.T) {
89-
got := getShell(tt.input)
90-
if len(got) != len(tt.want) {
91-
t.Fatalf("getShell(%q) = %v, want %v", tt.input, got, tt.want)
84+
for _, input := range []string{"powershell", "pwsh", "ps"} {
85+
t.Run(input, func(t *testing.T) {
86+
got := getShell(input)
87+
if len(got) != 2 {
88+
t.Fatalf("getShell(%q) = %v, want 2-element slice", input, got)
9289
}
93-
for i := range got {
94-
if got[i] != tt.want[i] {
95-
t.Errorf("getShell(%q)[%d] = %q, want %q", tt.input, i, got[i], tt.want[i])
96-
}
90+
if got[0] != wantBin {
91+
t.Errorf("getShell(%q)[0] = %q, want %q", input, got[0], wantBin)
92+
}
93+
if got[1] != "-Command" {
94+
t.Errorf("getShell(%q)[1] = %q, want \"-Command\"", input, got[1])
9795
}
9896
})
9997
}

src/raid/raid.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var ConfigPath = &lib.CfgPath
3838
// Initialize the raid environment, including loading configurations and initializing data storage.
3939
func Initialize() {
4040
if err := lib.InitConfig(); err != nil {
41-
log.Fatalf("%v\n", err)
41+
log.Fatalf("%v", err)
4242
}
4343
if err := Load(); err != nil {
44-
log.Fatalf("%v\n", err)
44+
log.Fatalf("%v", err)
4545
}
4646
if err := lib.LoadEnv(); err != nil {
4747
fmt.Fprintf(os.Stderr, "%v\n", err)

0 commit comments

Comments
 (0)