From 09571f2e2d9fd5402dbae15f4029d9e1d807e882 Mon Sep 17 00:00:00 2001 From: Techatrix Date: Thu, 26 Dec 2024 05:58:42 +0100 Subject: [PATCH] windows moment --- tests/build_runner_check.zig | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/build_runner_check.zig b/tests/build_runner_check.zig index e11dd8eee..37c518b7c 100644 --- a/tests/build_runner_check.zig +++ b/tests/build_runner_check.zig @@ -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, "\\\\", "/"); },