@@ -75,25 +75,23 @@ func TestGetShell_defaults(t *testing.T) {
7575}
7676
7777func 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 }
0 commit comments