Subject: | use Test::More and test interface more thoroughly. |
I've converted this test to use Test::More to provide a more consistent interface to testing.
Along the way I added and documented some tests.
Subject: | patch.txt |
diff --git a/t/mmap.t b/t/mmap.t
index caebbf5..883ffb0 100644
--- a/t/mmap.t
+++ b/t/mmap.t
@@ -1,24 +1,39 @@
-print "1..2\n";
-use Sys::Mmap;
+#! perl -T
+
+BEGIN {
+ use strict;
+ use warnings;
+ use Test::More tests => 4;
+
+ use_ok('Sys::Mmap');
+}
+
use FileHandle;
-$tmp = "mmap.tmp";
-sysopen(FOO, $tmp, O_WRONLY|O_CREAT|O_TRUNC) or die "$tmp: $!\n";
-print FOO "ok 1\n";
+$temp_file = "mmap.tmp";
+
+sysopen(FOO, $temp_file, O_WRONLY|O_CREAT|O_TRUNC) or die "$temp_file: $!\n";
+print FOO "ABCD1234";
close FOO;
-sysopen(FOO, $tmp, O_RDONLY) or die "$tmp: $!\n";
+my $foo;
+sysopen(FOO, $temp_file, O_RDONLY) or die "$temp_file: $!\n";
mmap($foo, 0, PROT_READ, MAP_SHARED, FOO);
close FOO;
-print $foo;
+is($foo, 'ABCD1234', "RO access to the file produces valid data");
munmap($foo);
-sysopen(FOO, $tmp, O_RDWR) or die "$tmp: $!\n";
+sysopen(FOO, $temp_file, O_RDWR) or die "$temp_file: $!\n";
mmap($foo, 0, PROT_READ|PROT_WRITE, MAP_SHARED, FOO);
close FOO;
-substr($foo, 3, 1) = "2";
-print $foo;
+substr($foo, 3, 1) = "Z";
+is($foo, 'ABCZ1234', 'Foo can be altered in RW mode');
+munmap($foo);
+
+sysopen(FOO, $temp_file, O_RDONLY) or die "$temp_file: $!\n";
+my $bar = <FOO>;
+is($bar, 'ABCZ1234', 'Altered foo reflects on disk');
-unlink($tmp);
+unlink($temp_file);