diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/look.zig | 4 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 16 | ||||
| -rw-r--r-- | src/ninep/tree.zig | 8 |
3 files changed, 20 insertions, 8 deletions
diff --git a/src/look.zig b/src/look.zig index 0f5103ba..19b320f9 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1401,8 +1401,10 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text: var said: [4200]u8 = undefined; const gone = if (comptime pardes.hosted) if (filesystem.localPath(dir)) |local| !exec.isDirectory(local) else false else true; if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch "look: no such directory"); + // A file not there is a miss, as `x` and `/abs/x` are: said and + // logged, the write answered with nothing. var cut: [miss_path_cap + "…".len]u8 = undefined; - return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such file", .{missText(trimmed, &cut)}) catch "look: no such file"); + return missed(p, id, "{s}: no such file", .{missText(trimmed, &cut)}); } // A raw terminal's clicks are its program's; a look written over // 9P is no keyboard input, and searches whatever the key mode. diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 6c9ee2da..2b366de0 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -3224,7 +3224,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt try testing.expect(std.mem.indexOf(u8, rd(p, @intFromEnum(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null); } -test "a look at a ./ or ../ name that is not there names the file, ENOENT; a plain one is looked for as text" { +test "a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); var tmp = testing.tmpDir(.{}); @@ -3236,9 +3236,9 @@ test "a look at a ./ or ../ name that is not there names the file, ENOENT; a pla _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/many/a.txt\n", .{dir})); for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| { const r = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}\n", .{name})); - try testing.expectEqual(E.NOENT, r.errno()); + try testing.expectEqual(Status.ok, r.reply.status); var want: [64]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "look: {s}: no such file", .{name}), r.reply.ename); + try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "look: {s}: no such file", .{name}))); } try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .look), "zz.txt\n").reply.status); try testing.expect(th.logHas(p, "look: no match for \"zz.txt\"")); @@ -4323,3 +4323,13 @@ test "a collapsed pane's ctl says so" { try testing.expect(p.panes[id].?.collapsed); try testing.expect(std.mem.endsWith(u8, rd(p, Node.of(serialOf(p), .ctl), 0, 4096).bytes, " collapsed ")); } + +test "a look of ./x that is not there is a miss, as x and /abs/x are: answered, the err logged" { + const p = try withFile(testing.allocator, "x\n"); + defer p.deinit(); + for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| { + const r = wr(p, Node.of(serialOf(p), .look), line); + try testing.expectEqual(Status.ok, r.reply.status); + } + try testing.expect(th.logHas(p, "look: ./zzq-nosuch.txt: no such file")); +} diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index e5d1c848..e566482c 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -495,14 +495,14 @@ test "a reason past 128 bytes keeps its end: the path in it gives up its middle" const words = "why " ** 40 ++ "the reason"; try testing.expect(std.mem.endsWith(u8, fitErr(words, &out), "the reason")); try testing.expectEqualStrings("short", fitErr("short", &out)); - // Through the tree: a look at a long ./ name not there says why at the end. + // Through the tree: a look at a long ./ name not there, a miss, says + // why at the end of its err record, the name giving up its middle. const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); var line: [512]u8 = undefined; const r = th.wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "./{s}x.txt\n", .{"no-such-dir/" ** 20})); - try testing.expectEqual(Status.err, r.reply.status); - try testing.expect(r.reply.ename.len <= 128); - try testing.expect(std.mem.endsWith(u8, r.reply.ename, "no such file") or std.mem.endsWith(u8, r.reply.ename, "no such directory")); + try testing.expectEqual(Status.ok, r.reply.status); + try testing.expect(th.logHas(p, "x.txt: no such file")); } /// A refusal with no reason of its own said in Plan 9's words, not the C |
