From 24a3537ef863cfc724f63609af97ba8ca2b5c805 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 7 Mar 2026 21:37:19 +0100 Subject: [PATCH 1/2] fix(windows): use proper temp dir for testing on windows --- src/nightwatch_test.zig | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/nightwatch_test.zig b/src/nightwatch_test.zig index aec0721..ebada03 100644 --- a/src/nightwatch_test.zig +++ b/src/nightwatch_test.zig @@ -145,15 +145,18 @@ var temp_dir_counter = std.atomic.Value(u32).init(0); /// Create a fresh temporary directory and return its absolute path (caller frees). fn makeTempDir(allocator: std.mem.Allocator) ![]u8 { const n = temp_dir_counter.fetchAdd(1, .monotonic); - const name = try std.fmt.allocPrint( - allocator, - "/tmp/nightwatch_test_{d}_{d}", - .{ switch (builtin.os.tag) { - .linux => std.os.linux.getpid(), - .windows => std.os.windows.GetCurrentProcessId(), - else => std.c.getpid(), - }, n }, - ); + const pid = switch (builtin.os.tag) { + .linux => std.os.linux.getpid(), + .windows => std.os.windows.GetCurrentProcessId(), + else => std.c.getpid(), + }; + const name = if (builtin.os.tag == .windows) blk: { + const tmp_dir = std.process.getEnvVarOwned(allocator, "TEMP") catch + try std.process.getEnvVarOwned(allocator, "TMP"); + defer allocator.free(tmp_dir); + break :blk try std.fmt.allocPrint(allocator, "{s}\\nightwatch_test_{d}_{d}", .{ tmp_dir, pid, n }); + } else + try std.fmt.allocPrint(allocator, "/tmp/nightwatch_test_{d}_{d}", .{ pid, n }); errdefer allocator.free(name); try std.fs.makeDirAbsolute(name); return name; From 849138902301910f39e3b9d61fd54979da9171ae Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 7 Mar 2026 21:38:11 +0100 Subject: [PATCH 2/2] fix(windows): use cross platform path join to fix tests on windows --- src/nightwatch_test.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nightwatch_test.zig b/src/nightwatch_test.zig index ebada03..a4917ae 100644 --- a/src/nightwatch_test.zig +++ b/src/nightwatch_test.zig @@ -197,7 +197,7 @@ test "creating a file emits a 'created' event" { defer watcher.deinit(); try watcher.watch(tmp); - const file_path = try std.fmt.allocPrint(allocator, "{s}/hello.txt", .{tmp}); + const file_path = try std.fs.path.join(allocator, &.{ tmp, "hello.txt" }); defer allocator.free(file_path); { const f = try std.fs.createFileAbsolute(file_path, .{}); @@ -222,7 +222,7 @@ test "writing to a file emits a 'modified' event" { defer th.deinit(); // Create the file before setting up the watcher to start from a clean slate. - const file_path = try std.fmt.allocPrint(allocator, "{s}/data.txt", .{tmp}); + const file_path = try std.fs.path.join(allocator, &.{ tmp, "data.txt" }); defer allocator.free(file_path); { const f = try std.fs.createFileAbsolute(file_path, .{}); @@ -256,7 +256,7 @@ test "deleting a file emits a 'deleted' event" { const th = try TestHandler.init(allocator); defer th.deinit(); - const file_path = try std.fmt.allocPrint(allocator, "{s}/gone.txt", .{tmp}); + const file_path = try std.fs.path.join(allocator, &.{ tmp, "gone.txt" }); defer allocator.free(file_path); { const f = try std.fs.createFileAbsolute(file_path, .{}); @@ -290,7 +290,7 @@ test "creating a sub-directory emits a 'dir_created' event" { defer watcher.deinit(); try watcher.watch(tmp); - const dir_path = try std.fmt.allocPrint(allocator, "{s}/subdir", .{tmp}); + const dir_path = try std.fs.path.join(allocator, &.{ tmp, "subdir" }); defer allocator.free(dir_path); try std.fs.makeDirAbsolute(dir_path);