#!/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 IPC::Run qw( run ) ;
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 $cvs_spec ;
my @revml_out_spec = ( "revml:", "--sort-by=name,rev_id" ) ;
my $max_change_id ;
sub check {
goto &die if $ENV{FATALTEST} && ! $_[0];
}
my @tests = (
sub {
my $cvs_options = init_cvs "cvs_", $module ;
$cvs_spec = "cvs:$cvs_options->{repo}:$module/" ;
$ENV{CVSROOT} = "foobar" ;
check ok 1 ;
},
##
## Empty import
##
sub {
run [ @vcp, "revml:-", $cvs_spec ], \"" ;
check ok $?, 0, "`vcp revml:- $cvs_spec` return value" ;
},
##
## revml->cvs->revml (using cvs command) idempotency
##
sub {}, ## Mult. ok()s in next sub{}.
sub {
eval {
my $infile = $t . "test-cvs-in-0.revml" ;
## $in and $out allow us to avoide execing diff most of the time.
run [ @vcp, "revml:$infile", $cvs_spec ], \undef
or die "`vcp revml:$infile $cvs_spec` returned $?" ;
check ok 1 ;
my $out ;
run [ @vcp, $cvs_spec, '--use-cvs', @revml_out_spec ], \undef, \$out
or die "`vcp $cvs_spec --use-cvs` returned $?" ;
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';
},
##
## revml->cvs->revml (using direct read) idempotency
##
sub {
eval {
# Reuses repository from last test.
my $infile = $t . "test-cvs-in-0.revml" ;
my $out ;
run [ @vcp, $cvs_spec, @revml_out_spec ], \undef, \$out
or die "`vcp $cvs_spec` returned $?" ;
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/a/deeply/..." ;
my $out ;
run [ @vcp, $cvs_spec, @revml_out_spec ], \undef, \$out
or die "`vcp $cvs_spec` returned $?" ;
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{()a/deeply/}{$1}g ;
$in =~ s{(id="|id>)/ignored}{$1/foo}g;
## No branches in the output file
$in =~ s{^\s*\r?\n}{}ms;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff' ;
},
##
## Idempotency test for an incremental revml->cvs->revml update
##
sub {}, ## Mult. ok()s in next sub{}.
sub {
my $infile = $t . "test-cvs-in-1.revml" ;
eval {
## $in and $out allow us to avoid execing diff most of the time.
run [ @vcp, "revml:$infile", $cvs_spec ], \undef
or die "`vcp revml:$infile $cvs_spec` returned $?" ;
check ok 1 ;
my $out ;
run [ @vcp, $cvs_spec, qw( -r ch_4: ), @revml_out_spec ], \undef, \$out
or die "`vcp $cvs_spec -r ch_4:` returned $?" ;
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*?)/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*?)/ignored}{$1/foo/newdir}g;
assert_eq $infile, $in, $out ;
} ;
check ok $@ || '', '', 'diff' ;
},
###
### cvs->revml, using the VCP::Source::cvs --cd option
### (also depends on being able to reroot on input.
#sub {
# eval {
# my $infile = $t . "test-cvs-in-0.revml" ;
# ## $in and $out allow us to avoide execing diff most of the time.
# my $cvs_spec = "$cvs_spec/cd_test" ;
# run [ @vcp, "revml:$infile", $cvs_spec ], \undef
# or die "`vcp revml:$infile $cvs_spec` returned $?" ;
#
# ok 1 ;
#
# my $out ;
# run [ @vcp, $cvs_spec ], \undef, \$out
# or die "`vcp $cvs_spec` returned $?" ;
#
# 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 ;
#
# assert_eq $infile, $in, $out ;
# } ;
# ok $@ || '', '', 'diff ';
#},
#
) ;
plan tests => scalar( @tests ) ;
my $why_skip ;
$why_skip .= cvs_borken ;
$why_skip ? skip( $why_skip, 0 ) : $_->() for @tests ;