Skip to content

Commit 2053491

Browse files
committed
Add tests for setup shell integration features
1 parent f0a83f8 commit 2053491

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/termio/shell_integration.zig

+31
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,37 @@ pub fn setup_features(
147147
if (!features.title) try env.put("GHOSTTY_SHELL_INTEGRATION_NO_TITLE", "1");
148148
}
149149

150+
test "setup_features" {
151+
const testing = std.testing;
152+
153+
var arena = ArenaAllocator.init(testing.allocator);
154+
defer arena.deinit();
155+
const alloc = arena.allocator();
156+
157+
var env = EnvMap.init(alloc);
158+
defer env.deinit();
159+
160+
// Test: all features enabled (no environment variables should be set)
161+
try setup_features(&env, .{ .cursor = true, .sudo = true, .title = true });
162+
try testing.expect(env.get("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR") == null);
163+
try testing.expect(env.get("GHOSTTY_SHELL_INTEGRATION_NO_SUDO") == null);
164+
try testing.expect(env.get("GHOSTTY_SHELL_INTEGRATION_NO_TITLE") == null);
165+
166+
// Test: all features disabled
167+
try setup_features(&env, .{ .cursor = false, .sudo = false, .title = false });
168+
try testing.expectEqualStrings("1", env.get("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR").?);
169+
try testing.expectEqualStrings("1", env.get("GHOSTTY_SHELL_INTEGRATION_NO_SUDO").?);
170+
try testing.expectEqualStrings("1", env.get("GHOSTTY_SHELL_INTEGRATION_NO_TITLE").?);
171+
172+
// Test: mixed features
173+
env.deinit();
174+
env = EnvMap.init(alloc);
175+
try setup_features(&env, .{ .cursor = false, .sudo = true, .title = false });
176+
try testing.expectEqualStrings("1", env.get("GHOSTTY_SHELL_INTEGRATION_NO_CURSOR").?);
177+
try testing.expect(env.get("GHOSTTY_SHELL_INTEGRATION_NO_SUDO") == null);
178+
try testing.expectEqualStrings("1", env.get("GHOSTTY_SHELL_INTEGRATION_NO_TITLE").?);
179+
}
180+
150181
/// Setup the bash automatic shell integration. This works by
151182
/// starting bash in POSIX mode and using the ENV environment
152183
/// variable to load our bash integration script. This prevents

0 commit comments

Comments
 (0)