Compare commits
2 commits
240f3f148f
...
8491389023
| Author | SHA1 | Date | |
|---|---|---|---|
| 8491389023 | |||
| 24a3537ef8 |
1 changed files with 16 additions and 13 deletions
|
|
@ -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).
|
/// Create a fresh temporary directory and return its absolute path (caller frees).
|
||||||
fn makeTempDir(allocator: std.mem.Allocator) ![]u8 {
|
fn makeTempDir(allocator: std.mem.Allocator) ![]u8 {
|
||||||
const n = temp_dir_counter.fetchAdd(1, .monotonic);
|
const n = temp_dir_counter.fetchAdd(1, .monotonic);
|
||||||
const name = try std.fmt.allocPrint(
|
const pid = switch (builtin.os.tag) {
|
||||||
allocator,
|
.linux => std.os.linux.getpid(),
|
||||||
"/tmp/nightwatch_test_{d}_{d}",
|
.windows => std.os.windows.GetCurrentProcessId(),
|
||||||
.{ switch (builtin.os.tag) {
|
else => std.c.getpid(),
|
||||||
.linux => std.os.linux.getpid(),
|
};
|
||||||
.windows => std.os.windows.GetCurrentProcessId(),
|
const name = if (builtin.os.tag == .windows) blk: {
|
||||||
else => std.c.getpid(),
|
const tmp_dir = std.process.getEnvVarOwned(allocator, "TEMP") catch
|
||||||
}, n },
|
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);
|
errdefer allocator.free(name);
|
||||||
try std.fs.makeDirAbsolute(name);
|
try std.fs.makeDirAbsolute(name);
|
||||||
return name;
|
return name;
|
||||||
|
|
@ -194,7 +197,7 @@ test "creating a file emits a 'created' event" {
|
||||||
defer watcher.deinit();
|
defer watcher.deinit();
|
||||||
try watcher.watch(tmp);
|
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);
|
defer allocator.free(file_path);
|
||||||
{
|
{
|
||||||
const f = try std.fs.createFileAbsolute(file_path, .{});
|
const f = try std.fs.createFileAbsolute(file_path, .{});
|
||||||
|
|
@ -219,7 +222,7 @@ test "writing to a file emits a 'modified' event" {
|
||||||
defer th.deinit();
|
defer th.deinit();
|
||||||
|
|
||||||
// Create the file before setting up the watcher to start from a clean slate.
|
// 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);
|
defer allocator.free(file_path);
|
||||||
{
|
{
|
||||||
const f = try std.fs.createFileAbsolute(file_path, .{});
|
const f = try std.fs.createFileAbsolute(file_path, .{});
|
||||||
|
|
@ -253,7 +256,7 @@ test "deleting a file emits a 'deleted' event" {
|
||||||
const th = try TestHandler.init(allocator);
|
const th = try TestHandler.init(allocator);
|
||||||
defer th.deinit();
|
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);
|
defer allocator.free(file_path);
|
||||||
{
|
{
|
||||||
const f = try std.fs.createFileAbsolute(file_path, .{});
|
const f = try std.fs.createFileAbsolute(file_path, .{});
|
||||||
|
|
@ -287,7 +290,7 @@ test "creating a sub-directory emits a 'dir_created' event" {
|
||||||
defer watcher.deinit();
|
defer watcher.deinit();
|
||||||
try watcher.watch(tmp);
|
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);
|
defer allocator.free(dir_path);
|
||||||
try std.fs.makeDirAbsolute(dir_path);
|
try std.fs.makeDirAbsolute(dir_path);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue