summaryrefslogtreecommitdiff
path: root/core/ninep/testing.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 21:38:07 -0300
committerGabriel Schneider <[email protected]>2026-11-19 22:01:15 -0300
commitb8a6b0589ddbe65a4c80272ff44ceb77d2f0d02f (patch)
tree867467c655b0152d947515951e96591483fbb99b /core/ninep/testing.zig
parenta18b99e1e0862de4b3c8fd55e0fd816fe2dca621 (diff)
downloadpardes-b8a6b0589ddbe65a4c80272ff44ceb77d2f0d02f.tar.gz
pardes-b8a6b0589ddbe65a4c80272ff44ceb77d2f0d02f.zip
core, docs: the control tree's test harness is core/ninep/harness.zig, no longer core/ninep/testing.zig (P18, the user's ruling on the tree step's name collisions: the file's name collided with the future `core.testing`): the file moved whole in this change, so its history follows it (no line of it changed), and its 27 imports follow, nine `@import("testing.zig")` in core/ninep (addr, cols, ctl, events, pane, pty, screen, sources, tree) and 18 `@import("ninep/testing.zig")` in core (Addon, Core three, Dir, Effect, Query, dump three, edit_cmd, fs, keys, look two, mouse, sam_edit, tape), with the two design notes naming it (docs/next-tests.md, docs/next-terminal.md); the build and the root's test lists never named it; a rename only, nothing else on any line; tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds (`install -Dplatform=gui`), the macOS library for Linux and aarch64-macos and the FreeBSD cross-build rc 0, under a load of 22 to 60
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/ninep/testing.zig')
-rw-r--r--core/ninep/testing.zig168
1 files changed, 0 insertions, 168 deletions
diff --git a/core/ninep/testing.zig b/core/ninep/testing.zig
deleted file mode 100644
index cf75d80d..00000000
--- a/core/ninep/testing.zig
+++ /dev/null
@@ -1,168 +0,0 @@
-//! Test helpers shared by the control-tree modules: drive one request
-//! through the core and collect the reply and the effects it raised.
-const std = @import("std");
-const pardes = @import("../root.zig");
-const tree = @import("tree.zig");
-const cloud9 = @import("cloud9");
-
-const Pardes = pardes.Pardes;
-pub const Req = tree.Req;
-pub const Reply = tree.Reply;
-pub const E = tree.E;
-
-pub const Answer = struct {
- reply: Reply = .{ .tag = 0, .status = .err, .errno = E.IO },
- bytes: []const u8 = "",
- saved: bool = false,
- watch: ?bool = null,
- pty_buf: [256]u8 = undefined,
- pty_len: usize = 0,
- winsize: ?struct { cols: u16, rows: u16 } = null,
- signal: ?pardes.PtySignal = null,
- spawned: bool = false,
- closed: bool = false,
-
- pub fn pty(a: *const Answer) []const u8 {
- return a.pty_buf[0..a.pty_len];
- }
-
- pub fn errno(a: Answer) u16 {
- return if (a.reply.status == .err) a.reply.errno else 0;
- }
-};
-
-pub fn call(p: *Pardes, req: Req) Answer {
- var ans: Answer = .{};
- ans.reply = p.serveFs(req);
- // An EINVAL or ENOENT refusal says so in words a 9ns mount maps back
- // to it (cloud9's enameErrno), or a shell through the mount hears EIO.
- const said = ans.reply;
- if (said.status == .err and said.ename.len > 0 and (said.errno == E.INVAL or said.errno == E.NOENT) and cloud9.fs.enameErrno(said.ename) != said.errno) {
- std.debug.print("a mount reads this refusal as errno {d}, not {d}: \"{s}\"\n", .{ cloud9.fs.enameErrno(said.ename), said.errno, said.ename });
- @panic("a refusal's words do not say its errno");
- }
- ans.bytes = p.fsPayload(ans.reply);
- while (p.nextEffect()) |e| switch (e) {
- .save_file, .save_text => ans.saved = true,
- .watch => |w| ans.watch = w.on,
- .write => |w| {
- const b = w.bytes.slice();
- const n = @min(b.len, ans.pty_buf.len - ans.pty_len);
- @memcpy(ans.pty_buf[ans.pty_len..][0..n], b[0..n]);
- ans.pty_len += n;
- },
- .resize_pty => |r| ans.winsize = .{ .cols = r.cols, .rows = r.rows },
- .signal_pty => |s| ans.signal = s.sig,
- .close_pty => ans.closed = true,
- .spawn => ans.spawned = true,
- else => {},
- };
- return ans;
-}
-
-pub fn rd(p: *Pardes, node: u64, off: u64, size: u32) Answer {
- return call(p, .{ .tag = 1, .op = .read, .node = node, .off = off, .size = size });
-}
-
-/// Whether the log, read whole from a fresh open, holds `needle`.
-pub fn logHas(p: *Pardes, needle: []const u8) bool {
- return logCount(p, needle) > 0;
-}
-
-/// How many times the log, read whole from a fresh open, holds `needle`.
-pub fn logCount(p: *Pardes, needle: []const u8) usize {
- const log = @backingInt(tree.TopFile.log);
- const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle;
- defer _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h });
- const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes;
- return std.mem.count(u8, text, needle);
-}
-
-pub fn wr(p: *Pardes, node: u64, data: []const u8) Answer {
- return call(p, .{ .tag = 2, .op = .write, .node = node, .data = data });
-}
-
-pub fn rdir(p: *Pardes, node: u64, skip: u64) Answer {
- return call(p, .{ .tag = 4, .op = .readdir, .node = node, .off = skip, .size = 4096 });
-}
-
-pub fn look_up(p: *Pardes, dir: u64, name: []const u8) Answer {
- return call(p, .{ .tag = 3, .op = .lookup, .node = dir, .data = name });
-}
-
-/// Makes a pane the way a client does, by walking to /pane/new, and answers
-/// the serial of the pane the walk landed on.
-/// The open is what makes the pane; the handle it answers is the serial, which
-/// is also what a read of that fid reports.
-pub fn newPane(p: *Pardes) !u32 {
- const made = call(p, .{ .tag = 8, .op = .open, .node = @backingInt(tree.TopFile.new) });
- if (made.reply.status != .ok or made.reply.handle == 0) return error.NoPane;
- return made.reply.handle;
-}
-
-pub fn rmdir(p: *Pardes, node: u64) Answer {
- return call(p, .{ .tag = 9, .op = .release, .node = node, .remove = true });
-}
-
-pub fn withFile(gpa: std.mem.Allocator, text: []const u8) !*Pardes {
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- errdefer p.deinit();
- while (p.nextEffect()) |_| {}
- _ = try p.setTestFile(text);
- while (p.nextEffect()) |_| {}
- return p;
-}
-
-pub fn withTerm(gpa: std.mem.Allocator) !*Pardes {
- if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
- const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- errdefer p.deinit();
- while (p.nextEffect()) |_| {}
- std.debug.assert(p.panes[0].?.isTerminal());
- return p;
-}
-
-pub fn serialOf(p: *Pardes) u32 {
- return p.panes[0].?.serial;
-}
-
-pub const Dirent = struct { node: u64, dir: bool, name: []const u8 };
-
-pub fn dirents(bytes: []const u8, out: []Dirent) []Dirent {
- var n: usize = 0;
- var i: usize = 0;
- while (i + 10 <= bytes.len and n < out.len) {
- const node = std.mem.readInt(u64, bytes[i..][0..8], .little);
- const kind = bytes[i + 8];
- const len = bytes[i + 9];
- i += 10;
- if (i + len > bytes.len) break;
- out[n] = .{ .node = node, .dir = kind == 1, .name = bytes[i .. i + len] };
- i += len;
- n += 1;
- }
- return out[0..n];
-}
-
-pub fn nameAt(list: []const Dirent, want: []const u8) ?Dirent {
- for (list) |d| if (std.mem.eql(u8, d.name, want)) return d;
- return null;
-}
-
-/// A host that starts shells and does nothing else: the core alone starts
-/// none.
-pub const starting: pardes.Host.VTable = .{ .spawn = startNothing };
-
-fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {}
-
-pub const FakeTty = struct {
- taken: bool,
-
- pub const vtable: pardes.Host.VTable = .{ .tty_taken = answer };
-
- fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
- _ = id;
- const f: *FakeTty = @ptrCast(@alignCast(ctx.?));
- return f.taken;
- }
-};