summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:08:35 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:09:05 -0300
commit6ff5fc7447cc411dc24cb1d841130f15a410e354 (patch)
treeaf62dbe381cb6df4d19c0523b6d6cfd99e500773 /test
parent5322d373c78ecee48b934886c95f3b8c4471a11f (diff)
downloadpardes-6ff5fc7447cc411dc24cb1d841130f15a410e354.tar.gz
pardes-6ff5fc7447cc411dc24cb1d841130f15a410e354.zip
test: three of test/output.zig's tests through the 9P tree alone: DumpConfig's report in its one +DumpConfig pane, a second refreshing it in place (settings, a new file: /index, /focus and its body, Theme acme seen there), Config with no configuration directory refused, said in the log and opening nothing (settings), a Mini that cannot read its file leaving the panes, the last snapshot and the keyboard as they were (panes); the startup path line stays, a process flag with no 9P surface; each checked to fail against a break (openRead never reusing an output pane, Config taking a made-up path when there is no directory, a failed Mini giving the keyboard back to its caller)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
-rw-r--r--test/behaviour.zig1
-rw-r--r--test/behaviour/panes.zig16
-rw-r--r--test/behaviour/settings.zig38
-rw-r--r--test/output.zig60
4 files changed, 57 insertions, 58 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 3e377ed7..2a37693e 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -10,4 +10,5 @@ test {
_ = @import("behaviour/other_files.zig");
_ = @import("behaviour/panes.zig");
_ = @import("behaviour/root_ctl.zig");
+ _ = @import("behaviour/settings.zig");
}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index 8a906c2b..90c283b7 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -118,3 +118,19 @@ test "panes: PdfSections on a PDF with no outline says so and opens nothing" {
}
try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "PdfSections: this PDF has no outline") != null);
}
+
+test "panes: a Mini that cannot read its file leaves the panes, the last Mini's snapshot and the keyboard as they were" {
+ var s = try Session.initFile(std.testing.allocator, "abc\n");
+ defer s.deinit();
+ const text = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{text});
+ try s.write(exec, s.at("Mini /virtual/pane/{d}/body\n", .{text}));
+ const mini = try s.focused();
+ try std.testing.expect(mini != text);
+ const body = try s.read(s.at("/pane/{d}/body", .{mini}));
+ const index = try s.read("/index");
+ try std.testing.expectEqual(@as(u16, 2), try s.refused(exec, "Mini /virtual/does-not-exist\n"));
+ try std.testing.expectEqual(mini, try s.focused());
+ try s.expect("/index", index);
+ try s.expect(s.at("/pane/{d}/body", .{mini}), body);
+}
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
new file mode 100644
index 00000000..57751ab1
--- /dev/null
+++ b/test/behaviour/settings.zig
@@ -0,0 +1,38 @@
+//! docs/typ/reference.typ, Settings <settings>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn has(text: []const u8, part: []const u8) !void {
+ if (std.mem.indexOf(u8, text, part) == null) {
+ std.debug.print("not in it: {s}\n", .{part});
+ return error.TestExpectedText;
+ }
+}
+
+test "settings: DumpConfig reports the settings in its one +DumpConfig pane, a second refreshing it" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const text = try s.focused();
+ const exec = s.at("/pane/{d}/exec", .{text});
+ try s.write(exec, "DumpConfig\n");
+ const out = try s.focused();
+ try std.testing.expect(out != text);
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), s.at("{d} text 0 /+DumpConfig ", .{out})) != null);
+ const report = try s.read(s.at("/pane/{d}/body", .{out}));
+ for ([_][]const u8{ "Theme orchard\n", "Last shell spawned: (none)\n", "Shell change pending: on\n", "\nShell ", "LocationsConfig ", "no per-user config path" }) |line| try has(report, line);
+ try s.write("/ctl", "Theme acme\n");
+ try s.write("/focus", s.at("{d}", .{text}));
+ try s.write(exec, "DumpConfig\n");
+ try std.testing.expectEqual(out, try s.focused());
+ try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+DumpConfig "));
+ try has(try s.read(s.at("/pane/{d}/body", .{out})), "Theme acme\n");
+}
+
+test "settings: Config without a configuration directory says so and opens nothing" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const index = try s.read("/index");
+ try std.testing.expectEqual(@as(u16, 5), try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Config\n"));
+ try s.expect("/index", index);
+ try has(try s.read("/log"), "Config: no startup file here: no configuration directory");
+}
diff --git a/test/output.zig b/test/output.zig
index 2b8bf1f5..4d5945cd 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -495,60 +495,12 @@ test "Mini syntax colors survive toggles themes and rendering without source acc
}
}
-test "Mini failures leave its existing snapshot and focus unchanged" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const source = try p.setTestFile("abc\n");
- var path_buf: [128]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "/virtual/pane/{d}/body", .{source.serial});
- try panes.mini.open(p, 0, path);
- const id = p.active;
- const mini = p.panes[id].?;
- const body = mini.file.?.content.ptr;
- const next = p.freeSlot();
- try std.testing.expectError(error.FileNotFound, panes.mini.open(p, 0, "/virtual/does-not-exist"));
- try std.testing.expectEqual(id, p.active);
- try std.testing.expectEqual(body, mini.file.?.content.ptr);
- try std.testing.expectEqual(next, p.freeSlot());
-}
-
-test "DumpConfig prints the startup path and refreshes its one output" {
+test "DumpConfig prints the startup path" {
const path = "/home/pardes-test/.config/pardes/init";
const p = try Pardes.init(std.testing.allocator, .{ .startup_config_path = path });
defer p.deinit();
-
- try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig"));
- const opened = p.active;
- const out = p.panes[opened].?.file.?;
- for ([_][]const u8{
- "Startup config: " ++ path ++ "\n",
- "Theme orchard\n",
- "Last shell spawned: (none)\n",
- "Shell change pending: on\n",
- "LocationsConfig ",
- }) |line| try std.testing.expect(std.mem.indexOf(u8, out.content, line) != null);
- var default_line: [256]u8 = undefined;
- try std.testing.expect(std.mem.indexOf(u8, out.content, try std.fmt.bufPrint(&default_line, "Shell {s}\n", .{config.defaultShell()})) != null);
- try std.testing.expectEqualStrings(config.dump_config_buffer, std.fs.path.basename(out.path));
- try std.testing.expectEqual(panes.Output.Origin{ .cmd = .DumpConfig }, out.output.?.from);
-
- try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig"));
- try std.testing.expectEqual(opened, p.active);
- var buffers: usize = 0;
- for (p.panes) |slot| {
- const f = (slot orelse continue).file orelse continue;
- const origin = (f.output orelse continue).from;
- buffers += @intFromBool(std.meta.eql(origin, panes.Output.Origin{ .cmd = .DumpConfig }));
- }
- try std.testing.expectEqual(@as(usize, 1), buffers);
-}
-
-test "DumpConfig reports the absence of a per-user config path" {
- const p = try Pardes.init(std.testing.allocator, .{});
- defer p.deinit();
try std.testing.expect(p.executeBuiltinLine(0, "DumpConfig"));
- const report = p.panes[p.active].?.file.?.content;
- try std.testing.expect(std.mem.indexOf(u8, report, "no per-user config path") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.panes[p.active].?.file.?.content, "Startup config: " ++ path ++ "\n") != null);
}
/// The file Config names, in a fresh temporary directory: `pardes/init`
@@ -621,14 +573,6 @@ test "Config with no startup file opens a pane of its name, and Save makes its d
try std.testing.expectEqual(std.Io.File.Kind.directory, made.kind);
}
-test "Config without a configuration directory says so and opens nothing" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const before = p.freeSlot();
- try std.testing.expect(p.executeBuiltinLine(p.active, "Config"));
- try std.testing.expectEqual(before, p.freeSlot());
-}
-
test "EffectCode lists readable virtual sources used by this backend" {
if (comptime !builtins.EffectCode.enabled) return;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });