mirror of
https://github.com/lima-vm/lima.git
synced 2026-10-28 11:44:35 +08:00
Parse editor commands with shellwords while preserving standalone paths, and add Windows path tests. Signed-off-by: deltron-fr <kayceoogbonnaya2304@gmail.com>
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
// SPDX-FileCopyrightText: Copyright The Lima Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//go:build windows
|
|
|
|
package editorcmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestDetectWindowsPath(t *testing.T) {
|
|
editorPath := makeWindowsEditor(t)
|
|
t.Setenv("VISUAL", "")
|
|
t.Setenv("EDITOR", editorPath)
|
|
|
|
path, args := Detect()
|
|
|
|
assert.Equal(t, path, editorPath)
|
|
assert.Equal(t, len(args), 0)
|
|
}
|
|
|
|
func TestDetectWindowsPathWithArguments(t *testing.T) {
|
|
editorPath := makeWindowsEditor(t)
|
|
t.Setenv("VISUAL", "")
|
|
t.Setenv("EDITOR", fmt.Sprintf(`'%s' --wait`, editorPath))
|
|
|
|
path, args := Detect()
|
|
|
|
assert.Equal(t, path, editorPath)
|
|
assert.DeepEqual(t, args, []string{"--wait"})
|
|
}
|
|
|
|
func makeWindowsEditor(t *testing.T) string {
|
|
t.Helper()
|
|
|
|
editorDir := filepath.Join(t.TempDir(), "editor with spaces")
|
|
assert.NilError(t, os.Mkdir(editorDir, 0o755))
|
|
editorPath := filepath.Join(editorDir, "editor.exe")
|
|
assert.NilError(t, os.WriteFile(editorPath, nil, 0o755))
|
|
return editorPath
|
|
}
|