added more comprehensive tests
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sun, 07 Aug 2011 11:07:35 +0200
changeset 4 cdf3ca65d677
parent 3 92690b23b317
child 5 3f80a97bea87
added more comprehensive tests
.perltidyrc
Build.PL
bin/.perltidyrc
t/000-syntax.t
t/001-root.t
--- a/.perltidyrc	Sun Aug 07 11:07:27 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
---paren-tightness=2
---square-bracket-tightness=2
--- a/Build.PL	Sun Aug 07 11:07:27 2011 +0200
+++ b/Build.PL	Sun Aug 07 11:07:35 2011 +0200
@@ -10,5 +10,10 @@
 	perl => "5.10.0",
 	autodie => "0",
 	Fuse => "0",
+	"Pod::Usage" => "0",
+    },
+    build_requires => {
+	"Test::More"  => "0.92",
+	"Digest::MD5" => "0",
     },
 )->create_build_script();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/.perltidyrc	Sun Aug 07 11:07:35 2011 +0200
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- a/t/000-syntax.t	Sun Aug 07 11:07:27 2011 +0200
+++ b/t/000-syntax.t	Sun Aug 07 11:07:35 2011 +0200
@@ -7,7 +7,7 @@
 
 my @files;
 find(sub {
-    -f -x and ~/^\./ or return;
+    -f -x and !/^\./ or return;
     push @files, $File::Find::name;
 }, "blib");
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/001-root.t	Sun Aug 07 11:07:35 2011 +0200
@@ -0,0 +1,65 @@
+use strict;
+use warnings;
+use Test::More;
+use English qw(-no_match_vars);
+use File::Temp;
+use File::Basename;
+use File::Find;
+use Cwd qw(abs_path);
+use POSIX qw(SEEK_END);
+use Digest::MD5;
+
+plan skip_all => "Need root permissions to perform these tests.\n"
+    . "\t try: sudo ./Build test verbose=1 test-files=$0"
+    if not $EUID == 0;
+
+my $dir = File::Temp->newdir(TEMPLATE => "blockfuse.XXXXXX");
+
+END { system("umount $dir 2>/dev/null") if $dir };
+system("blib/script/blockfuse $dir");
+is($?, 0, "mounted");
+
+my %size;
+find(sub {
+    (my $name = $File::Find::name) =~ s/^\/dev//;
+    if (-d) {
+	ok(-d "$dir/$name", "dir $name");
+    }
+    elsif (-b) {
+	ok(-f "$dir/$name", "block->file $name");
+	if (open(my $block, $_)) {
+	    seek($block, 0, SEEK_END);
+	    my $size = tell($block);
+	    close($block);
+	    is($size, -s "$dir/$name", "size $name");
+	    $size{$name} = $size;
+	}
+    }
+    elsif (-l and (-b abs_path $_ or -d abs_path $_)) {
+	ok(-l "$dir/$name", "link $name");
+    }
+}, "/dev");
+
+# now md5sum test for the smallest device
+my $smallest = (sort { $size{$a} <=> $size{$b} } grep {$size{$_}} keys %size)[0];
+
+
+my %digest = (
+    dev => Digest::MD5->new(),
+    file => Digest::MD5->new(),
+);
+
+{
+    local $/ = \4096;
+    open(my $dev, "/dev/$smallest") or die "/dev/$smallest: $!";
+    $digest{dev}->add($_) while defined($_ = <$dev>);
+
+    open(my $file, "$dir/$smallest") or die "$dir/$smallest: $!";
+    $digest{file}->add($_) while defined($_ = <$file>);
+}
+
+is($digest{file}->hexdigest(), $digest{dev}->hexdigest(), "digests are equal");
+
+
+
+done_testing();