diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 4695dd9a8e8c791ce71f010cd00be2c828117841..d7d592ee36f19c69908f2205d57aca7d6274fb4d 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1651,6 +1651,21 @@ test "AtomicFile" { \\ this is a test file ; + // link() succeeds with no file already present + { + var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = false }); + defer af.deinit(io); + try af.file.writeStreamingAll(io, test_content); + try af.link(io); + } + // link() returns error.PathAlreadyExists if file already present + { + var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = false }); + defer af.deinit(io); + try af.file.writeStreamingAll(io, test_content); + try expectError(error.PathAlreadyExists, af.link(io)); + } + // replace() succeeds if file already present { var af = try ctx.dir.createFileAtomic(io, test_out_file, .{ .replace = true }); defer af.deinit(io);