diff options
Diffstat (limited to 'src/ninep/addr.zig')
| -rw-r--r-- | src/ninep/addr.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ninep/addr.zig b/src/ninep/addr.zig index df2cfaf0..b78c46e7 100644 --- a/src/ninep/addr.zig +++ b/src/ninep/addr.zig @@ -498,6 +498,28 @@ test "regular expressions search lines as sam's do, and a search wraps" { try testing.expectEqual(@as(u32, 5), q.panes[0].?.fs.addr.q0); } +test "a refused write to dot after a truncation changes nothing; a truncation with no write empties it at close" { + const p = try th.withFile(testing.allocator, "one\ntwo\nthree\n"); + defer p.deinit(); + const serial = th.serialOf(p); + const dot = Node.of(serial, .dot); + try testing.expectEqual(Status.ok, th.wr(p, dot, "2").reply.status); + const was = th.rd(p, dot, 0, 64).bytes; + var kept: [64]u8 = undefined; + @memcpy(kept[0..was.len], was); + // A shell's `echo /nomatch/ > dot`: truncate, then the refused write. + const h = th.call(p, .{ .tag = 1, .op = .open, .node = dot, .omode = 1 }).reply.handle; + _ = th.call(p, .{ .tag = 2, .op = .setattr, .node = dot, .truncate = true }); + try testing.expectEqual(Status.err, th.call(p, .{ .tag = 3, .op = .write, .node = dot, .handle = h, .data = "/nomatch/" }).reply.status); + _ = th.call(p, .{ .tag = 4, .op = .release, .node = dot, .handle = h, .opened = true }); + try testing.expectEqualStrings(kept[0..was.len], th.rd(p, dot, 0, 64).bytes); + // `: > dot`: the truncation alone empties it once its open goes. + const h2 = th.call(p, .{ .tag = 5, .op = .open, .node = dot, .omode = 1 }).reply.handle; + _ = th.call(p, .{ .tag = 6, .op = .setattr, .node = dot, .truncate = true }); + _ = th.call(p, .{ .tag = 7, .op = .release, .node = dot, .handle = h2, .opened = true }); + try testing.expectEqualStrings(" 0 0 ", th.rd(p, dot, 0, 64).bytes); +} + test "a failed address leaves none, so data refuses rather than act at the last one" { const p = try th.withFile(testing.allocator, "one\ntwo\n"); defer p.deinit(); |
