summaryrefslogtreecommitdiff
path: root/test/behaviour/addons.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/addons.zig')
-rw-r--r--test/behaviour/addons.zig46
1 files changed, 40 insertions, 6 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index c91bda1a..523aefb9 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -33,12 +33,12 @@ fn unload(s: *Session, name: []const u8) void {
test "addons: Addon load takes a library in, /addons lists it with the kinds compiled in, its words join /commands and Help, and Addon unload lets it go" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
- try std.testing.expect(has(try s.read("/addons"), "image 1 1.0 0 - - static\n"));
+ try std.testing.expect(has(try s.read("/addons"), "image 1 2.0 0 - - static\n"));
try load(&s, fake.ok);
defer unload(&s, "fake");
// `<kind> <version> <abi> <panes open> <path> <blake3> <state>`.
const listed = try s.read("/addons");
- const at = std.mem.indexOf(u8, listed, "\nfake 1 1.0 0 /").?;
+ const at = std.mem.indexOf(u8, listed, "\nfake 1 2.0 0 /").?;
var fields = std.mem.tokenizeScalar(u8, listed[at + 1 .. std.mem.indexOfScalarPos(u8, listed, at + 1, '\n').?], ' ');
for (0..5) |_| _ = fields.next();
try std.testing.expectEqual(@as(usize, 64), fields.next().?.len);
@@ -52,7 +52,7 @@ test "addons: Addon load takes a library in, /addons lists it with the kinds com
// A pane of it open, it stays; closed, it goes.
try s.write("/ctl", "Fake\n");
const pane = try paneOf(&s, "fake");
- try std.testing.expect(has(try s.read("/addons"), "\nfake 1 1.0 1 /"));
+ try std.testing.expect(has(try s.read("/addons"), "\nfake 1 2.0 1 /"));
try std.testing.expect(try s.refused("/ctl", "Addon unload fake\n") != 0);
try std.testing.expect(has(s.said, "1 fake pane is open"));
try s.write(s.at("/pane/{d}/ctl", .{pane}), "Del\n");
@@ -69,10 +69,10 @@ test "addons: a library of another ABI, one with no pardes_addon, and one whose
defer s.deinit();
for ([_][]const u8{ fake.abi, fake.no_export, fake.core_word }) |path| try load(&s, path);
const listed = try s.read("/addons");
- try std.testing.expect(has(listed, "\nfakeabi 1 2.0 0 /"));
- try std.testing.expect(has(listed, " refused: wants abi 2, this pardes speaks 1\n"));
+ try std.testing.expect(has(listed, "\nfakeabi 1 3.0 0 /"));
+ try std.testing.expect(has(listed, " refused: wants abi 3, this pardes speaks 2\n"));
try std.testing.expect(has(listed, " refused: it has no pardes_addon\n"));
- try std.testing.expect(has(listed, "\nfakeword 1 1.0 0 /"));
+ try std.testing.expect(has(listed, "\nfakeword 1 2.0 0 /"));
try std.testing.expect(has(listed, " refused: word Save is the core's\n"));
// A file that is no library at all: listed with what the loader said.
var tmp = std.testing.tmpDir(.{});
@@ -189,6 +189,40 @@ test "addons: Addon reload moves every pane of the kind to the library as it is
try std.testing.expect(!std.mem.eql(u8, before, try s.read("/addons")));
}
+test "addons: a job under way across a reload answers into nothing, its library kept until it has; the reloaded pane's own jobs land" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const copy = struct {
+ fn of(ss: *Session, d: std.Io.Dir, from: []const u8) !void {
+ try d.writeFile(std.testing.io, .{ .sub_path = "fake.so", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, from, ss.arena.allocator(), .limited(64 << 20)) });
+ }
+ }.of;
+ try copy(&s, tmp.dir, fake.ok);
+ try s.write("/ctl", s.at("Addon load {s}/fake.so\n", .{dir}));
+ defer unload(&s, "fake");
+ try s.write("/ctl", "Fake\n");
+ const pane = try paneOf(&s, "fake");
+ try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeBump 5\n");
+ // A job taken by a worker, still running as the library is replaced
+ // by another (one with no record: the pane comes back at its place, 5,
+ // then its words' last values, FakeBump 5: 10).
+ s.hold_jobs = true;
+ try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeJob\n");
+ try copy(&s, tmp.dir, fake.no_dump);
+ try s.write("/ctl", "Addon reload fake\n");
+ try std.testing.expect(has(try s.screen(), "count 10 "));
+ // It answers now, from the old library's code: of another generation,
+ // the answer is dropped, and the old library goes after it.
+ s.releaseJobs();
+ try std.testing.expect(has(try s.screen(), "count 10 "));
+ try s.write(s.at("/pane/{d}/ctl", .{pane}), "FakeJob\n");
+ try std.testing.expect(has(try s.screen(), "count 16 "));
+}
+
test "addons: a Look at a file whose extension an addon claims opens a pane of its kind, and its words are in Help" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();