authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-05 12:13:31+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-13 15:46:43+01:00
log5c8b92db7f6e99d075af1cf87d48a5af0c748603
tree6ce024041d0806fac93d26ad8b58fcde85c6877f
parentdd75e7bcb1fe142f4d60dc2d83e6feee53e580f3
signaturelock-open Commit is signed but in an unrecognized format.

tests: do not require absolute paths from the build system

File arguments added to `std.Build.Step.Run` with e.g. `addFileArg` are not necessarily passed as absolute paths. It used to be the case that they were as a consequence of an unnecessary path conversion done by the frontend, but this no longer happens, at least not always, so these tests were sometimes failing when run locally. Therefore, the standalone tests must handle cwd-relative CLI paths correctly.

5 files changed, 7 insertions(+), 19 deletions(-)

test/standalone/dirname/exists_in.zig+1-6
......@@ -29,17 +29,12 @@ fn run(allocator: std.mem.Allocator) !void {
2929 return error.BadUsage;
3030 };
3131
32 if (!std.fs.path.isAbsolute(dir_path)) {
33 std.log.err("expected <dir> to be an absolute path", .{});
34 return error.BadUsage;
35 }
36
3732 const relpath = args.next() orelse {
3833 std.log.err("missing <path> argument", .{});
3934 return error.BadUsage;
4035 };
4136
42 var dir = try std.fs.openDirAbsolute(dir_path, .{});
37 var dir = try std.fs.cwd().openDir(dir_path, .{});
4338 defer dir.close();
4439
4540 _ = try dir.statFile(relpath);
test/standalone/dirname/has_basename.zig-5
......@@ -31,11 +31,6 @@ fn run(allocator: std.mem.Allocator) !void {
3131 return error.BadUsage;
3232 };
3333
34 if (!std.fs.path.isAbsolute(path)) {
35 std.log.err("path must be absolute", .{});
36 return error.BadUsage;
37 }
38
3934 const basename = args.next() orelse {
4035 std.log.err("missing <basename> argument", .{});
4136 return error.BadUsage;
test/standalone/dirname/touch.zig+1-6
......@@ -26,15 +26,10 @@ fn run(allocator: std.mem.Allocator) !void {
2626 return error.BadUsage;
2727 };
2828
29 if (!std.fs.path.isAbsolute(path)) {
30 std.log.err("path must be absolute: {s}", .{path});
31 return error.BadUsage;
32 }
33
3429 const dir_path = std.fs.path.dirname(path) orelse unreachable;
3530 const basename = std.fs.path.basename(path);
3631
37 var dir = try std.fs.openDirAbsolute(dir_path, .{});
32 var dir = try std.fs.cwd().openDir(dir_path, .{});
3833 defer dir.close();
3934
4035 _ = dir.statFile(basename) catch {
test/standalone/run_output_caching/main.zig+1-1
......@@ -4,7 +4,7 @@ pub fn main() !void {
44 var args = try std.process.argsWithAllocator(std.heap.page_allocator);
55 _ = args.skip();
66 const filename = args.next().?;
7 const file = try std.fs.createFileAbsolute(filename, .{});
7 const file = try std.fs.cwd().createFile(filename, .{});
88 defer file.close();
99 try file.writeAll(filename);
1010}
test/standalone/self_exe_symlink/create-symlink.zig+4-1
......@@ -11,5 +11,8 @@ pub fn main() anyerror!void {
1111 const exe_path = it.next() orelse unreachable;
1212 const symlink_path = it.next() orelse unreachable;
1313
14 try std.fs.cwd().symLink(exe_path, symlink_path, .{});
14 // If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
15 const exe_rel_path = try std.fs.path.relative(allocator, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
16 defer allocator.free(exe_rel_path);
17 try std.fs.cwd().symLink(exe_rel_path, symlink_path, .{});
1518}