#!/usr/local/bin/perl -w
=head1 NAME
revml.t - testing of vcp revml in and out
=cut
use strict ;
use Carp ;
use File::Spec ;
use Test ;
use VCP::TestUtils ;
# use eq_or_diff from Test::Differences if available,
# else just use ok.
eval "use Test::Differences";
sub ok_or_diff {
if( defined &eq_or_diff ) {
# $_[3] = { context => 3 }; # arg to eq_or_diff
goto &eq_or_diff;
}
goto &Test::ok;
}
my @vcp = vcp_cmd ;
my $t = -d 't' ? 't/' : '' ;
my $in_revml = $t . "test-revml-in-0-no-big-files.revml" ;
my $compressed_revml = "/tmp/50revml_$$.revml.gz";
my $out_revml = "/tmp/50revml_$$.revml";
my @tests = (
##
## Empty imports, used here just to see if commad line parsing is ok and
## that a really simple file can make it through the XML parser ok.
##
sub {
run [ @vcp, "revml:-", "revml:" ], \"" ;
ok $?, 0, "`vcp revml:- revml:` return value" ;
},
sub {
run [ @vcp, "-", "-" ], \"" ;
ok $?, 0, "`vcp revml:- revml:` return value" ;
},
sub {
run [ @vcp, "-", ], \"" ;
ok $?, 0, "`vcp revml:- revml:` return value" ;
},
sub {
run [ @vcp, ], \"" ;
ok $?, 0, "`vcp revml:- revml:` return value" ;
},
# create gzipped revml
sub {
run [ @vcp, "revml:$in_revml", "revml:$compressed_revml", "--compress" ];
ok $?, 0, "vcp return value" ;
},
# check that gzipped revml exists
sub {
ok -z $compressed_revml, '', "gzipped file $compressed_revml created";
},
# uncompress the gzipped revml
sub {
my $out;
run [ @vcp, "revml:$compressed_revml", "--uncompress", "revml:-", "--sort-by=name,rev_id" ], \undef, \$out;
unlink $compressed_revml or warn "failed to unlink $compressed_revml";
my $expected = slurp $in_revml;
ok_or_diff $out, $expected;
},
( map {
my $source_spec = $_;
sub {
eval {
my $out ;
my $infile = $t . "test-revml-in-0.revml" ;
$source_spec =~ s/INFILE/$infile/;
## $in and $out allow us to avoide execing diff most of the time.
run [ @vcp, $source_spec, "-", "--sort-by=name,rev_id"],
\undef, \$out;
my $in = slurp( $infile ) ;
assert_eq $infile, $in, $out ;
} ;
ok $@ || '', '', "diff of test-revml-in-0.revml" ;
};
} qw( INFILE revml:INFILE revml:INFILE: revml:INFILE:/... )
),
( map {
my $type = $_ ;
##
## Idempotency tests
##
## These depend on the "test-foo-in.revml" files built in the makefile.
## See MakeMaker.PL for how those are generated.
##
sub {
eval {
my $out ;
my $infile = $t . "test-$type-in-0.revml" ;
## $in and $out allow us to avoide execing diff most of the time.
run [ @vcp, "$infile", "-", "--sort-by=name,rev_id" ], \undef, \$out;
my $in = slurp( $infile ) ;
assert_eq $infile, $in, $out ;
} ;
ok $@ || '', '', "diff of test-$type-in-0.revml" ;
},
} qw( revml cvs p4 ) )
) ;
plan tests => scalar( @tests ) ;
$_->() for @tests ;