summaryrefslogtreecommitdiff
path: root/test/process/window.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:37:48 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (patch)
tree457f82861e13ae95ab8d46ab04db93bcc0ca0e0b /test/process/window.zig
parent174e031985db910b4907ba324d6fd12c67898a5a (diff)
downloadpardes-4c4b9bf54d77dbc0f9f4e2619746908e501c6001.tar.gz
pardes-4c4b9bf54d77dbc0f9f4e2619746908e501c6001.zip
tests: the gui goldens go (test/gui-goldens.txt, the gui-golden step, window.zig's scenes case): their 15 frame hashes were this machine's; what they caught the kept set catches, checked break by break: the core's primary selection drawn as a secondary one (6 frames) fails 12 tty cases, the grip's focus fill and its button a pixel narrow (all 15) fail "every pixel of a grip column is band, button or ring", the theme's rules a pixel wider (all 15) fail "an empty column is ruled on both sides" and "decor is read from the regions"; two caught by the frames alone get unit tests of their own in gui.zig, the scrollbar thumb a pixel narrower (all 15) and the block cursor not reversed (9 frames); breaks the frames never saw (the body's clip and its context border, InactiveDim's fade, an image's scissor, fit and placed rect, the palette, the glyph art) stay the unit tests' and the image harness's or nobody's, as before
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/process/window.zig')
-rw-r--r--test/process/window.zig196
1 files changed, 4 insertions, 192 deletions
diff --git a/test/process/window.zig b/test/process/window.zig
index ea7d21d5..8d1afed8 100644
--- a/test/process/window.zig
+++ b/test/process/window.zig
@@ -1,33 +1,18 @@
-//! The window's own (T4 of docs/next-tests.md): what only its pixels and
-//! its own input show, on the hidden window `zig build process-test
-//! -Dplatform=gui` drives. test/gui_monkey.py and test/gui_golden.py, here.
+//! The window's own (T4 of docs/next-tests.md): its own input, on the
+//! hidden window `zig build process-test -Dplatform=gui` drives, settling
+//! alive. Its pixels are its unit tests' (`unit-test -Dplatform=gui`) and
+//! the image and kitty harnesses'; what the core draws, the tty cases'.
const std = @import("std");
const process = @import("../process.zig");
-extern "c" fn system(cmd: [*:0]const u8) c_int;
pub const cases = .{
.{ "window: a monkey over the effects: random clicks, drags, wheels, keys, columns, looks and themes, then it settles, alive, with no crash record", monkey },
- .{ "window: its scenes are the frames test/gui-goldens.txt hashes (PARDES_GUI_GOLDEN=check|update, this machine's)", goldens },
};
fn envOr(name: [*:0]const u8, default: []const u8) []const u8 {
return if (std.c.getenv(name)) |v| std.mem.span(v) else default;
}
-/// The serial of the first pane whose tag holds `word`, waited for.
-fn paneWith(f: *process.Files, word: []const u8) !u32 {
- const deadline = process.nowMs() + 10_000;
- while (process.nowMs() < deadline) : (process.nap(50)) {
- var rows = std.mem.tokenizeScalar(u8, try f.read("/index"), '\n');
- while (rows.next()) |row| {
- const serial = std.fmt.parseInt(u32, row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse continue], 10) catch continue;
- if (process.has(try f.read(f.at("/pane/{d}/tag", .{serial})), word)) return serial;
- }
- }
- std.debug.print("no pane's tag holds {s}\n", .{word});
- return error.NoSuchPane;
-}
-
const themes = [_][]const u8{ "lapis", "forge", "acme", "dusk", "daybreak" };
/// test/gui_monkey.py's: random bursts, each run then settling with its
@@ -172,176 +157,3 @@ fn firstPane(f: *process.Files) !?u32 {
const end = std.mem.indexOfScalar(u8, index, ' ') orelse return null;
return std.fmt.parseInt(u32, index[0..end], 10) catch null;
}
-
-/// test/gui_golden.py's scenes, each frame's sha256 against
-/// test/gui-goldens.txt: an exact gate for one machine (a GPU, a driver,
-/// software rendering here draw their own pixels), never a CI one, so it
-/// runs only when asked: PARDES_GUI_GOLDEN=check, or =update to rewrite the
-/// goldens; PARDES_GUI_GOLDEN_KEEP=<dir> keeps each frame as <scene>.ppm.
-/// The root is fixed: its paths are drawn in the tags.
-fn goldens(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
- try process.only(.gui);
- const mode = envOr("PARDES_GUI_GOLDEN", "");
- if (!std.mem.eql(u8, mode, "check") and !std.mem.eql(u8, mode, "update")) return error.SkipZigTest;
- var arena = std.heap.ArenaAllocator.init(gpa);
- defer arena.deinit();
- const a = arena.allocator();
- const root = "/tmp/pardes-gui-golden";
- _ = system("rm -rf -- /tmp/pardes-gui-golden");
- if (std.c.mkdir(root, 0o700) != 0) return error.NoRoot;
- defer _ = system("rm -rf -- /tmp/pardes-gui-golden");
- var zig: std.ArrayList(u8) = .empty;
- try zig.appendSlice(a,
- \\const std = @import("std");
- \\
- \\pub const Shape = union(enum) {
- \\ circle: f32,
- \\ square: f32,
- \\
- \\ pub fn area(shape: Shape) f32 {
- \\ return switch (shape) {
- \\ .circle => |r| std.math.pi * r * r,
- \\ .square => |s| s * s,
- \\ };
- \\ }
- \\};
- \\
- \\pub fn main() void {
- \\ var total: f32 = 0;
- \\ const shapes = [_]Shape{ .{ .circle = 1 }, .{ .square = 2 } };
- \\ for (shapes) |shape| {
- \\
- );
- for (0..60) |n| try zig.print(a, " total += shape.area() * {d}; // line {d}\n", .{ n, n });
- try zig.appendSlice(a, " }\n std.debug.print(\"{d}\\n\", .{total});\n}\n");
- try process.writeFile(a, root ++ "/shapes.zig", zig.items);
- var notes: std.ArrayList(u8) = .empty;
- for (0..4) |_| try notes.appendSlice(a, "Pardes GUI golden\n\nA second document, opened by Look.\n");
- try process.writeFile(a, root ++ "/notes.txt", notes.items);
- // One of the two alignments puts a wide glyph across the body's right edge.
- var wide: std.ArrayList(u8) = .empty;
- try wide.append(a, 'x');
- for (0..80) |_| try wide.appendSlice(a, "\u{754c}");
- try wide.append(a, '\n');
- for (0..80) |_| try wide.appendSlice(a, "\u{754c}");
- try wide.append(a, '\n');
- try process.writeFile(a, root ++ "/wide.txt", wide.items);
- var ppm: std.ArrayList(u8) = .empty;
- try ppm.print(a, "P6\n{d} {d}\n255\n", .{ 96, 64 });
- for (0..64) |yy| for (0..96) |xx| try ppm.appendSlice(a, &.{ @intCast(xx * 255 / 96), @intCast(yy * 255 / 64), 128 });
- try process.writeFile(a, root ++ "/ramp.ppm", ppm.items);
-
- var d = try process.Detached.start(gpa, exe, "gui-golden", .{
- .root = root,
- .file = root ++ "/shapes.zig",
- .init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\n",
- // The virtual clock: the same frames on any machine.
- .grid = .{ 120, 40 },
- .env = &.{ .{ "PARDES_TEST_CLOCK", "1" }, .{ "PARDES_TEST_PAD", "7" } },
- });
- defer d.deinit();
- const f = &d.files;
- var results: std.ArrayList(u8) = .empty;
- const keep = std.c.getenv("PARDES_GUI_GOLDEN_KEEP");
- const Scene = struct {
- fn shot(dd: *process.Detached, al: std.mem.Allocator, out: *std.ArrayList(u8), kept: ?[*:0]const u8, label: []const u8, file: []const u8) !void {
- const bytes = try dd.capture(al, file);
- var digest: [32]u8 = undefined;
- std.crypto.hash.sha2.Sha256.hash(bytes, &digest, .{});
- try out.print(al, "{s} {x}\n", .{ label, digest });
- if (kept) |dir| try process.writeFile(al, try std.fmt.allocPrint(al, "{s}/{s}.ppm", .{ std.mem.span(dir), label }), bytes);
- std.debug.print("{s} {x}\n", .{ label, digest[0..8] });
- }
- };
- const shot = Scene.shot;
- const first = try paneWith(f, "shapes.zig");
- try shot(&d, a, &results, keep, "01-boot", "latest.ppm");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/notes.txt\n");
- const notes_pane = try paneWith(f, "notes.txt");
- try shot(&d, a, &results, keep, "02-second-document", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{first}), "Msg a golden notice\n");
- try shot(&d, a, &results, keep, "03-notice", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{first}), "TreeContext\n");
- try f.write(f.at("/pane/{d}/dot", .{first}), "45\n");
- try shot(&d, a, &results, keep, "04-context-rows-mid-thumb", "latest.ppm");
- try f.write(f.at("/pane/{d}/dot", .{first}), "40,43\n");
- try shot(&d, a, &results, keep, "05-body-selection", "latest.ppm");
- // A press and a drag along the source's tag: the tag takes the keyboard
- // with a selection and a caret. The pointer then rests on empty body
- // space, far right.
- for ([_]struct { []const u8, i32, u32, u32 }{ .{ "down", 1, 500, 87 }, .{ "motion", 1, 620, 87 }, .{ "up", 1, 620, 87 }, .{ "motion", 0, 1880, 1300 } }) |ev| {
- try d.mouse(ev[0], ev[1], ev[2], ev[3]);
- process.nap(100);
- }
- try shot(&d, a, &results, keep, "06-tag-focus-selection", "latest.ppm");
- try d.typeKeys("\x1b");
- process.nap(200);
- const scratch = try f.newPane();
- try f.write(f.at("/pane/{d}/exec", .{scratch}), "Save\n");
- try shot(&d, a, &results, keep, "07-prompt-notice", "latest.ppm");
- try d.typeKeys("\x1b");
- process.nap(200);
- try f.write(f.at("/pane/{d}/exec", .{scratch}), "Del\n");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/wide.txt\n");
- const wide_pane = try paneWith(f, "wide.txt");
- var name: std.ArrayList(u8) = .empty;
- try name.append(a, 'x');
- for (0..70) |_| try name.appendSlice(a, "\u{754c}");
- try name.append(a, '\n');
- try f.write(f.at("/pane/{d}/name", .{wide_pane}), name.items);
- try f.write("/ctl", "Wrap off\n");
- try shot(&d, a, &results, keep, "08-wide-glyph-edges", "latest.ppm");
- try f.write("/ctl", "Wrap on\n");
- try f.write(f.at("/pane/{d}/exec", .{wide_pane}), "Del\n");
- try f.write(f.at("/pane/{d}/ctl", .{notes_pane}), "Collapse\n");
- try shot(&d, a, &results, keep, "09-collapsed-focus-tint", "latest.ppm");
- try f.write(f.at("/pane/{d}/ctl", .{notes_pane}), "Collapse\n");
- try f.write(f.at("/pane/{d}/tag", .{first}), " Second\nthird line of the tag");
- try shot(&d, a, &results, keep, "12-multiline-tag", "latest.ppm");
- try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/ramp.ppm\n");
- _ = try paneWith(f, "ramp.ppm");
- try shot(&d, a, &results, keep, "13-image", "latest.ppm");
- try f.write("/ctl", "Theme ink\n");
- try shot(&d, a, &results, keep, "14-theme-ink", "latest.ppm");
- try f.write("/ctl", "Theme acme\n");
- try shot(&d, a, &results, keep, "15-theme-acme-light", "latest.ppm");
- try f.write("/ctl", "Debug\n");
- try shot(&d, a, &results, keep, "16-debug", "latest.ppm");
- try f.write("/ctl", "Debug\n");
- // A terminal pane: raw rows, ANSI colours, a hidden prompt.
- const before = try f.read("/index");
- try f.write(f.at("/pane/{d}/exec", .{first}), "Term\n");
- const terminal = blk: {
- const deadline = process.nowMs() + 10_000;
- while (process.nowMs() < deadline) : (process.nap(50)) {
- var rows = std.mem.tokenizeScalar(u8, try f.read("/index"), '\n');
- while (rows.next()) |row| {
- const head = row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse continue];
- if (std.mem.indexOf(u8, before, f.at("{s} ", .{head})) == null) break :blk try std.fmt.parseInt(u32, head, 10);
- }
- }
- return error.NoTerminal;
- };
- try f.write(f.at("/pane/{d}/pty/data", .{terminal}), "PS1='$ '; clear; printf '\\033[1;36mcolour\\033[0m plain \\033[32mgreen\\033[0m\\n'\r");
- {
- const deadline = process.nowMs() + 10_000;
- while (!process.has(try f.read(f.at("/pane/{d}/body", .{terminal})), "green")) : (process.nap(50))
- if (process.nowMs() > deadline) return error.NoTerminalOutput;
- }
- try shot(&d, a, &results, keep, "17-terminal", "latest.ppm");
-
- const goldens_path = "test/gui-goldens.txt";
- if (std.mem.eql(u8, mode, "update")) {
- try process.writeFile(a, goldens_path, results.items);
- std.debug.print("updated {s}\n", .{goldens_path});
- return;
- }
- const want = try process.readWhole(a, goldens_path);
- var bad: usize = 0;
- var got = std.mem.tokenizeScalar(u8, results.items, '\n');
- while (got.next()) |line| if (std.mem.indexOf(u8, want, line) == null) {
- bad += 1;
- std.debug.print("frame changed: {s}\n", .{line[0..std.mem.indexOfScalar(u8, line, ' ').?]});
- };
- if (bad > 0) return error.FramesChanged;
-}