diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 14:40:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 15:57:07 -0300 |
| commit | 323add8ead6160dee62d48efde69fcee7b333f3a (patch) | |
| tree | 598c916b34d41b68772451bf75097b0a3a4f12e3 /test/behaviour/look_and_exec.zig | |
| parent | e20b3ab1db83298a93030faaccf41298f44452a5 (diff) | |
| download | pardes-323add8ead6160dee62d48efde69fcee7b333f3a.tar.gz pardes-323add8ead6160dee62d48efde69fcee7b333f3a.zip | |
look's host failures pinned through 9P: a T1 test (test/behaviour/look_and_exec.zig) looks at a fifo (refused, 'look: <path>: not a regular file'), at a link to nothing and at a file behind a directory it may not search (misses, said and logged, the write answered, nothing opened), and at a directory named like a file ('notes.txt:3', listed in a pane of its own), each as the host has it today: what any Look under asks or under the tape must keep
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour/look_and_exec.zig')
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 658d2483..1bc4f040 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -3,6 +3,8 @@ const std = @import("std"); const Session = @import("session").Session; const expectEqual = std.testing.expectEqual; +extern "c" fn mkfifo(path: [*:0]const u8, mode: std.c.mode_t) c_int; + test "look-and-exec: a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" { var s = try Session.initFile(std.testing.allocator, "a indented\nb\n indented\n \n"); defer s.deinit(); @@ -544,6 +546,50 @@ test "look-and-exec: a look at a file it may not read fails the write naming the try std.testing.expectEqualStrings(s.at("look: {s}: permission denied", .{path}), s.said); } +test "look-and-exec: what the host has at a path decides a look: a fifo is no file, a link to nothing and a file behind a directory it may not search are misses, a directory named like a file is listed" { + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = try tmpPath(&s, &tmp); + const before = lines(try s.read("/index")); + // A fifo: there, but no file to read whole. The write fails naming it. + const fifo = s.at("{s}/pipe\x00", .{dir}); + if (mkfifo(fifo[0 .. fifo.len - 1 :0], 0o644) != 0) return error.SkipZigTest; + try expectEqual(@as(u16, 5), try s.refused("/look", s.at("{s}/pipe\n", .{dir}))); + try std.testing.expectEqualStrings(s.at("look: {s}/pipe: not a regular file", .{dir}), s.said); + try expectEqual(before, lines(try s.read("/index"))); + // A link to nothing names no file: a miss, said and logged, the write + // answered. + try tmp.dir.symLink(io, "nowhere", "dangling", .{}); + try expectEqual(@as(u16, 0), try s.refused("/look", s.at("{s}/dangling\n", .{dir}))); + try std.testing.expect(has(try s.read("/log"), s.at("look: no match for \"{s}/dangling\"", .{dir}))); + try expectEqual(before, lines(try s.read("/index"))); + // A file behind a directory it may not search is not there to it: a miss. + try tmp.dir.createDir(io, "locked", .default_dir); + try tmp.dir.writeFile(io, .{ .sub_path = "locked/inside.txt", .data = "hidden\n" }); + const locked = s.at("{s}/locked\x00", .{dir}); + _ = std.c.chmod(locked[0 .. locked.len - 1 :0], 0o000); + defer _ = std.c.chmod(locked[0 .. locked.len - 1 :0], 0o755); + const inside = s.at("{s}/locked/inside.txt\x00", .{dir}); + // Root searches anything: that part says nothing then. + const searchable = std.c.access(inside[0 .. inside.len - 1 :0], 0) == 0; + if (!searchable) { + try expectEqual(@as(u16, 0), try s.refused("/look", s.at("{s}/locked/inside.txt\n", .{dir}))); + try std.testing.expect(has(try s.read("/log"), s.at("look: no match for \"{s}/locked/inside.txt\"", .{dir}))); + try expectEqual(before, lines(try s.read("/index"))); + } + // A directory where a file's name is wanted (`notes.txt`, `notes.txt:3`): + // a directory all the same, listed in a pane of its own. + try tmp.dir.createDir(io, "notes.txt", .default_dir); + try tmp.dir.writeFile(io, .{ .sub_path = "notes.txt/a", .data = "" }); + try s.write("/look", s.at("{s}/notes.txt:3\n", .{dir})); + const shown = try s.focused(); + try s.expect(s.at("/pane/{d}/name", .{shown}), s.at("{s}/notes.txt/\n", .{dir})); + try s.expect(s.at("/pane/{d}/body", .{shown}), "a\n"); +} + test "look-and-exec: a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); |
