summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/addons.zig71
-rw-r--r--test/fs_namespace.zig20
-rw-r--r--test/image_harness.zig20
-rw-r--r--test/kitty.zig12
-rw-r--r--test/mode.zig2
-rw-r--r--test/panes.zig56
-rw-r--r--test/pdf.zig13
-rw-r--r--test/process.zig7
-rw-r--r--test/process_test.zig4
-rw-r--r--test/session.zig2
-rw-r--r--test/snapshot.zig13
11 files changed, 175 insertions, 45 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index 523aefb9..c7a59951 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -33,13 +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 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 2.0 0 /").?;
- var fields = std.mem.tokenizeScalar(u8, listed[at + 1 .. std.mem.indexOfScalarPos(u8, listed, at + 1, '\n').?], ' ');
+ try std.testing.expect(std.mem.startsWith(u8, listed, "fake 1 2.0 0 /"));
+ var fields = std.mem.tokenizeScalar(u8, listed[0..std.mem.indexOfScalar(u8, listed, '\n').?], ' ');
for (0..5) |_| _ = fields.next();
try std.testing.expectEqual(@as(usize, 64), fields.next().?.len);
try std.testing.expectEqualStrings("loaded", fields.next().?);
@@ -52,16 +51,13 @@ 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 2.0 1 /"));
+ try std.testing.expect(std.mem.startsWith(u8, try s.read("/addons"), "fake 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");
try s.write("/ctl", "Addon unload fake\n");
try std.testing.expect(!has(try s.read("/addons"), "fake"));
try std.testing.expect(!has(try s.read("/commands"), "Fake"));
- // A compiled-in kind is no library to let go.
- try std.testing.expect(try s.refused("/ctl", "Addon unload image\n") != 0);
- try std.testing.expect(has(s.said, "image is compiled in"));
}
test "addons: a library of another ABI, one with no pardes_addon, and one whose word is the core's are refused, each listed with why" {
@@ -69,7 +65,7 @@ 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 3.0 0 /"));
+ try std.testing.expect(std.mem.startsWith(u8, listed, "fakeabi 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 2.0 0 /"));
@@ -119,6 +115,65 @@ test "addons: a pane of an addon's kind shows its cells and its picture, takes i
try std.testing.expect(try s.focused() != pane);
}
+test "addons: the image addon opens the pictures a Look names, fitted, with the core's art words in its tag; refuses what it cannot read; and keeps a picture's bytes through a dump" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try load(&s, Session.image_addon);
+ const listed = try s.read("/addons");
+ try std.testing.expect(std.mem.startsWith(u8, listed, "image 1 2.0 0 /") and has(listed, " loaded\n"));
+ 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)];
+ // A PNG 4x2, a JPEG 16x8 baseline and progressive, a PPM 2x1: each a
+ // pane showing its pixels (`src`), over the cells it fits.
+ const b64 = std.base64.standard.Decoder;
+ const pictures = [_]struct { []const u8, []const u8, u32, u32 }{
+ .{ "red.png", "iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAAE0lEQVR4nGP4z8AARGDiPwMyBwBnsgf5Q2OaZwAAAABJRU5ErkJggg==", 4, 2 },
+ .{ "red.jpg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAAIABADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD5Dooor8LP9VD/2Q==", 16, 8 },
+ .{ "red.jpeg", "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wgARCAAIABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAVAQEBAAAAAAAAAAAAAAAAAAAGCP/aAAwDAQACEAMQAAABkIC1V//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAQUCP//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Bf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Bf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEABj8CP//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8hP//aAAwDAQACAAMAAAAQA//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQMBAT8Qf//EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQIBAT8Qf//EABQQAQAAAAAAAAAAAAAAAAAAABD/2gAIAQEAAT8QP//Z", 16, 8 },
+ .{ "pixel.ppm", "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7", 2, 1 },
+ };
+ for (pictures) |pic| {
+ const bytes = if (std.mem.endsWith(u8, pic[0], ".ppm")) pic[1] else blk: {
+ const out = try s.arena.allocator().alloc(u8, try b64.calcSizeForSlice(pic[1]));
+ try b64.decode(out, pic[1]);
+ break :blk out;
+ };
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = pic[0], .data = bytes });
+ try s.write("/look", s.at("{s}/{s}\n", .{ dir, pic[0] }));
+ try std.testing.expect(has(try s.read("/screen"), s.at("\"serial\":{d},\"rect\":", .{try s.focused()})));
+ try std.testing.expect(has(try s.read("/screen"), s.at("\"src\":[0,0,{d},{d}]", .{ pic[2], pic[3] })));
+ }
+ const pane = try s.focused();
+ // Its tag: the kind's `img`, the core's art words, its path. With no
+ // pixels to show (no frontend), glyph art whatever Petscii says.
+ const tag = s.at("/pane/{d}/tag", .{pane});
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), s.at("img petscii:on palette:commodore ascii:on {s}/pixel.ppm ", .{dir})));
+ const ctl = s.at("/pane/{d}/ctl", .{pane});
+ for ([_][]const u8{ "Petscii on\n", "Palette terminal\n", "Palette terminal\n", "Ascii off\n" }) |line| try s.write(ctl, line);
+ try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), "img petscii:on palette:terminal ascii:off "));
+ try std.testing.expect(has(try s.read("/screen"), "\"petscii\":true"));
+ // A file it cannot read: the Look fails saying so, and opens nothing.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "bad.png", .data = "\x89PNG not really" });
+ const panes = (try s.read("/index")).len;
+ try std.testing.expect(try s.refused("/look", s.at("{s}/bad.png\n", .{dir})) != 0);
+ try std.testing.expect(has(s.said, "bad.png: not an image pardes can read"));
+ try std.testing.expectEqual(panes, (try s.read("/index")).len);
+ // Its record is the file's bytes: restored without the addon it waits
+ // as a placeholder holding them, and shows them again when it comes.
+ try s.write("/ctl", "Dump\n");
+ const label = try s.arena.allocator().dupe(u8, std.mem.sliceTo(try s.read("/dumps"), ' '));
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n');
+ while (lines.next()) |line| if (std.mem.indexOf(u8, line, " image ") != null) try s.write(s.at("/pane/{s}/ctl", .{std.mem.sliceTo(line, ' ')}), "Del\n");
+ try s.write("/ctl", "Addon unload image\n");
+ try s.write("/ctl", s.at("Restore {s}\n", .{label}));
+ try std.testing.expect(has(try s.screen(), "addon image 1 is not loaded: Addon load <path>"));
+ try load(&s, Session.image_addon);
+ defer unload(&s, "image");
+ try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]"));
+}
+
test "addons: a dump keeps an addon's pane; restored without its addon it waits as a placeholder, and opens in place when the addon comes" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig
index 6ee50f77..22ce27fe 100644
--- a/test/fs_namespace.zig
+++ b/test/fs_namespace.zig
@@ -1,6 +1,5 @@
const std = @import("std");
const pardes = @import("pardes");
-const image = pardes.image;
const filesystem = pardes.filesystem;
test "runtime Mount and Unmount copy command arguments and change Look resolution" {
@@ -289,8 +288,6 @@ test "owned cwd failed file opens never publish a pane or retain a reservation"
test "images decode through explicit filesystem mounts, and a dump reads one on disk from there" {
if (!filesystem.platform_has_fs) return error.SkipZigTest;
const gpa = std.testing.allocator;
- pardes.image.start(std.testing.io, gpa);
- defer pardes.image.stop();
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
const bytes = "P6\n1 1\n255\n\x0d\x4d\xe7";
@@ -299,22 +296,27 @@ test "images decode through explicit filesystem mounts, and a dump reads one on
const directory_len = try tmp.dir.realPath(std.testing.io, &directory_buffer);
const path = try std.fmt.allocPrint(gpa, "/n/os{s}/pixel.ppm", .{directory_buffer[0..directory_len]});
defer gpa.free(path);
- const p = try pardes.Pardes.init(gpa, .{ .tty_only = true, .file = path });
+ const p = try pardes.Pardes.init(gpa, .{ .tty_only = true });
defer p.deinit();
+ // The image addon loaded, as `Addon load` loads it; the picture looked at.
+ pardes.Addon.perform(p, .load, 0, @import("test_addons").image);
+ pardes.look.lookAt(p, 0, path);
var arena = std.heap.ArenaAllocator.init(gpa);
defer arena.deinit();
// Its decode is a job its host runs: here, at once.
- while (p.nextEffect()) |e| p.perform(e);
+ while (p.nextEffect()) |e| if (e == .job) p.perform(e);
_ = try p.render(arena.allocator());
const shown = p.surface.placements.items;
try std.testing.expectEqual(@as(usize, 1), shown.len);
try std.testing.expectEqual(@as(u32, 1), shown[0].raster.w);
try std.testing.expectEqual(@as(u32, 1), shown[0].raster.h);
- // The picture's bytes are in the dump: it comes back as it was shown.
+ // The picture's bytes are in the dump: it comes back as it was shown
+ // (a placeholder holding them, as a core without the addon keeps it).
try pardes.dump.dumpState(p);
const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
defer restored.deinit();
- const slot = restored.panes[0].?.addon.?;
- var kept: [64]u8 = undefined;
- try std.testing.expectEqualStrings(bytes, kept[0..image.kind.dump.?(slot.st, &kept, kept.len)]);
+ const slot = for (restored.panes) |pane| {
+ if (pane) |each| if (each.addon) |s| break s;
+ } else return error.NoImagePane;
+ try std.testing.expectEqualStrings(bytes, slot.record.?);
}
diff --git a/test/image_harness.zig b/test/image_harness.zig
index 18392851..02e6690b 100644
--- a/test/image_harness.zig
+++ b/test/image_harness.zig
@@ -36,12 +36,14 @@ pub fn main(init: std.process.Init) !void {
defer arena_state.deinit();
const arena = arena_state.allocator();
const args = try init.minimal.args.toSlice(arena);
- if (args.len != 3 and args.len != 4) return error.BadArgs;
+ // <pardes> <image.so> tui|gui [pdf]
+ if (args.len != 4 and args.len != 5) return error.BadArgs;
const exe = try arena.dupeSentinel(u8, args[1], 0);
- const backend = args[2];
- const pdf_mode = args.len == 4 and std.mem.eql(u8, args[3], "pdf");
- if (args.len == 4 and !pdf_mode) return error.BadArgs;
+ const image_addon = try std.Io.Dir.cwd().realPathFileAlloc(init.io, args[2], arena);
+ const backend = args[3];
+ const pdf_mode = args.len == 5 and std.mem.eql(u8, args[4], "pdf");
+ if (args.len == 5 and !pdf_mode) return error.BadArgs;
const base = try std.fmt.allocPrintSentinel(arena, "/tmp/pardes-image-harness-{d}", .{libc.getpid()}, 0);
if (libc.mkdir(base, 0o755) != 0 and libc.errno(-1) != .EXIST) return error.MkdirFailed;
defer cleanupBase(arena, base);
@@ -54,6 +56,10 @@ pub fn main(init: std.process.Init) !void {
const config_dir = try std.fmt.allocPrintSentinel(arena, "{s}/pardes", .{config_home}, 0);
if (libc.mkdir(config_dir, 0o755) != 0) return error.MkdirFailed;
try eh.writeFile(try std.fmt.allocPrintSentinel(arena, "{s}/init", .{config_dir}, 0), "Theme helix\n");
+ // Its data directory too, holding the image addon its start scan loads.
+ _ = setenv("XDG_DATA_HOME", try std.fmt.allocPrintSentinel(arena, "{s}/data", .{base}, 0), 1);
+ for ([_][]const u8{ "data", "data/pardes", "data/pardes/addons" }) |sub| _ = libc.mkdir(try std.fmt.allocPrintSentinel(arena, "{s}/{s}", .{ base, sub }, 0), 0o755);
+ if (libc.symlink(image_addon, try std.fmt.allocPrintSentinel(arena, "{s}/data/pardes/addons/image.so", .{base}, 0)) != 0) return error.SymlinkFailed;
_ = setenv("HISTFILE", "/dev/null", 1);
_ = setenv("TERM", "xterm-256color", 1);
_ = setenv("LC_ALL", "C", 1);
@@ -78,11 +84,15 @@ fn cleanupBase(arena: std.mem.Allocator, base: [:0]const u8) void {
_ = libc.rmdir(config_dir);
const config_home = std.fmt.allocPrintSentinel(arena, "{s}/.config", .{base}, 0) catch return;
_ = libc.rmdir(config_home);
- const names = [_][]const u8{ "native.ppm", "pages.pdf", "latest.ppm", "latest.ppm.tmp", ".bash_history" };
+ const names = [_][]const u8{ "native.ppm", "pages.pdf", "latest.ppm", "latest.ppm.tmp", ".bash_history", "data/pardes/addons/image.so" };
for (names) |name| {
const path = std.fmt.allocPrintSentinel(arena, "{s}/{s}", .{ base, name }, 0) catch continue;
_ = libc.unlink(path);
}
+ for ([_][]const u8{ "data/pardes/addons", "data/pardes", "data" }) |sub| {
+ const path = std.fmt.allocPrintSentinel(arena, "{s}/{s}", .{ base, sub }, 0) catch continue;
+ _ = libc.rmdir(path);
+ }
_ = libc.rmdir(base);
}
diff --git a/test/kitty.zig b/test/kitty.zig
index 70e20139..ad70f453 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -64,9 +64,9 @@ const Rig = struct {
read: [pardes.MAX_PANES]std.ArrayList(u8) = @splat(.empty),
fn init(shells: u8) !Rig {
- // f=100 decodes through pardes's own decoder (stb_image), which the
- // shells start at launch.
- pardes.image.start(std.testing.io, gpa);
+ // f=100 decodes through wuffs, its resize through stb_image_resize,
+ // which the shells start at launch.
+ pardes.TerminalImages.start(std.testing.io, gpa);
// ghostty warns of every refused command; the refusals are the point.
std.testing.log_level = .err;
// A core boots one shell or the classic three.
@@ -86,7 +86,7 @@ const Rig = struct {
for (&r.read) |*b| b.deinit(gpa);
r.frame.deinit();
r.p.deinit();
- pardes.image.stop();
+ pardes.TerminalImages.stop();
}
fn drain(r: *Rig) void {
@@ -398,7 +398,7 @@ test "kitty: a=p places one image twice by placement id, a source rect crops it,
const crop = cropped orelse return error.CroppedPlacementMissing;
try std.testing.expectEqual(o.x + 9, crop.dst.x);
try std.testing.expectEqual(@as(u16, 1), crop.dst.w);
- const g: pardes.image.NativeGeometry = .{ .src = crop.src, .dst = crop.at.? };
+ const g: pardes.NativeGeometry = .{ .src = crop.src, .dst = crop.at.? };
try std.testing.expectEqual(@as(u32, 2), g.src.x);
try std.testing.expectEqual(@as(u32, 2), g.src.w);
// Put again under the same id, placement 1 moves; it is not doubled.
@@ -1212,7 +1212,7 @@ test "kitty: an image wider than its pane is cut at the pane's edge, never drawn
try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= o.x + r.pane(0).cols);
try std.testing.expect(drawn[0].dst.x + drawn[0].dst.w <= right);
// And the pixels it takes are only that cell's.
- const g: pardes.image.NativeGeometry = .{ .src = drawn[0].src, .dst = drawn[0].at.? };
+ const g: pardes.NativeGeometry = .{ .src = drawn[0].src, .dst = drawn[0].at.? };
try std.testing.expect(g.dst.w <= @as(u32, drawn[0].dst.w) * 10);
}
diff --git a/test/mode.zig b/test/mode.zig
index cb93b73e..7335b4ef 100644
--- a/test/mode.zig
+++ b/test/mode.zig
@@ -92,7 +92,7 @@ test "Mode from actual tag Exec preserves parked file and output insert transact
test "Mode leaves image and PDF document modes unchanged" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- const picture = try pardes.Kind.open(p, 1, pardes.Kind.image, "/mode-test.png", "");
+ const picture = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/mode-test.png", "");
try mode(p, 1, .normal);
try std.testing.expect(picture.addon != null);
if (comptime panes.Pdf.enabled) {
diff --git a/test/panes.zig b/test/panes.zig
index e0c383fd..28a884ab 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -8,7 +8,6 @@ const Key = pardes.Key;
const config = pardes.config;
const modal = pardes.modal;
const dump = pardes.dump;
-const image = pardes.image;
const syntax = pardes.syntax;
const filesystem = pardes.filesystem;
@@ -2246,24 +2245,65 @@ const OutputTests = struct {
}
};
+/// The image addon (addons/image/image.c), loaded as `Addon load` loads it.
const ImageTests = struct {
+ fn load(p: *Pardes) u8 {
+ pardes.Addon.perform(p, .load, 0, @import("test_addons").image);
+ return p.kinds.byName("image").?;
+ }
+
test "pane-local renderer choices are visible in the image tag" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
- pardes.image.start(std.testing.io, std.testing.allocator);
- defer pardes.image.stop();
// A picture shown (its decode landed, a frame drawn): the core's
// art words after the kind's `img`, then its path.
const id = p.freeSlot().?;
- const pane = try pardes.Kind.open(p, id, pardes.Kind.image, "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03");
+ const pane = try pardes.Kind.open(p, id, load(p), "/tmp/picture.ppm", "P6\n1 1\n255\n\x01\x02\x03");
while (p.nextEffect()) |e| p.perform(e);
pardes.exec.placeNew(p, 0, 0, id, .doc);
_ = try p.render(p.scratch.allocator());
pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
- try std.testing.expectEqualStrings(
- config.tag_image ++ " petscii:on palette:terminal ascii:off /tmp/picture.ppm",
- try pardes.tagline.tagPrefix(p, pane),
- );
+ try std.testing.expectEqualStrings("img petscii:on palette:terminal ascii:off /tmp/picture.ppm", try pardes.tagline.tagPrefix(p, pane));
+ }
+
+ test "an image's dump keeps its file's bytes, its renderer choices and its tag's tail" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ try pardes.panes.deinitPane(p, p.panes[0].?);
+ p.panes[0] = null;
+
+ const source = "P6\n1 1\n255\n\x0d\x4d\xe7";
+ const k = load(p);
+ const pane = try pardes.Kind.open(p, 0, k, "/missing/restored-image.ppm", source);
+ pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
+ if (pane.tag.own) |own| p.gpa.free(own);
+ pane.tag.own = try p.gpa.dupe(u8, " Keep Del");
+ try dump.dumpState(p);
+
+ // Restored where its addon is (a Restore's kinds are the process's).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const e = &p.kinds.kinds[k];
+ const brought = [_]pardes.Kind.Loaded{pardes.Kind.loadedOf(p.kinds.ops[k].?, e.path.slice(), e.hash, &words)};
+ const restored = try dump.initFromDump(gpa, .{ .tty_only = true, .addons = &brought }, p.dump_out.?);
+ defer restored.deinit();
+ const restored_pane = restored.panes[0].?;
+ const art = restored_pane.addon.?.art;
+ try std.testing.expect(art.glyph);
+ try std.testing.expectEqual(pardes.Placement.Art.Palette.terminal, art.palette);
+ try std.testing.expect(!art.ascii);
+ try std.testing.expect(restored_pane.tag.own != null);
+ try std.testing.expectEqualStrings(" Keep Del", pardes.tagline.curTail(restored_pane));
+ var kept: [64]u8 = undefined;
+ const slot = restored_pane.addon.?;
+ try std.testing.expectEqualSlices(u8, source, kept[0..slot.ops.?.dump.?(slot.st, &kept, kept.len)]);
+
+ // And dumped again, its bytes still there.
+ try dump.dumpState(restored);
+ const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null);
+ defer again.deinit();
+ // Loaded as a replica loads it: a placeholder holding the record.
+ try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?);
}
};
diff --git a/test/pdf.zig b/test/pdf.zig
index 5de72876..98e8a0ae 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -3,7 +3,6 @@ const pardes = @import("pardes");
const panes = pardes.panes;
const look = pardes.look;
const pdf_impl = panes.Pdf.pdf;
-const image = pardes.image;
const config = pardes.config;
const builtins = pardes.builtins;
const layout = pardes.layout;
@@ -23,8 +22,8 @@ const Placement = pardes.Placement;
const Shown = struct {
page: u32,
revision: u32,
- fit: image.NativeFit,
- geometry: image.NativeGeometry,
+ fit: pardes.panes.Pdf.NativeFit,
+ geometry: pardes.NativeGeometry,
pixel_offset_y: f32,
rgba: []const u8,
iw: usize,
@@ -628,7 +627,7 @@ test "MuPDF pane renders, navigates, searches, and round-trips its page" {
try std.testing.expectEqual(@as(usize, 1), first.placements.items.len);
const first_place = (try shownAll(p, frame.allocator()))[0];
try std.testing.expect(first_place.rgba.len == first_place.iw * first_place.ih * 4);
- try std.testing.expectEqual(image.NativeFit.width, first_place.fit);
+ try std.testing.expectEqual(pardes.panes.Pdf.NativeFit.width, first_place.fit);
const request = panes.Pdf.renderRequest(
panes.Pdf.paneViewport(p, pane) orelse return error.MissingPdfViewport,
pdf_raster_policy,
@@ -964,7 +963,7 @@ test "a fling's banded pages show the reader exactly what whole pages would" {
const landing = @as(f64, @floatFromInt(pv.page_starts[1] -| viewport.pixel_h / 3));
const Shot = struct {
page: u32,
- dst: image.PixelRect,
+ dst: pardes.RectPx,
pixels: []u8,
};
var shots: [8]Shot = undefined;
@@ -1190,7 +1189,7 @@ test "a tall page is drawn at the display's resolution, in bands that are the wh
fn copySourceRect(
gpa: std.mem.Allocator,
place: Shown,
- src: image.PixelRect,
+ src: pardes.RectPx,
) ![]u8 {
const stride = place.iw * 4;
const row_len = @as(usize, src.w) * 4;
@@ -1388,7 +1387,7 @@ test "PDF tint and tinted theme changes rebuild every visible raster only" {
const Snapshot = struct {
page: u32,
revision: u32,
- geometry: image.NativeGeometry,
+ geometry: pardes.NativeGeometry,
pixel_offset_y: f32,
iw: usize,
ih: usize,
diff --git a/test/process.zig b/test/process.zig
index 674996d0..0a443a21 100644
--- a/test/process.zig
+++ b/test/process.zig
@@ -512,6 +512,9 @@ pub fn of(gpa: std.mem.Allocator, h: *const eh.Harness) Files {
/// host it was built with.
pub const Backend = enum { tui, gui };
pub var backend: Backend = .tui;
+/// The image addon the build made (the runner's --image-addon=), linked
+/// into each session's data directory, where its start scan finds it.
+pub var image_addon: ?[:0]const u8 = null;
/// A case about one frontend's own behaviour (`--tty`, a killed terminal
/// editor) skips on the other.
@@ -583,6 +586,10 @@ pub const Detached = struct {
errdefer if (d.cap_len > 0) removeDir(d.captures());
const dir = d.root();
var bufs: [6][4096]u8 = undefined;
+ if (image_addon) |lib| {
+ for ([_][]const u8{ "/.local", "/.local/share", "/.local/share/pardes", "/.local/share/pardes/addons" }) |sub| _ = libc.mkdir(try std.fmt.bufPrintSentinel(&bufs[5], "{s}{s}", .{ dir, sub }, 0), 0o755);
+ _ = libc.symlink(lib, try std.fmt.bufPrintSentinel(&bufs[5], "{s}/.local/share/pardes/addons/image.so", .{dir}, 0));
+ }
if (opts.init) |text| {
const cfg = try std.fmt.bufPrintSentinel(&bufs[5], "{s}/config", .{dir}, 0);
_ = libc.mkdir(cfg, 0o755);
diff --git a/test/process_test.zig b/test/process_test.zig
index e363c78a..37dd0954 100644
--- a/test/process_test.zig
+++ b/test/process_test.zig
@@ -22,12 +22,14 @@ const files = .{
pub fn main(init: std.process.Init) !void {
const all = try init.minimal.args.toSlice(init.arena.allocator());
- // <pardes> [--backend=tui|gui] [filter]
+ // <pardes> [--backend=tui|gui] [--image-addon=<image.so>] [filter]
var args: [3][:0]const u8 = undefined;
var n: usize = 0;
for (all[1..]) |a| {
if (std.mem.startsWith(u8, a, "--backend=")) {
process.backend = std.meta.stringToEnum(process.Backend, a["--backend=".len..]) orelse return error.Usage;
+ } else if (std.mem.startsWith(u8, a, "--image-addon=")) {
+ process.image_addon = try std.Io.Dir.cwd().realPathFileAlloc(init.io, a["--image-addon=".len..], init.arena.allocator());
} else if (n < args.len) {
args[n] = a;
n += 1;
diff --git a/test/session.zig b/test/session.zig
index db33d7b0..5b608521 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -13,6 +13,8 @@ const Reply = pardes.ctlfs.Reply;
extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
pub const Session = struct {
+ /// The image addon (addons/image/image.c), as the build installs it.
+ pub const image_addon = @import("session_options").image_addon;
/// The fake addon, and its copies built wrong (build.zig).
pub const fake_addons = struct {
const o = @import("session_options");
diff --git a/test/snapshot.zig b/test/snapshot.zig
index d93face2..26022a41 100644
--- a/test/snapshot.zig
+++ b/test/snapshot.zig
@@ -86,6 +86,9 @@ var careful = false;
/// abs path of the deterministic mock language server the build handed over
/// (--lspmock=); null leaves the protocol client fully disabled for the run
var lspmock_bin: ?[:0]const u8 = null;
+/// abs path of the image addon the build made (--image-addon=), linked into
+/// each script's data directory, where a session's start scan finds it
+var image_addon: ?[:0]const u8 = null;
var record_dir: ?[]const u8 = null;
/// --tape=DIR: each session records its tape there (PARDES_RECORD, src/tape.zig)
/// and the script fails unless every tape replays without diverging.
@@ -133,6 +136,8 @@ pub fn main(init: std.process.Init) !void {
trace_stable = true;
} else if (std.mem.startsWith(u8, a, "--lspmock=")) {
lspmock = try absPath(arena, orig_cwd, a["--lspmock=".len..]);
+ } else if (std.mem.startsWith(u8, a, "--image-addon=")) {
+ image_addon = try arena.dupeSentinel(u8, try absPath(arena, orig_cwd, a["--image-addon=".len..]), 0);
} else if (std.mem.startsWith(u8, a, "--record=")) {
record_dir = try absPath(arena, orig_cwd, a["--record=".len..]);
} else if (std.mem.startsWith(u8, a, "--tape=")) {
@@ -165,6 +170,7 @@ pub fn main(init: std.process.Init) !void {
std.mem.eql(u8, a, "--no-retry") or
std.mem.eql(u8, a, "--trace-stable") or
std.mem.startsWith(u8, a, "--lspmock=") or
+ std.mem.startsWith(u8, a, "--image-addon=") or
std.mem.startsWith(u8, a, "--record=") or
std.mem.startsWith(u8, a, "--tape=") or
std.mem.eql(u8, a, "--dump") or
@@ -628,6 +634,13 @@ fn runScript(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const
// XDG directory that points outside this per-snapshot fake home.
const config_home = try std.fmt.allocPrintSentinel(arena, "{s}/.config", .{home}, 0);
_ = setenv("XDG_CONFIG_HOME", config_home, 1);
+ // ...and its data directory (dumps, the addons its start scan loads).
+ const data_home = try std.fmt.allocPrintSentinel(arena, "{s}/.local/share", .{home}, 0);
+ _ = setenv("XDG_DATA_HOME", data_home, 1);
+ if (image_addon) |lib| {
+ for ([_][]const u8{ "/.local", "/.local/share", "/.local/share/pardes", "/.local/share/pardes/addons" }) |sub| try mkdir(arena, try std.fmt.allocPrint(arena, "{s}{s}", .{ home, sub }), true);
+ if (libc.symlink(lib, try std.fmt.allocPrintSentinel(arena, "{s}/pardes/addons/image.so", .{data_home}, 0)) != 0) return error.SymlinkFailed;
+ }
// ...and it is not empty: the DEFAULT shell is $SHELL, whatever this
// machine's user logs in with (fish's prompt carries a hostname and its
// greeting a version), so a golden taken