TestDetectFromEnv verifies the TERM_PROGRAM → backend mapping. The Override knob and the ZELLIJ / kitty / FLOW_TERM checks have higher precedence and are checked separately below.
(t *testing.T)
| 63 | // Override knob and the ZELLIJ / kitty / FLOW_TERM checks have higher |
| 64 | // precedence and are checked separately below. |
| 65 | func TestDetectFromEnv(t *testing.T) { |
| 66 | cases := []struct { |
| 67 | termProgram string |
| 68 | want Backend |
| 69 | }{ |
| 70 | {"iTerm.app", BackendITerm}, |
| 71 | {"Apple_Terminal", BackendTerminal}, |
| 72 | {"WarpTerminal", BackendWarp}, |
| 73 | {"ghostty", BackendGhostty}, |
| 74 | {"", BackendITerm}, |
| 75 | {"WezTerm", BackendITerm}, |
| 76 | {"vscode", BackendITerm}, |
| 77 | } |
| 78 | for _, tc := range cases { |
| 79 | t.Run(tc.termProgram, func(t *testing.T) { |
| 80 | t.Setenv("ZELLIJ", "") |
| 81 | t.Setenv("KITTY_WINDOW_ID", "") |
| 82 | t.Setenv("TERM", "") |
| 83 | t.Setenv("FLOW_TERM", "") |
| 84 | t.Setenv("TERM_PROGRAM", tc.termProgram) |
| 85 | Override = "" |
| 86 | if got := Detect(); got != tc.want { |
| 87 | t.Errorf("Detect() with TERM_PROGRAM=%q: got %q, want %q", |
| 88 | tc.termProgram, got, tc.want) |
| 89 | } |
| 90 | }) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // TestOverrideBeatsEnv confirms the test escape hatch: setting Override |
| 95 | // pins the backend regardless of env vars, so individual tests can pin |