Permalink
Browse files

add mimimal tests

  • Loading branch information...
1 parent 4d1dd48 commit 219a0151a987b343b9a0e2c262bb8ea12bba5d52 @kazuho committed Jan 20, 2010
Showing with 60 additions and 0 deletions.
  1. +1 −0 t/assets/hello.txt
  2. +59 −0 t/blockdiff_dump.t
View
@@ -0,0 +1 @@
+hello
View
@@ -0,0 +1,59 @@
+use strict;
+use warnings;
+
+use Digest::MD5 qw(md5);
+use File::Temp qw(tempdir);
+use POSIX qw(:sys_wait_h);
+use Test::More;
+
+my $BS_HDR = "\0\x40\0\0"; # 16384 (block size) in little endian
+
+my $tempdir = tempdir(CLEANUP => 1);
+
+# full backup test
+my $out = runit("t/assets/hello.txt");
+my $status = $?;
+ok WIFEXITED($?), 'blockdiff_dump exited';
+is WEXITSTATUS($?), 0, 'blockdiff_dump exit code';
+is(
+ $out,
+ $BS_HDR . ("\0"x8) . read_file('t/assets/hello.txt'),
+ 'blockdiff_dump output',
+);
+is(
+ read_file("$tempdir/md5.out"),
+ $BS_HDR . md5(read_file('t/assets/hello.txt')),
+ 'blockdiff_dump md5 output',
+);
+
+# nexist
+runit("t/assets/nexist.txt", 1);
+$status = $?;
+ok WIFEXITED($?), 'blockdiff_dump exitted';
+isnt WEXITSTATUS($?), 0, 'blockdiff_dump error on exit';
+
+# TODO: incremental backup
+
+# TODO: -z and --lzop
+
+done_testing;
+
+sub runit {
+ my ($fn, $no_stderr) = @_;
+ open(
+ my $fh,
+ '-|',
+ "blib/script/blockdiff_dump $fn 6> $tempdir/md5.out"
+ . ($no_stderr ? ' 2> /dev/null' : ''),
+ ) or die "failed to exec blockdiff:$!";
+ my $out = join '', <$fh>;
+ close $fh;
+ $out;
+}
+
+sub read_file {
+ my $fn = shift;
+ open my $fh, '<', $fn
+ or die "failed to open file:$fn:$!";
+ return join '', <$fh>;
+}

0 comments on commit 219a015

Please sign in to comment.