summaryrefslogtreecommitdiff
path: root/test/process/other_files.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 16:33:08 -0300
committerGabriel Schneider <[email protected]>2026-11-04 16:48:55 -0300
commitef0d017705146a74bf7cc2706b9796f227ea6977 (patch)
treeb4f14a8724055be7918416b8893c32760d0ee7f8 /test/process/other_files.zig
parentbe3985092df1c3388cfa09ca5e989d2fa66f55ec (diff)
downloadpardes-ef0d017705146a74bf7cc2706b9796f227ea6977.tar.gz
pardes-ef0d017705146a74bf7cc2706b9796f227ea6977.zip
test: test/fs.py's discovery, run_file, exit_answers, unattended_messages_expire, directory_panes, putall_answers_after_its_saves, new_terminals_named_once, recent_survives_restart, store_shared_between_windows, odd_paths, delcol_last_keeps_window, cut_writes and edit_commands in Zig, the Python deleted (and its now unused newest, walk_tree, del_twice and the --discovery switch): at T2 in new test/process/{tree,terminals,root_ctl,edit}.zig and other_files.zig (the tree's listing, stats, log follow, ctl lock, focus, commands, sel, Save making directories, the 16 slots; a write cut at an 8 KiB msize; pty/run's answers, busy and shell gone; terminals named once; Exit; MessageLinger unattended; Putall; odd paths and ThemeFile; Edit's < | > off the loop, a held write answered after a later read and flushed, X and w; /recent across a restart and a store two sessions share), at T1 a directory pane in test/behaviour/look_and_exec.zig and 9P's new after Delcol of the last column in columns_and_tags.zig; discovery brought up to the tree as documented (sessions, kbdin, mousein at the root, /index stats 0, a sel write stays selected, the unknown-message words, a look's line in dot, a Save under / refused as permission denied), as the Python had gone stale; process.Conn gains replace, writeCut, create, newPane, newest, look, dialRefusal, send and answer, and process.sleep; a failing process test prints its error return trace; each checked to fail against a break (a detached session 161 wide, 17 connection slots, a pty taking one row, Edit's failure said as exit code, ThemeFile's .zon words changed, Exit not quitting, unattended messages never expiring, a directory pane's sub/ without its slash, Putall's modified-on-disk words changed, /recent saying shut for closed, a missing interpreter said as missing)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/process/other_files.zig')
-rw-r--r--test/process/other_files.zig119
1 files changed, 119 insertions, 0 deletions
diff --git a/test/process/other_files.zig b/test/process/other_files.zig
index d03d6b36..f682bb18 100644
--- a/test/process/other_files.zig
+++ b/test/process/other_files.zig
@@ -6,8 +6,33 @@ const process = @import("../process.zig");
pub const cases = .{
.{ "other-files: kbdin and mousein drive a detached session as the user would, each write done before it is answered", keysAndMouse },
.{ "other-files: a held connection lists a directory, stats a file, writes and reads, is refused in words and removes a pane", heldConnection },
+ .{ "other-files: a file opened and closed is in /recent closed, and still is in the next session; Recent's row opens it again", recentSurvivesRestart },
+ .{ "other-files: two sessions share one store: a file opened in one is in the other's /recent, a Del'd pane comes back from @p only where it was", storeShared },
};
+extern "c" fn system(cmd: [*:0]const u8) c_int;
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+/// A session's root kept past it, removed at the test's end.
+fn keepRoot(d: *process.Detached, buf: *[4096]u8) []const u8 {
+ d.owns_root = false;
+ @memcpy(buf[0..d.root().len], d.root());
+ return buf[0..d.root().len];
+}
+
+fn removeRoot(root: []const u8) void {
+ var cmd: [4200]u8 = undefined;
+ _ = system(std.fmt.bufPrintSentinel(&cmd, "rm -rf -- '{s}'", .{root}, 0) catch return);
+}
+
+fn storeExists(root: []const u8) bool {
+ var buf: [4200]u8 = undefined;
+ return std.c.access(std.fmt.bufPrintSentinel(&buf, "{s}/.local/state/pardes/store", .{root}, 0) catch return false, 0) == 0;
+}
+
/// A script types and clicks as the user does: no sleep or poll between a
/// write and the read that checks it; where to click is read off /screen.
/// (test/fs.py's keys_and_mouse, the first case written through the files
@@ -64,3 +89,97 @@ fn heldConnection(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try c.remove(try std.fmt.bufPrint(&path, "/pane/{d}", .{serial}));
try std.testing.expectError(error.NotFound, c.walk(body));
}
+
+/// The list is kept under $XDG_STATE_HOME (here HOME's .local/state) across
+/// restarts.
+fn recentSurvivesRestart(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var root_buf: [4096]u8 = undefined;
+ var one = try process.Detached.start(gpa, exe, "recent1", .{});
+ const root = keepRoot(&one, &root_buf);
+ defer removeRoot(root);
+ const kept = try std.fmt.allocPrint(a, "{s}/kept.txt", .{root});
+ {
+ defer one.deinit();
+ try one.put("kept.txt", "one\ntwo\n");
+ const c = try process.Conn.dial(gpa, one.socket());
+ defer c.deinit(gpa);
+ const serial = try c.look(a, try std.fmt.allocPrint(a, "{s}:2", .{kept}));
+ try std.testing.expect(has(try c.read(a, "/recent"), try std.fmt.allocPrint(a, "open {s}\n", .{kept})));
+ try c.write(try std.fmt.allocPrint(a, "/pane/{d}/ctl", .{serial}), "Del\n");
+ try std.testing.expect(has(try c.read(a, "/recent"), try std.fmt.allocPrint(a, "closed {s}\n", .{kept})));
+ }
+ try std.testing.expect(storeExists(root));
+ var two = try process.Detached.start(gpa, exe, "recent2", .{ .root = root });
+ defer two.deinit();
+ const c = try process.Conn.dial(gpa, two.socket());
+ defer c.deinit(gpa);
+ try std.testing.expect(has(try c.read(a, "/recent"), try std.fmt.allocPrint(a, "closed {s}\n", .{kept})));
+ // Recent fills a query pane with it, its row relative to the pane's
+ // directory, and a look at the row opens it again.
+ try c.write("/pane/1/exec", "Recent\n");
+ var answer = std.mem.tokenizeAny(u8, try c.read(a, "/pane/1/exec"), " \n");
+ var last: []const u8 = "";
+ while (answer.next()) |w| last = w;
+ const rows = try std.fmt.parseInt(u32, last, 10);
+ const body = try c.read(a, try std.fmt.allocPrint(a, "/pane/{d}/body", .{rows}));
+ try std.testing.expect(std.mem.startsWith(u8, body, "Recent "));
+ var lines = std.mem.tokenizeScalar(u8, body, '\n');
+ const row = while (lines.next()) |l| {
+ if (std.mem.startsWith(u8, l, "kept.txt:")) break l;
+ } else return error.NoRow;
+ try c.write(try std.fmt.allocPrint(a, "/pane/{d}/look", .{rows}), try std.fmt.allocPrint(a, "{s}\n", .{row[0 .. std.mem.indexOfScalar(u8, row, ' ') orelse row.len]}));
+ try std.testing.expect(has(try c.read(a, "/recent"), try std.fmt.allocPrint(a, "open {s}\n", .{kept})));
+}
+
+/// Del, and again when the first refused over unsaved text.
+fn delTwice(c: *process.Conn, ctl: []const u8) !void {
+ c.write(ctl, "Del\n") catch try c.write(ctl, "Del\n");
+}
+
+/// The store (Store.zig) shared with no restart; a pane Del'd in one
+/// comes back where it was from a look at its @p serial there, its text
+/// with it, and only there.
+fn storeShared(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ var root_buf: [4096]u8 = undefined;
+ var one = try process.Detached.start(gpa, exe, "store1", .{});
+ const root = keepRoot(&one, &root_buf);
+ defer removeRoot(root);
+ {
+ defer one.deinit();
+ var two = try process.Detached.start(gpa, exe, "store2", .{ .root = root });
+ defer two.deinit();
+ const c1 = try process.Conn.dial(gpa, one.socket());
+ defer c1.deinit(gpa);
+ const c2 = try process.Conn.dial(gpa, two.socket());
+ defer c2.deinit(gpa);
+ try one.put("shared.txt", "one\ntwo\nthree\n");
+ const shared = try std.fmt.allocPrint(a, "{s}/shared.txt", .{root});
+ const serial = try c1.look(a, try std.fmt.allocPrint(a, "{s}:3", .{shared}));
+ try std.testing.expect(has(try c1.read(a, "/recent"), try std.fmt.allocPrint(a, "open {s}\n", .{shared})));
+ try std.testing.expect(has(try c2.read(a, "/recent"), try std.fmt.allocPrint(a, "closed {s}\n", .{shared})));
+ try c1.write(try std.fmt.allocPrint(a, "/pane/{d}/ctl", .{serial}), "Del\n");
+ try std.testing.expect(has(try c1.read(a, "/recent"), try std.fmt.allocPrint(a, "closed {s}\n", .{shared})));
+ const scratch = try c1.newPane();
+ try c1.write(try std.fmt.allocPrint(a, "/pane/{d}/body", .{scratch}), "kept across a Del\n");
+ try delTwice(c1, try std.fmt.allocPrint(a, "/pane/{d}/ctl", .{scratch}));
+ var rows = std.mem.tokenizeScalar(u8, try c1.read(a, "/index"), '\n');
+ while (rows.next()) |r| try std.testing.expect(!std.mem.startsWith(u8, r, try std.fmt.allocPrint(a, "{d} ", .{scratch})));
+ const back = try c1.look(a, try std.fmt.allocPrint(a, "@p{d}", .{scratch}));
+ try std.testing.expectEqualStrings("kept across a Del\n", try c1.read(a, try std.fmt.allocPrint(a, "/pane/{d}/body", .{back})));
+ // The other window's session closed no such pane.
+ const source = try c2.newPane();
+ c2.write(try std.fmt.allocPrint(a, "/pane/{d}/look", .{source}), try std.fmt.allocPrint(a, "@p{d}\n", .{scratch})) catch {};
+ var others = std.mem.tokenizeScalar(u8, try c2.read(a, "/index"), '\n');
+ while (others.next()) |r| {
+ const body = try c2.read(a, try std.fmt.allocPrint(a, "/pane/{s}/body", .{r[0..std.mem.indexOfScalar(u8, r, ' ').?]}));
+ try std.testing.expect(!has(body, "kept across a Del"));
+ }
+ }
+ try std.testing.expect(storeExists(root));
+}