From d23f320d7e6d78fedc0f8d53fe59cef2c8956768 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 19 Nov 2026 02:56:37 +0000 Subject: [PATCH] test(proc): add direct coverage for which `proc.which` searches the given PATH string for an executable regular file, and `src/proc.zig` exercises it only through `resolveExecutable`. The new test `which resolves executable candidates directly` in `src/proc.zig` passes the `makeExecFixture` directory as the search path. It checks that `tool.sh` resolves to its absolute path and that both `plain.txt` and an absent name return null. --- changelog.d/+proc-which-direct.misc.md | 1 + src/proc.zig | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 changelog.d/+proc-which-direct.misc.md diff --git a/changelog.d/+proc-which-direct.misc.md b/changelog.d/+proc-which-direct.misc.md new file mode 100644 index 0000000..104037c --- /dev/null +++ b/changelog.d/+proc-which-direct.misc.md @@ -0,0 +1 @@ +`proc.which` tests cover executable resolution and null returns for non-executable candidates. diff --git a/src/proc.zig b/src/proc.zig index eb43d04..c4b1af4 100644 --- a/src/proc.zig +++ b/src/proc.zig @@ -806,3 +806,19 @@ test "resolveExecutable handles relative slash paths" { defer gpa.free(rel_plain); try std.testing.expectEqual(@as(?[]u8, null), try resolveExecutable(gpa, rel_plain, null)); } + +test "which resolves executable candidates directly" { + const gpa = std.testing.allocator; + const fixture = try makeExecFixture(gpa, "which"); + defer gpa.free(fixture.plain_path); + defer gpa.free(fixture.exe_path); + defer gpa.free(fixture.base); + defer fsx.deleteTree(gpa, fsx.cwd, fixture.base) catch {}; + + const found = (try which(gpa, "tool.sh", fixture.base)).?; + defer gpa.free(found); + try std.testing.expectEqualStrings(fixture.exe_path, found); + + try std.testing.expectEqual(@as(?[]u8, null), try which(gpa, "plain.txt", fixture.base)); + try std.testing.expectEqual(@as(?[]u8, null), try which(gpa, "not-present-tool", fixture.base)); +}