mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
24de156592
Now that the tests run again, it turns out that they actually fail, so fix them.
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
//go:build windows
|
|
// +build windows
|
|
|
|
package oscommands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cli/safeexec"
|
|
"github.com/go-errors/errors"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// handling this in a separate file because str.ToArgv has different behaviour if we're on windows
|
|
|
|
func TestOSCommandOpenFileWindows(t *testing.T) {
|
|
type scenario struct {
|
|
filename string
|
|
runner *FakeCmdObjRunner
|
|
test func(error)
|
|
}
|
|
|
|
fullCmdPath, _ := safeexec.LookPath("cmd")
|
|
|
|
scenarios := []scenario{
|
|
{
|
|
filename: "test",
|
|
runner: NewFakeRunner(t).
|
|
ExpectArgs([]string{fullCmdPath, "/c", "start", "", "test"}, "", errors.New("error")),
|
|
test: func(err error) {
|
|
assert.Error(t, err)
|
|
},
|
|
},
|
|
{
|
|
filename: "test",
|
|
runner: NewFakeRunner(t).
|
|
ExpectArgs([]string{fullCmdPath, "/c", "start", "", "test"}, "", nil),
|
|
test: func(err error) {
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
{
|
|
filename: "filename with spaces",
|
|
runner: NewFakeRunner(t).
|
|
ExpectArgs([]string{fullCmdPath, "/c", "start", "", "filename with spaces"}, "", nil),
|
|
test: func(err error) {
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
{
|
|
filename: "let's_test_with_single_quote",
|
|
runner: NewFakeRunner(t).
|
|
ExpectArgs([]string{fullCmdPath, "/c", "start", "", "let's_test_with_single_quote"}, "", nil),
|
|
test: func(err error) {
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
{
|
|
filename: "$USER.txt",
|
|
runner: NewFakeRunner(t).
|
|
ExpectArgs([]string{fullCmdPath, "/c", "start", "", "$USER.txt"}, "", nil),
|
|
test: func(err error) {
|
|
assert.NoError(t, err)
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, s := range scenarios {
|
|
oSCmd := NewDummyOSCommandWithRunner(s.runner)
|
|
platform := &Platform{
|
|
OS: "windows",
|
|
Shell: "cmd",
|
|
ShellArg: "/c",
|
|
}
|
|
oSCmd.Platform = platform
|
|
oSCmd.Cmd.platform = platform
|
|
oSCmd.UserConfig.OS.OpenCommand = `start "" {{filename}}`
|
|
|
|
s.test(oSCmd.OpenFile(s.filename))
|
|
}
|
|
}
|