summaryrefslogtreecommitdiff
path: root/t/zz-atomic.t
diff options
context:
space:
mode:
Diffstat (limited to 't/zz-atomic.t')
-rw-r--r--t/zz-atomic.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/t/zz-atomic.t b/t/zz-atomic.t
new file mode 100644
index 0000000..240dc72
--- /dev/null
+++ b/t/zz-atomic.t
@@ -0,0 +1,35 @@
+use 5.008001;
+use strict;
+use warnings;
+use Test::More 0.96;
+
+BEGIN {
+ plan skip_all => "Can't mock random() with Path::Tiny already loaded"
+ if $INC{'Path/Tiny.pm'};
+ eval "use Test::MockRandom 'Path::Tiny';";
+ plan skip_all => "Test::MockRandom required for atomicity tests" if $@;
+}
+
+use lib 't/lib';
+use TestUtils qw/exception/;
+
+use Path::Tiny;
+srand(0);
+
+subtest "spew (atomic)" => sub {
+ my $file = Path::Tiny->tempfile;
+ ok( $file->spew("original"), "spew" );
+ is( $file->slurp, "original", "original file" );
+
+ my $tmp = $file->[Path::Tiny::PATH] . $$ . "0";
+ open my $fh, ">", $tmp;
+ ok( $fh, "opened collision file '$tmp'" );
+ print $fh "collide!";
+ close $fh;
+
+ my $error = exception { ok( $file->spew("overwritten"), "spew" ) };
+ ok( $error, "spew errors if the temp file exists" );
+ is( $file->slurp(), "original", "original file intact" );
+};
+
+done_testing();