summaryrefslogtreecommitdiff
path: root/test/behaviour/root_ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 16:59:08 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:13:25 -0300
commit023793be1112bc35b50551580d273f4cf611b3da (patch)
tree4167a4e0435d545dbdb8e09e4f6578491b1dd1e2 /test/behaviour/root_ctl.zig
parentd1273bbd99daf9b1855d82bf315db8ede20abde5 (diff)
downloadpardes-023793be1112bc35b50551580d273f4cf611b3da.tar.gz
pardes-023793be1112bc35b50551580d273f4cf611b3da.zip
test: sixteen of src/ninep/ctl.zig's tests through the 9P tree alone, in new test/behaviour/{log,mounts,rules,settings}.zig and appended to edit, columns_and_tags, look_and_exec, panes and root_ctl: the log's msg and err records (a root ctl's message the session's, the same failure counted, a root exec's err its pane's), Mount's refusals (and nothing mounted, read from Unmount), Pager and Shell read back from the root ctl, a control character in any ctl and in any tag, a bad command inside an Edit block, a look's :addr and file:addr, the root look's file:/re/ from the dot, exec's readback, focus (a column tag's keyboard taken by Newcol), the pane ctl's and the root ctl's words; each checked to fail against a break: the (xN) count one short, msg - written as msg 0, a root exec's err left as -, a missing socket's words changed, Pager defaulting off, a bare Shell not clearing, tree.zig's ctl check skipped, DEL taken in a tag, an Edit block's bad command naming }, a look's address evaluated from 0 not the dot, no results recorded, focus leaving the header the keyboard, "not a pane control message", every setting value taken
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/root_ctl.zig')
-rw-r--r--test/behaviour/root_ctl.zig55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig
index bdf912da..f7ebbbb9 100644
--- a/test/behaviour/root_ctl.zig
+++ b/test/behaviour/root_ctl.zig
@@ -29,3 +29,58 @@ test "root-ctl: size sets the screen of a session no frontend is attached to, an
try std.testing.expect(std.mem.indexOf(u8, s.said, "too small for the panes") != null);
try std.testing.expectEqual(.{ @as(usize, 120), @as(usize, 40) }, try size(&s));
}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+fn columns(s: *Session) !usize {
+ return std.mem.count(u8, try s.read("/layout"), "\n") - 1; // and `active`
+}
+
+test "root-ctl: the root ctl reads the settings as a write takes them, and takes the session's builtins" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const settings = try s.read("/ctl");
+ try std.testing.expect(has(settings, "Verbose on\n"));
+ try std.testing.expect(has(settings, "LocationsConfig "));
+ try std.testing.expect(has(settings, "CallstackDepth 8\n"));
+ try s.write("/ctl", "CallstackDepth\n");
+ // Settings only: nothing /status or the DumpConfig window says.
+ try std.testing.expect(!has(settings, "Platform"));
+ try std.testing.expect(!has(settings, "requested"));
+ // Every line written back is taken, and changes nothing.
+ try s.write("/ctl", settings);
+ try s.expect("/ctl", settings);
+ try s.write("/ctl", "Verbose off\n");
+ try std.testing.expect(has(try s.read("/ctl"), "Verbose off\n"));
+ const before = try columns(&s);
+ try s.write("/ctl", "Newcol\n");
+ try std.testing.expectEqual(before + 1, try columns(&s));
+ const refusals = [_]struct { []const u8, []const u8 }{
+ .{ "Del", "not a session control message \"Del\": write it to pane/<n>/ctl" },
+ .{ "Nonsense 1", "unknown control message \"Nonsense\"" },
+ .{ "Verbose maybe", "bad value in control message; takes on, off \"maybe\"" },
+ .{ "Placement east", "bad value in control message; takes acme, pardes \"east\"" },
+ // A number's refusal names its range.
+ .{ "InactiveDim 200", "bad value in control message; takes 0-100 (a percentage) \"200\"" },
+ .{ "MessageLinger x", "bad value in control message; takes 0-60000 (milliseconds) \"x\"" },
+ .{ "Newcol 2", "wrong #args in control message \"Newcol\"" },
+ .{ "Theme", "wrong #args in control message \"Theme\"" },
+ };
+ for (refusals) |r| {
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", s.at("{s}\n", .{r[0]})));
+ try std.testing.expectEqualStrings(r[1], s.said);
+ }
+ _ = try s.refused("/ctl", "Theme no-such-theme\n");
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "bad value in control message; like it: n"));
+ try std.testing.expect(std.mem.endsWith(u8, s.said, "; Themes lists all \"no-such-theme\""));
+ // A bare required word fails the check, so the line before never runs.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Verbose on\nMount\n"));
+ try std.testing.expect(has(try s.read("/ctl"), "Verbose off\n"));
+ // A builtin that fails as it runs fails the write, quoting its error and
+ // its line; the lines before it have taken effect, as in acme.
+ try std.testing.expectEqual(@as(u16, 2), try s.refused("/ctl", "Verbose on\nMount x /tmp/pardes-no-such-sock-zz\nVerbose off\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "Mount x: /tmp/pardes-no-such-sock-zz: no such socket"));
+ try std.testing.expect(has(try s.read("/ctl"), "Verbose on\n"));
+}