diff options
Diffstat (limited to 't/TestBackup.pm')
-rw-r--r-- | t/TestBackup.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/t/TestBackup.pm b/t/TestBackup.pm new file mode 100644 index 0000000..0679776 --- /dev/null +++ b/t/TestBackup.pm @@ -0,0 +1,40 @@ +package TestBackup; +use File::Cmp qw(fcmp); +use File::Temp qw(tempdir); +use Exporter; +use re '/aa'; +use Carp; +use Test; + +our @ISA = qw(Test); +our @EXPORT=qw(makefile fileok plan ok); + +sub import { + my $pkg = shift; + my $workdir = tempdir(CLEANUP => 1); + chdir($workdir) or croak "can't change to $workdir: $!"; + @pattern = grep { /[\w\d]+/ } map { chr($_) } (1..127); + delete $ENV{VERSION_CONTROL}; + $pkg->export_to_level(1, @_); +} + +sub makefile { + my $file = shift; + my $size = shift // 1024; + + open(FH, '>', $file) or croak "can't create file $file (wd $workdir): $!"; + while ($size) { + my $n = @pattern; + $n = $size if $n > $size; + syswrite(FH, join('',@pattern[0..$n])) or + croak "write error creating $file: $!"; + $size -= $n; + } + close FH +} + +sub fileok { + ok(fcmp(@_)); +} + +1; |