Add tests

This commit is contained in:
vlo
2026-11-22 20:13:40 +01:00
parent 7ef531e720
commit 3f17c820e8
2 changed files with 40 additions and 2 deletions
+15 -2
View File
@@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void {
translate_c.linkSystemLibrary("XFixes", .{}); translate_c.linkSystemLibrary("XFixes", .{});
translate_c.linkSystemLibrary("Xext", .{}); translate_c.linkSystemLibrary("Xext", .{});
const window = b.addModule("root", .{ const zwindow = b.addModule("root", .{
.root_source_file = b.path("src/Window.zig"), .root_source_file = b.path("src/Window.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
@@ -27,5 +27,18 @@ pub fn build(b: *std.Build) void {
.link_libc = false, .link_libc = false,
}); });
_ = window; const test_step = b.step("test", "Run tests");
const tests = b.addTest(.{
.name = "ZWindow-tests",
.root_module = b.createModule(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.root_module.addImport("ZWindow", zwindow);
test_step.dependOn(&b.addRunArtifact(tests).step);
b.installArtifact(tests);
} }
+25
View File
@@ -0,0 +1,25 @@
const std = @import("std");
const ZWindow = @import("ZWindow");
test "ZWindow" {
var window = try ZWindow.init(.{ .height = 256, .width = 256, .raw_mouse_input = false });
var running: bool = true;
while (running) {
if (window.pollEvent()) |event| {
switch (event) {
.mouse_motion => {
std.debug.print("mouse_motion {d} {d}\n", .{ event.mouse_motion.x, event.mouse_motion.y });
},
.key_down => {
std.debug.print("key_down {d}\n", .{event.key_down.scancode});
},
.key_up => {
std.debug.print("key_up {d}\n", .{event.key_up.scancode});
},
.window_close => running = false,
else => {},
}
}
}
}