Skip to content

Commit

Permalink
add mimimal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Jan 20, 2010
1 parent 4d1dd48 commit 219a015
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions t/assets/hello.txt
@@ -0,0 +1 @@
hello
59 changes: 59 additions & 0 deletions t/blockdiff_dump.t
@@ -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.