summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/ctl.zig22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 30091ae1..d1f920a2 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -243,9 +243,10 @@ pub fn captured(p: *Pardes, req: Req, id: usize, exec: bool, text: []const u8, i
}
/// The errno a builtin's failure answers with: ENOENT for what is not
-/// there (`no such`, the words 9ns reads as ENOENT too), else EIO.
+/// there (`no such`, `not found`, the words 9ns reads as ENOENT too), else
+/// EIO.
fn failureErrno(failure: []const u8) u16 {
- return if (std.mem.indexOf(u8, failure, "no such") != null) E.NOENT else E.IO;
+ return if (std.mem.indexOf(u8, failure, "no such") != null or std.mem.indexOf(u8, failure, "not found") != null) E.NOENT else E.IO;
}
pub fn resultsLen(p: *Pardes) u64 {
@@ -1831,18 +1832,31 @@ test "Grep with no hit says grep: no match and opens nothing, a missing pane dir
var tmp = testing.tmpDir(.{});
defer tmp.cleanup();
try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "alpha\n" });
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "other.txt", .data = "one\nbravo here\nthree bravo\n" });
var dir_buf: [4096]u8 = undefined;
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
var line: [4200]u8 = undefined;
_ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/a.txt\n", .{dir}));
+ // A hit opens its +Search, a row a line: exec reads it back.
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep bravo\n").reply.status);
+ const grepped = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
+ try testing.expectEqual(@as(usize, 2), std.mem.count(u8, grepped.file.?.content, "other.txt:"));
+ try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:2") != null);
+ try testing.expect(std.mem.indexOf(u8, grepped.file.?.content, "other.txt:3") != null);
+ try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Find other\n").reply.status);
+ const found = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trimEnd(u8, rd(p, root_exec, 0, 64).bytes, "\n"), 10)).?].?;
+ try testing.expect(std.mem.indexOf(u8, found.file.?.content, "other.txt") != null);
// A second pane in a directory that is not there.
const other = try th.newPane(p);
_ = wr(p, Node.of(other, .name), "/tmp/pardes-no-such-dir-zz/b.txt\n");
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
const missed = wr(p, Node.of(serialOf(p), .exec), "Grep zzqqnomatchzz\n");
- try testing.expectEqual(E.IO, missed.errno());
- try testing.expectEqualStrings("grep: no match", missed.reply.ename);
+ try testing.expectEqual(E.NOENT, missed.errno());
+ try testing.expectEqualStrings("grep: no match, not found", missed.reply.ename);
+ const unfound = wr(p, Node.of(serialOf(p), .exec), "Find zzqqnomatchzz\n");
+ try testing.expectEqual(E.NOENT, unfound.errno());
+ try testing.expectEqualStrings("find: no match, not found", unfound.reply.ename);
var after: usize = 0;
for (p.panes) |slot| after += @intFromBool(slot != null);
try testing.expectEqual(count, after);