Skip to content

Commit

Permalink
Adding the no editor unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrielVelazquez committed Feb 3, 2025
1 parent 35d7a3a commit 8da47a3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4322,7 +4322,7 @@ fn openScreenFile(
file_path: []const u8,
) !void {
const editor = std.posix.getenv("EDITOR") orelse {
std.log.err("EDITOR environment variable not set", .{});
std.log.debug("EDITOR environment variable not set", .{});
return error.EnvironmentVariableNotFound;
};
const allocator = std.heap.page_allocator;
Expand Down Expand Up @@ -4721,3 +4721,17 @@ fn presentSurface(self: *Surface) !void {
{},
);
}

test "openScreenFile - no EDITOR" {
const testing = std.testing;
const unsetenv = @import("os/env.zig").unsetenv;
const allocator = testing.allocator;

var surface = Surface{ .alloc = allocator, .size = undefined, .app = undefined, .rt_app = undefined, .rt_surface = undefined, .font_grid_key = undefined, .font_size = undefined, .font_metrics = undefined, .renderer = undefined, .renderer_state = undefined, .renderer_thr = undefined, .renderer_thread = undefined, .mouse = undefined, .keyboard = undefined, .io = undefined, .io_thr = undefined, .io_thread = undefined, .config = undefined, .config_conditional_state = undefined };
const file_path = "test.txt";

_ = unsetenv("EDITOR");

const err = surface.openScreenFile(file_path);
try testing.expectError(error.EnvironmentVariableNotFound, err);
}

0 comments on commit 8da47a3

Please sign in to comment.