diff options
Diffstat (limited to 'e2e_harness.zig')
| -rw-r--r-- | e2e_harness.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/e2e_harness.zig b/e2e_harness.zig index 8b795705..cd4ffd63 100644 --- a/e2e_harness.zig +++ b/e2e_harness.zig @@ -40,6 +40,10 @@ pub const Harness = struct { /// when true, print the captured screen state after each pump/waitFor and on /// every assertion, so live test runs can be inspected (zig build test -Dtrace). trace: bool = false, + /// every raw byte the app has emitted (accumulated in pump). Lets tests assert + /// on control sequences the emulator consumes and never renders (e.g. OSC 52 + /// clipboard writes). gpa-owned; freed in deinit. + raw: std.ArrayList(u8) = .empty, pub fn init(gpa: std.mem.Allocator, exe: [*:0]const u8, rows: u16, cols: u16) !Harness { return initArgs(gpa, exe, rows, cols, null); @@ -81,6 +85,7 @@ pub const Harness = struct { posix.kill(self.pid, posix.SIG.KILL) catch {}; _ = linux.close(self.master); self.stream.deinit(); + self.raw.deinit(self.gpa); self.term.deinit(self.gpa); self.gpa.destroy(self.term); } @@ -110,6 +115,7 @@ pub const Harness = struct { if ((fds[0].revents & posix.POLL.IN) != 0) { const n = posix.read(self.master, &buf) catch break; if (n == 0) break; + self.raw.appendSlice(self.gpa, buf[0..n]) catch {}; self.stream.nextSlice(buf[0..n]); } } @@ -159,6 +165,7 @@ pub const Harness = struct { if ((fds[0].revents & posix.POLL.IN) != 0) { const n = posix.read(self.master, &buf) catch break; if (n == 0) break; + self.raw.appendSlice(self.gpa, buf[0..n]) catch {}; self.stream.nextSlice(buf[0..n]); } const text = try self.screenText(); @@ -234,6 +241,15 @@ pub const Harness = struct { return error.ExpectFailed; } } + + /// Assert a byte sequence appears anywhere in the app's raw output so far. + /// For control sequences the emulator swallows and never renders (OSC 52 etc.). + pub fn expectRawContains(self: *Harness, needle: []const u8, msg: []const u8) !void { + if (std.mem.indexOf(u8, self.raw.items, needle) == null) { + std.debug.print("E2E FAIL: {s}\n(raw output has no {any})\n", .{ msg, needle }); + return error.ExpectFailed; + } + } }; /// Write a file (helper for test setup, raw linux syscalls). |
