diff options
Diffstat (limited to 'test/e2e_harness.zig')
| -rw-r--r-- | test/e2e_harness.zig | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig index 6f2f5ef1..e08e59f2 100644 --- a/test/e2e_harness.zig +++ b/test/e2e_harness.zig @@ -261,6 +261,26 @@ pub const Harness = struct { if (self.trace) self.traceScreen("waitFor miss"); return false; } + + /// Wait up to `ms` for `needle` to appear in the app's RAW output, pumping + /// bytes the whole time. Same shape as `waitFor`, against `raw` rather than + /// the grid: for control sequences the emulator swallows and never renders. + pub fn waitForRaw(self: *Harness, needle: []const u8, ms: i64) bool { + if (std.mem.indexOf(u8, self.raw.items, needle) != null) return true; + const deadline = nowMs() + ms; + var buf: [4096]u8 = undefined; + while (nowMs() < deadline) { + var fds = [_]posix.pollfd{.{ .fd = self.master, .events = posix.POLL.IN, .revents = 0 }}; + _ = posix.poll(&fds, 50) catch {}; + if ((fds[0].revents & posix.POLL.IN) == 0) continue; + const n = posix.read(self.master, &buf) catch break; + if (n == 0) break; + self.recordRaw(buf[0..n]); + self.stream.nextSlice(buf[0..n]); + if (std.mem.indexOf(u8, self.raw.items, needle) != null) return true; + } + return false; + } fn recordRaw(self: *Harness, bytes: []const u8) void { self.raw.appendSlice(bytes) catch |err| switch (err) { error.CaptureFull => {}, @@ -338,6 +358,17 @@ pub const Harness = struct { return error.ExpectFailed; } } + + /// Assert a byte sequence appears in the app's raw output, waiting for it. + /// A fixed `pump` before `expectRawContains` budgets a STARTUP instead of + /// waiting for an answer, and a cold 70 MB Debug binary on a loaded machine + /// overruns any such budget. + pub fn expectRawWaitFor(self: *Harness, needle: []const u8, ms: i64, msg: []const u8) !void { + if (!self.waitForRaw(needle, ms)) { + 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 libc). |
