Skip to content

Commit

Permalink
windows moment
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed Dec 26, 2024
1 parent 9f24966 commit 09571f2
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions tests/build_runner_check.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@ pub fn main() !u8 {
std.debug.panic("could no open/read file '{s}': {}", .{ args[2], err });
defer gpa.free(actual_unsanitized);

// The build runner will produce absolute paths in the output so we remove them here.
// We also convert windows style '\' path seperators to posix style '/'.
const actual = blk: {
const sep = switch (std.fs.path.sep) {
std.fs.path.sep_posix => "/",
std.fs.path.sep_windows => "\\\\",
else => unreachable,
};
var base_dir_buffer: std.ArrayListUnmanaged(u8) = .{};
defer base_dir_buffer.deinit(gpa);

const base_dir = try std.fmt.allocPrint(gpa, "{s}{s}", .{ args[3], sep });
defer gpa.free(base_dir);
try std.json.encodeJsonStringChars(args[3], .{}, base_dir_buffer.writer(gpa));
try std.json.encodeJsonStringChars(&.{std.fs.path.sep}, .{}, base_dir_buffer.writer(gpa));

const actual = try std.mem.replaceOwned(u8, gpa, actual_unsanitized, base_dir, "");
// The build runner will produce absolute paths in the output so we remove them here.
const actual = try std.mem.replaceOwned(u8, gpa, actual_unsanitized, base_dir_buffer.items, "");

// We also convert windows style '\\' path separators to posix style '/'.
switch (std.fs.path.sep) {
std.fs.path.sep_posix => break :blk actual,
std.fs.path.sep_windows => {
'/' => break :blk actual,
'\\' => {
defer gpa.free(actual);
break :blk try std.mem.replaceOwned(u8, gpa, actual, "\\\\", "/");
},
Expand Down

0 comments on commit 09571f2

Please sign in to comment.