diff options
| -rw-r--r-- | build/tests.zig | 8 | ||||
| -rw-r--r-- | test/replicas.zig | 31 |
2 files changed, 31 insertions, 8 deletions
diff --git a/build/tests.zig b/build/tests.zig index 5e913501..8cf42acd 100644 --- a/build/tests.zig +++ b/build/tests.zig @@ -148,7 +148,8 @@ pub fn add(b: *std.Build, c: struct { // The replicas' soak, its clients showing a picture, a game of life and // a PDF (docs/design.pdf) from these libraries, as a user's addons are // loaded. - const replicas = program(b, "pardes-replicas", "test/replicas.zig", c.target, c.optimize, &.{ .{ .name = "pardes", .module = c.core_module }, .{ .name = "runtime", .module = c.core_runtime }, .{ .name = "term", .module = c.parts.term } }); + const replicas_imports: []const std.Build.Module.Import = &.{ .{ .name = "pardes", .module = c.core_module }, .{ .name = "runtime", .module = c.core_runtime }, .{ .name = "term", .module = c.parts.term } }; + const replicas = program(b, "pardes-replicas", "test/replicas.zig", c.target, c.optimize, replicas_imports); const run_replicas = b.addRunArtifact(replicas); for ([_]?*std.Build.Step.Compile{ c.image_addon, life_lib, c.pdf_addon }) |l| if (l) |lib| { run_replicas.addArg("--addon"); @@ -160,7 +161,10 @@ pub fn add(b: *std.Build, c: struct { } run_replicas.addPassthruArgs(); run_replicas.has_side_effects = true; - b.step("replicas", "one authority and several replicas in process, each client typing over a delayed link: digests at quiescence, rollback rate and costs per RTT (-- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207])").dependOn(&run_replicas.step); + const replicas_step = b.step("replicas", "one authority and several replicas in process, each client typing over a delayed link: digests at quiescence, rollback rate and costs per RTT (-- [--seeds N] [--steps M] [--clients C] [--rtt 30,80,207])"); + replicas_step.dependOn(&run_replicas.step); + // Its typist's own tests (what it never types), with every soak and unit-test. + _ = units.add(b, units.root(b, "test/replicas.zig", true, replicas_imports), replicas_step); for ([_]*std.Build.Module{ snake_mod, life_mod, liar_mod, c.parts.image }) |m| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = m })).step); if (c.pdf_addon) |lib| addon_test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = lib.root_module })).step); // ...and the pdf addon's, which mupdf-check runs too (its script diff --git a/test/replicas.zig b/test/replicas.zig index cd0a3459..65e6a0ba 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -334,12 +334,11 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const 0...15 => { buf[0] = typed[random.uintLessThan(usize, typed.len)]; if (buf[0] == 'q' and script.space) buf[0] = 'r'; - script.space = buf[0] == ' '; + script.space = script.space or buf[0] == ' '; return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } }; }, 16...27 => { buf[0] = normal[random.uintLessThan(usize, normal.len)]; - script.space = false; return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } }; }, 28...31 => { @@ -393,7 +392,7 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const // A search in the pane with the keyboard (a PDF's `/` is its own): // `/`, a pattern, Enter. 41 => { - script.* = .{ .n = 2, .evs = .{ .{ .paste = ([_][]const u8{ "the", "view", "pardes" })[random.uintLessThan(usize, 3)] }, .{ .key = .{ .cp = Key.enter } }, undefined } }; + script.* = .{ .n = 2, .evs = .{ .{ .paste = ([_][]const u8{ "the", "view", "pardes" })[random.uintLessThan(usize, 3)] }, .{ .key = .{ .cp = Key.enter } }, undefined }, .space = script.space }; return .{ .key = .{ .cp = '/', .text = "/" } }; }, // A sweep of B1 over the PDF: a selection (or a page's pan, or nothing). @@ -403,7 +402,7 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const const y = at[1] + random.uintLessThan(u16, at[3]); const x1 = at[0] + random.uintLessThan(u16, at[2]); const y1 = @min(at[1] + at[3] - 1, y + random.uintLessThan(u16, 3)); - script.* = .{ .n = 2, .evs = .{ .{ .mouse = .{ .button = .left, .kind = .drag, .col = x1, .row = y1 } }, .{ .mouse = .{ .button = .left, .kind = .release, .col = x1, .row = y1 } }, undefined } }; + script.* = .{ .n = 2, .evs = .{ .{ .mouse = .{ .button = .left, .kind = .drag, .col = x1, .row = y1 } }, .{ .mouse = .{ .button = .left, .kind = .release, .col = x1, .row = y1 } }, undefined }, .space = script.space }; return .{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = y } }; }, // The wheel over the shell, which scrolls its history into view, @@ -426,8 +425,10 @@ const Script = struct { evs: [3]pardes.Event = undefined, n: u8 = 0, at: u8 = 0, - /// Its last key was a space: Space then q is Exit (config.zig's - /// leader), which ends the session and the run with it. + /// A space typed and no Esc since: SPC's level may be open (it stays + /// over a key it has no child for, keys.zig `leaderKey`, and Backspace + /// takes it back up), and q in it is Exit (config.zig's leader), which + /// ends the session and the run with it. space: bool = false, }; @@ -3664,3 +3665,21 @@ fn corpusCase(dir: []const u8) !bool { std.debug.print("corpus through a client: {d} scenes, the own frontend drew {d} frames and the client {d}; {s}\n", .{ steps.len, own_host.shown.frames, shows.shown.frames, if (ok) "every scene's frame the same" else "FAILED" }); return ok; } + +test "the typist types no q while a leader its space opened may be open: from its space to its next Esc (SPC 7 o q was Exit)" { + var prng: std.Random.DefaultPrng = .init(109); + var script: Script = .{}; + var buf: [64]u8 = undefined; + // SPC's level stays open over a key it has no child for (keys.zig + // `leaderKey`), and Backspace takes it back up: Esc is the typist's + // one key sure to leave it. + var open = false; + for (0..200_000) |_| switch (nextEvent(prng.random(), &buf, .{ .shell = null, .pdf = null }, &.{"Look"}, &script, false, true)) { + .key => |k| { + if (open and k.cp == 'q') return error.TestUnexpectedResult; + if (k.cp == ' ') open = true; + if (k.cp == Key.escape) open = false; + }, + else => {}, + }; +} |
