Skip to content

Commit 5c8b92d

Browse files
committed
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.
1 parent dd75e7b commit 5c8b92d

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

test/standalone/dirname/exists_in.zig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)