diff --git a/src/nightwatch_test.zig b/src/nightwatch_test.zig index a4917ae..0b33985 100644 --- a/src/nightwatch_test.zig +++ b/src/nightwatch_test.zig @@ -311,9 +311,9 @@ test "renaming a file is reported correctly per-platform" { const th = try TestHandler.init(allocator); defer th.deinit(); - const src_path = try std.fmt.allocPrint(allocator, "{s}/before.txt", .{tmp}); + const src_path = try std.fs.path.join(allocator, &.{ tmp, "before.txt" }); defer allocator.free(src_path); - const dst_path = try std.fmt.allocPrint(allocator, "{s}/after.txt", .{tmp}); + const dst_path = try std.fs.path.join(allocator, &.{ tmp, "after.txt" }); defer allocator.free(dst_path); { @@ -361,7 +361,7 @@ test "an unwatched directory produces no events" { defer watcher.deinit(); try watcher.watch(watched); // only watch the first dir - const file_path = try std.fmt.allocPrint(allocator, "{s}/silent.txt", .{unwatched}); + const file_path = try std.fs.path.join(allocator, &.{ unwatched, "silent.txt" }); defer allocator.free(file_path); { const f = try std.fs.createFileAbsolute(file_path, .{}); @@ -390,7 +390,7 @@ test "unwatch stops delivering events for that directory" { try watcher.watch(tmp); // Create a file while watching - should be reported. - const file1 = try std.fmt.allocPrint(allocator, "{s}/watched.txt", .{tmp}); + const file1 = try std.fs.path.join(allocator, &.{ tmp, "watched.txt" }); defer allocator.free(file1); { const f = try std.fs.createFileAbsolute(file1, .{}); @@ -403,7 +403,7 @@ test "unwatch stops delivering events for that directory" { watcher.unwatch(tmp); const count_before = th.events.items.len; - const file2 = try std.fmt.allocPrint(allocator, "{s}/after_unwatch.txt", .{tmp}); + const file2 = try std.fs.path.join(allocator, &.{ tmp, "after_unwatch.txt" }); defer allocator.free(file2); { const f = try std.fs.createFileAbsolute(file2, .{}); @@ -433,7 +433,9 @@ test "multiple files created sequentially all appear in the event list" { const N = 5; var paths: [N][]u8 = undefined; for (&paths, 0..) |*p, i| { - p.* = try std.fmt.allocPrint(allocator, "{s}/file{d}.txt", .{ tmp, i }); + const name = try std.fmt.allocPrint(allocator, "file{d}.txt", .{i}); + defer allocator.free(name); + p.* = try std.fs.path.join(allocator, &.{ tmp, name }); const f = try std.fs.createFileAbsolute(p.*, .{}); f.close(); } @@ -463,9 +465,9 @@ test "rename: old-name event precedes new-name event" { const th = try TestHandler.init(allocator); defer th.deinit(); - const src_path = try std.fmt.allocPrint(allocator, "{s}/old.txt", .{tmp}); + const src_path = try std.fs.path.join(allocator, &.{ tmp, "old.txt" }); defer allocator.free(src_path); - const dst_path = try std.fmt.allocPrint(allocator, "{s}/new.txt", .{tmp}); + const dst_path = try std.fs.path.join(allocator, &.{ tmp, "new.txt" }); defer allocator.free(dst_path); { @@ -506,9 +508,9 @@ test "rename-then-modify: rename event precedes the subsequent modify event" { const th = try TestHandler.init(allocator); defer th.deinit(); - const src_path = try std.fmt.allocPrint(allocator, "{s}/original.txt", .{tmp}); + const src_path = try std.fs.path.join(allocator, &.{ tmp, "original.txt" }); defer allocator.free(src_path); - const dst_path = try std.fmt.allocPrint(allocator, "{s}/renamed.txt", .{tmp}); + const dst_path = try std.fs.path.join(allocator, &.{ tmp, "renamed.txt" }); defer allocator.free(dst_path); { diff --git a/test_manual.ps1 b/test_manual.ps1 new file mode 100644 index 0000000..1d65abf --- /dev/null +++ b/test_manual.ps1 @@ -0,0 +1,64 @@ +# Manual test for nightwatch CLI. +# Usage: .\test_manual.ps1 [path-to-nightwatch-binary] +# +# Run this in one terminal. It starts nightwatch watching a temp dir, +# performs a sequence of filesystem operations, then exits. +# You should see one event per line on stdout as they happen. + +param( + [string]$NW = ".\zig-out\bin\nightwatch.exe" +) + +if (-not (Test-Path $NW)) { + Write-Error "error: binary not found: $NW" + exit 1 +} + +$TESTDIR = Join-Path $env:TEMP "nightwatch_manual_$PID" +New-Item -ItemType Directory -Path $TESTDIR | Out-Null + +Write-Host "--- watching $TESTDIR ---" +Write-Host "--- starting nightwatch (Ctrl-C to stop early) ---" +Write-Host "" + +# Start nightwatch in background, events go to stdout +$proc = Start-Process -FilePath $NW -ArgumentList $TESTDIR -NoNewWindow -PassThru +Start-Sleep -Milliseconds 500 + +Write-Host "[op] touch file1.txt" +New-Item -ItemType File -Path "$TESTDIR\file1.txt" | Out-Null +Start-Sleep -Milliseconds 400 + +Write-Host "[op] write to file1.txt" +Set-Content -Path "$TESTDIR\file1.txt" -Value "hello nightwatch" +Start-Sleep -Milliseconds 400 + +Write-Host "[op] mkdir subdir" +New-Item -ItemType Directory -Path "$TESTDIR\subdir" | Out-Null +Start-Sleep -Milliseconds 400 + +Write-Host "[op] touch subdir\file2.txt" +New-Item -ItemType File -Path "$TESTDIR\subdir\file2.txt" | Out-Null +Start-Sleep -Milliseconds 400 + +Write-Host "[op] rename file1.txt -> renamed.txt" +Rename-Item -Path "$TESTDIR\file1.txt" -NewName "renamed.txt" +Start-Sleep -Milliseconds 400 + +Write-Host "[op] delete renamed.txt" +Remove-Item -Path "$TESTDIR\renamed.txt" +Start-Sleep -Milliseconds 400 + +Write-Host "[op] delete subdir\file2.txt" +Remove-Item -Path "$TESTDIR\subdir\file2.txt" +Start-Sleep -Milliseconds 400 + +Write-Host "[op] rmdir subdir" +Remove-Item -Path "$TESTDIR\subdir" +Start-Sleep -Milliseconds 500 + +Write-Host "" +Write-Host "--- done, stopping nightwatch ---" +Stop-Process -Id $proc.Id -ErrorAction SilentlyContinue +$proc.WaitForExit() +Remove-Item -Recurse -Force -Path $TESTDIR