mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
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.
This commit is contained in:
parent
dd75e7bcb1
commit
5c8b92db7f
5 changed files with 7 additions and 19 deletions
|
|
@ -29,17 +29,12 @@ fn run(allocator: std.mem.Allocator) !void {
|
||||||
return error.BadUsage;
|
return error.BadUsage;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!std.fs.path.isAbsolute(dir_path)) {
|
|
||||||
std.log.err("expected <dir> to be an absolute path", .{});
|
|
||||||
return error.BadUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
const relpath = args.next() orelse {
|
const relpath = args.next() orelse {
|
||||||
std.log.err("missing <path> argument", .{});
|
std.log.err("missing <path> argument", .{});
|
||||||
return error.BadUsage;
|
return error.BadUsage;
|
||||||
};
|
};
|
||||||
|
|
||||||
var dir = try std.fs.openDirAbsolute(dir_path, .{});
|
var dir = try std.fs.cwd().openDir(dir_path, .{});
|
||||||
defer dir.close();
|
defer dir.close();
|
||||||
|
|
||||||
_ = try dir.statFile(relpath);
|
_ = try dir.statFile(relpath);
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,6 @@ fn run(allocator: std.mem.Allocator) !void {
|
||||||
return error.BadUsage;
|
return error.BadUsage;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!std.fs.path.isAbsolute(path)) {
|
|
||||||
std.log.err("path must be absolute", .{});
|
|
||||||
return error.BadUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
const basename = args.next() orelse {
|
const basename = args.next() orelse {
|
||||||
std.log.err("missing <basename> argument", .{});
|
std.log.err("missing <basename> argument", .{});
|
||||||
return error.BadUsage;
|
return error.BadUsage;
|
||||||
|
|
|
||||||
|
|
@ -26,15 +26,10 @@ fn run(allocator: std.mem.Allocator) !void {
|
||||||
return error.BadUsage;
|
return error.BadUsage;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!std.fs.path.isAbsolute(path)) {
|
|
||||||
std.log.err("path must be absolute: {s}", .{path});
|
|
||||||
return error.BadUsage;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dir_path = std.fs.path.dirname(path) orelse unreachable;
|
const dir_path = std.fs.path.dirname(path) orelse unreachable;
|
||||||
const basename = std.fs.path.basename(path);
|
const basename = std.fs.path.basename(path);
|
||||||
|
|
||||||
var dir = try std.fs.openDirAbsolute(dir_path, .{});
|
var dir = try std.fs.cwd().openDir(dir_path, .{});
|
||||||
defer dir.close();
|
defer dir.close();
|
||||||
|
|
||||||
_ = dir.statFile(basename) catch {
|
_ = dir.statFile(basename) catch {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ pub fn main() !void {
|
||||||
var args = try std.process.argsWithAllocator(std.heap.page_allocator);
|
var args = try std.process.argsWithAllocator(std.heap.page_allocator);
|
||||||
_ = args.skip();
|
_ = args.skip();
|
||||||
const filename = args.next().?;
|
const filename = args.next().?;
|
||||||
const file = try std.fs.createFileAbsolute(filename, .{});
|
const file = try std.fs.cwd().createFile(filename, .{});
|
||||||
defer file.close();
|
defer file.close();
|
||||||
try file.writeAll(filename);
|
try file.writeAll(filename);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,8 @@ pub fn main() anyerror!void {
|
||||||
const exe_path = it.next() orelse unreachable;
|
const exe_path = it.next() orelse unreachable;
|
||||||
const symlink_path = it.next() orelse unreachable;
|
const symlink_path = it.next() orelse unreachable;
|
||||||
|
|
||||||
try std.fs.cwd().symLink(exe_path, symlink_path, .{});
|
// If `exe_path` is relative to our cwd, we need to convert it to be relative to the dirname of `symlink_path`.
|
||||||
|
const exe_rel_path = try std.fs.path.relative(allocator, std.fs.path.dirname(symlink_path) orelse ".", exe_path);
|
||||||
|
defer allocator.free(exe_rel_path);
|
||||||
|
try std.fs.cwd().symLink(exe_rel_path, symlink_path, .{});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue