MCPcopy
hub / github.com/cheat/cheat / TestEditor

Function TestEditor

internal/config/editor_test.go:10–95  ·  view source on GitHub ↗

TestEditor tests the Editor function

(t *testing.T)

Source from the content-addressed store, hash-verified

8
9// TestEditor tests the Editor function
10func TestEditor(t *testing.T) {
11 // Save original env vars
12 oldVisual := os.Getenv("VISUAL")
13 oldEditor := os.Getenv("EDITOR")
14 defer func() {
15 os.Setenv("VISUAL", oldVisual)
16 os.Setenv("EDITOR", oldEditor)
17 }()
18
19 t.Run("windows default", func(t *testing.T) {
20 if runtime.GOOS != "windows" {
21 t.Skip("skipping windows test on non-windows platform")
22 }
23
24 // Clear env vars
25 os.Setenv("VISUAL", "")
26 os.Setenv("EDITOR", "")
27
28 editor, err := Editor()
29 if err != nil {
30 t.Errorf("unexpected error: %v", err)
31 }
32 if editor != "notepad" {
33 t.Errorf("expected 'notepad' on windows, got %s", editor)
34 }
35 })
36
37 t.Run("VISUAL takes precedence", func(t *testing.T) {
38 if runtime.GOOS == "windows" {
39 t.Skip("skipping non-windows test on windows platform")
40 }
41
42 os.Setenv("VISUAL", "emacs")
43 os.Setenv("EDITOR", "nano")
44
45 editor, err := Editor()
46 if err != nil {
47 t.Errorf("unexpected error: %v", err)
48 }
49 if editor != "emacs" {
50 t.Errorf("expected VISUAL to take precedence, got %s", editor)
51 }
52 })
53
54 t.Run("EDITOR when no VISUAL", func(t *testing.T) {
55 if runtime.GOOS == "windows" {
56 t.Skip("skipping non-windows test on windows platform")
57 }
58
59 os.Setenv("VISUAL", "")
60 os.Setenv("EDITOR", "vim")
61
62 editor, err := Editor()
63 if err != nil {
64 t.Errorf("unexpected error: %v", err)
65 }
66 if editor != "vim" {
67 t.Errorf("expected EDITOR value, got %s", editor)

Callers

nothing calls this directly

Calls 1

EditorFunction · 0.85

Tested by

no test coverage detected