refactor: strip .exe from shell names

This commit is contained in:
Jan De Dobbeleer 2020-09-20 19:13:37 +02:00 committed by Jan De Dobbeleer
parent 401c5b3265
commit 2603ff51bf
2 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,7 @@
package main
import "strings"
type shell struct {
props *properties
env environmentInfo
@ -15,7 +17,8 @@ func (s *shell) string() string {
if err != nil {
return "unknown"
}
return p.Executable()
shell := strings.Replace(p.Executable(), ".exe", "", 1)
return shell
}
func (s *shell) init(props *properties, env environmentInfo) {

View file

@ -42,7 +42,22 @@ func TestWriteCurrentShell(t *testing.T) {
env: env,
props: props,
}
assert.Equal(t, "zsh", s.string())
assert.Equal(t, expected, s.string())
}
func TestWriteCurrentShellWindowsExe(t *testing.T) {
expected := "pwsh"
env := new(MockedEnvironment)
process := new(process)
parentProcess := expected + ".exe"
process.On("Executable", nil).Return(parentProcess)
env.On("getParentProcess", nil).Return(process, nil)
props := &properties{}
s := &shell{
env: env,
props: props,
}
assert.Equal(t, expected, s.string())
}
func TestWriteCurrentShellError(t *testing.T) {