#!/usr/local/bin/perl -w
=head1 NAME
cvs.t - testing of vcp cvs i/o
=cut
use strict ;
use Carp ;
use Cwd ;
use File::Spec ;
use Test ;
use VCP::TestUtils ;
my @vcp = vcp_cmd ;
my $t = -d 't' ? 't/' : '' ;
my $module = 'foo' ; ## Must match the rev_root in the testrevml files
my @revml_out_spec = ( "revml:", "--sort-by=name,rev_id" ) ;
my $max_change_id ;
sub check {
goto &die if $ENV{FATALTEST} && ! $_[0];
}
my ( $infile_0, $cvsroot_0, $infile_1, $cvsroot_1 ) =
make_cvsroots( $module, $t );
my $cvs_spec_0 = "cvs:$cvsroot_0:$module/" ;
my $cvs_spec_1 = "cvs:$cvsroot_1:$module/" ;
my @options;
my @tests = (
##
## cvs->revml (using cvs command) idempotency
##
sub {
eval {
my $infile = $infile_0;
my $cvs_spec = $cvs_spec_0;
my $out ;
run [ @vcp, $cvs_spec, @options, @revml_out_spec ], \undef, \$out;
my $in = slurp $infile ;
s_content qw( rep_desc time user_id ), \$in, \$out ;
s_content qw( rev_root ), \$in, $module ;
rm_elts qw( mod_time change_id cvs_info ), \$in ;
rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff';
},
##
## cvs->revml (using direct read)
##
sub {
eval {
my $infile = $infile_0;
my $cvs_spec = $cvs_spec_0;
my $out ;
run [ @vcp, $cvs_spec, @options, @revml_out_spec ], \undef, \$out;
my $in = slurp $infile ;
s_content qw( rep_desc time user_id ), \$in, \$out ;
s_content qw( rev_root ), \$in, $module ;
rm_elts qw( mod_time change_id cvs_info ), \$in ;
rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff';
},
##
## cvs->revml, re-rooting a dir tree
##
sub {
eval {
## Hide global $cvs_spec for the nonce
my $cvs_spec = "$cvs_spec_0/a/deeply/..." ;
my $out ;
run [ @vcp, $cvs_spec, @options, @revml_out_spec ], \undef, \$out;
my $infile = $t . "test-cvs-in-0.revml" ;
my $in = slurp $infile ;
s_content qw( rep_desc time user_id ), \$in, \$out ;
rm_elts qw( mod_time change_id cvs_info ), \$in, \$out ;
rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ;
## Strip out all files from $in that shouldn't be there
rm_elts qw( rev ), qr{(?:(?!a/deeply).)*?}s, \$in ;
## Adjust the $in paths to look like the result paths. $in is
## now the "expected" output.
s_content qw( rev_root ), \$in, "foo/a/deeply" ;
$in =~ s{(<name>)a/deeply/}{$1}g ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
## No branches in the output file
$in =~ s{^\s*<branches.*?</branches>\r?\n}{}ms;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff' ;
},
##
## incremental cvs->revml
##
sub {
eval {
my $infile = $infile_1;
my $cvs_spec = $cvs_spec_1;
my $out ;
run [ @vcp, $cvs_spec, @options, qw( -r ch_4: ), @revml_out_spec ], \undef, \$out;
my $in = slurp $infile ;
s_content qw( rep_desc time user_id ), \$in, \$out ;
s_content qw( rev_root ), \$in, $module ;
rm_elts qw( mod_time change_id cvs_info ), \$in ;
rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
# ch_4 only exists on the main branch (it's ch_4_branch_1 on the
# side branches).
$in =~ s{^\s*?<rev id="/foo/branch-0/branched#1\.1\.2\..*?<name>branch-0/branched.*?<rev_id>1\.1\.2\.\d+.*?</rev>\r?\n}{}gsm;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff' ;
},
##
## cvs->revml Idempotency test, bootstrapping the second set of changes
##
sub {
eval {
my $infile = $t . "test-cvs-in-1-bootstrap.revml" ;
my $cvs_spec = $cvs_spec_1;
my $out ;
run [ @vcp, $cvs_spec, @options, qw( -r ch_4: --bootstrap=... ), @revml_out_spec ],
\undef, \$out;
my $in = slurp $infile ;
s_content qw( rep_desc time user_id ), \$in, \$out ;
s_content qw( rev_root ), \$in, $module ;
rm_elts qw( mod_time change_id cvs_info ), \$in ;
rm_elts qw( label ), qr/r_\w+|ch_\w+/, \$out ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
# ch_4 only exists on the main branch (it's ch_4_branch_1 on the
# side branches).
$in =~ s{^\s*?<rev id="/foo/branch-0/branched#1\.1\.2\..*?<name>branch-0/branched.*?<rev_id>1\.1\.2\.\d+.*?</rev>\r?\n}{}gsm;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff' ;
},
) ;
plan tests => 2 * @tests;
use vars qw( $why_skip ); # use vars because we local()ize.
$why_skip .= cvs_borken ;
my $test_num = 0;
for ( @tests ) {
@options = qw( --use-cvs );
{
++$test_num;
local $why_skip ||= "test not selected"
if $ENV{TESTNUM} && $ENV{TESTNUM} != $test_num;
$why_skip ? skip( $why_skip, 0 ) : $_->();
}
@options = ();
{
++$test_num;
local $why_skip ||= "test not selected"
if $ENV{TESTNUM} && $ENV{TESTNUM} != $test_num;
$why_skip ? skip( $why_skip, 0 ) : $_->();
}
}