95svn2p4.t #2

  • //
  • guest/
  • perforce_software/
  • revml/
  • t/
  • 95svn2p4.t
  • View
  • Commits
  • Open Download .zip Download (6 KB)
#!/usr/local/bin/perl -w

=head1 NAME

svn.t - testing of vcp svn 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 $cwd = cwd;

if ( $^O =~ /Win32/ ) {
    $cwd =~ s{\A[A-Z]:}{};
}

my $module = 'foo' ;  ## Must match the rev_root in the testrevml files

my @revml_out_spec = ( "sort:", "--", "revml:" ) ;

my $p4d_borken = $ENV{P4DBORKEN} || p4d_borken ;

sub check {
   croak "test failed and FATALTEST set" if ! $_[0];
}


my $infile_0  = "${t}test-svn-in-0.revml";
my $infile_1  = "${t}test-svn-in-1.revml";
my $svnroot_0 = "${t}svnroot_0";
my $svnroot_1 = "${t}svnroot_1";

my $svn_spec_0        = "svn:file://$cwd/$svnroot_0:/$module" ;
my $svn_spec_1        = "svn:file://$cwd/$svnroot_1:/$module" ;

## Where to put the destination repository
my $p4root = tmpdir "p4root";

my $state_location = tmpdir "vcp_state";

my $p4_spec = "p4:p4_t_user\@$p4root:";

my $repo_id;

my @tests = (
##
## svn to p4
##
sub {
   return skip $p4d_borken, 1 if $p4d_borken ;

   my $svn_spec = $svn_spec_0;

   ## TODO: test rewriting label branches to be labels; this will need
   ## gentrevml to write label branches.
   eval { run [ @vcp, "vcp:-" ], \<<TOHERE; };
Source:      $svn_spec_0/... --repo-id=svn:test_repository

Destination: $p4_spec//depot/...
                --init-p4d
                --db-dir=$state_location
                --repo-id=p4:test_repository

Map:
        tags/(*)/... <<label_parent(\$1)>>

TOHERE
   ok $@ || '', '';  # next sub checks this better
},

##
## check previous test by reading resulting p4 into revml,
## and comparing to the p4 version of the generated source revml.
##
sub {
   return skip $p4d_borken, 1 if $p4d_borken ;

   my $out;
   eval {
      run [ @vcp,
         "$p4_spec//depot/...",
         "--repo-id=p4:test_repository",
         "--run-p4d",
         @revml_out_spec,
         "--db-dir=$state_location",
         "--repo-id=revml:test_repository",
      ], \undef, \$out;
   };
   die $@ if $@;

   my $infile  = $t . "test-p4-in-0.revml";
   my $in = slurp $infile ;

   s_content  qw( rep_desc time user_id rep_type     ), \$in, \$out ;
   s_content  qw( rev_root                           ), \$in, "depot" ;
   rm_elts    qw( p4_info change_id source_change_id ), \$in, \$out ;

   $out =~ s{[\r\n]*\[vcp\] .*?(\r?\n)}{$1}g;
       ## Clean up the "[vcp] using estimated..." addition to comments
   
   $in =~ s{(id="|id>)/ignored}{$1//depot}g;

   $in =~ s{^\s*<label>\w+(081|085|089|093|101)</label>[ \t]*\r?\n}{}mg;
       ## These labels are applied in batch 2 when building the svn repo.

   ok_or_diff $out, $in;
},

##
## Incremental svn->p4->revml update (svn to p4 part)
##
sub {
   return skip $p4d_borken, 1 if $p4d_borken ;

   eval { run [ @vcp, "vcp:-" ], \<<TOHERE; };
Source:      $svn_spec_1/...
                --repo-id=svn:test_repository
                --continue

Destination: $p4_spec//depot/... 
                --run-p4d
                --db-dir=$state_location
                --repo-id=p4:test_repository

Map:
        tags/(*)/... <<label_parent(\$1)>>

TOHERE
   ok $@ || '', '';  # next sub checks this better
},

##
## part 2 of Incremental svn->p4->revml update (p4 to revml, check result)
##
sub {
   return skip $p4d_borken, 1 if $p4d_borken ;
   return skip 'last test did not complete', 1 if $@;
   
   my $out ;
   
   eval {
      run [ @vcp,
         "$p4_spec//depot/...",
            "--repo-id=p4:test_repository",
            "--continue",
            "--run-p4d",
         @revml_out_spec,
            "--db-dir=$state_location",
            "--repo-id=revml:test_repository",
      ], \undef, \$out;
   };
   die $@ if $@;
   
   my $infile  = $t . "test-p4-in-1.revml";
   my $in = slurp $infile ;
   
   s_content  qw( rep_desc time user_id rep_type     ), \$in, \$out ;
   s_content  qw( rev_root                           ), \$in, "depot" ;
   rm_elts    qw( p4_info change_id source_change_id ), \$in, \$out ;
       ## svn has no change_id and the p4 input file and output file have
       ## different ones because the svn->p4 splits a change in to two
       ## to put the branch operation in its own change.
   
   $out =~ s{[\r\n]*\[vcp\] .*?(\r?\n)}{$1}g;
       ## Clean up the "[vcp] using estimated..." addition to comments
   
   $in =~ s{(id="|id>)/ignored}{$1//depot}g;

   $in =~ s{^\s*<label>\w+(157|161|165|168|169|181)</label>[ \t]*\r?\n}{}mg;
       ## These labels are never applied (they would be applied
       ## after the final change in the second batch generated by gentrevml.

   ok_or_diff $out, $in;
},

##
## svn->p4->revml, re-rooting a dir tree
##
## Do this after the above tests so that we can start with an empty repo.
##
sub {
   return skip $p4d_borken, 1 if $p4d_borken ;

   ## Start anew
   rm_dir_tree $p4root;
   rm_dir_tree $state_location;

   eval {
      run [ @vcp,
         "$svn_spec_0/main/a/deeply/...",
         "$p4_spec//depot/new/...",
            "--db-dir=$state_location",
            "--repo-id=p4:test_repository",
            "--init-p4d",
      ],
         \undef;
   };
   ok $@ || '', '';  # next sub checks this better
},

sub {   
   return skip $p4d_borken, 1 if $p4d_borken ;
   my $out ;

   eval {
      run [ @vcp,
         "$p4_spec//depot/new/...",
            "--repo-id=p4:test_repository",
            "--run-p4d",
         @revml_out_spec,
            "--db-dir=$state_location",
            "--repo-id=revml:test_repository",
      ], \undef, \$out;
   };
   die $@ if $@;

   my $infile  = $t . "test-p4-in-0.revml";
   my $in = slurp $infile ;

   s_content  qw( rep_desc time user_id rep_type  ), \$in, \$out ;
   s_content  qw( rev_root                        ), \$in, "depot/new" ;
   rm_elts    qw( p4_info                         ), \$in, \$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.
   $in =~ s{<(name|source_name)>main/a/deeply/}{<$1>}g ;

   $in =~ s{(id="|id>)/ignored/main/a/deeply}{$1//depot/new}g;  #"# cperl syntax highlight fix

   $in =~ s{^\s*<label>\w+</label>[ \t]*\r?\n}{}mg;
       ## The above svn->p4 command does not capture labels.

   ok_or_diff $out, $in;
},

) ;

plan tests => scalar( @tests ) ;

my $why_skip ;
$why_skip .= p4_borken;
$why_skip .= svn_borken;
$why_skip ? skip( $why_skip, 0 ) : $_->() for @tests ;
# Change User Description Committed
#2 5404 Barrie Slaymaker - SVN support added
- Makefile gives clearer notices about missing optional
  prereqs.
- VCP::Filter::labelmap and VCP::Filter::map: <<skip>> replaces
  deprecated <<delete>> to be clearer that no revisions
  are deleted from either repository but some just are
  skipped and not inserted.
- VCP::Filter::map: support added for SVN-like branch labels
- VCP::Source: support added for ISO8601 timestamps
  emitted by SVN.
#1 5367 Barrie Slaymaker - t/95svn2p4.t created
//guest/perforce_software/revml/t/95cvs2p4.t
#30 4417 Barrie Slaymaker - Adapt to "estimated values" messages
       - Adapt to more accurate test suite
#29 3970 Barrie Slaymaker - VCP::Source handles rev queing, uses disk to reduce RAM
- Lots of other fixes
#28 3800 Barrie Slaymaker - <branches> removed from all code
#27 3689 Barrie Slaymaker - 95cvs2p4.t no longer fails if p4d missing
#26 3500 Barrie Slaymaker - Use -kb on cvs export to suppress carriage
  returns.
#25 3496 Barrie Slaymaker - VSS branching
#24 3115 Barrie Slaymaker Move sorting function to the new VCP::Filter::sort;
       it's for testing and reporting only and the code
       was bloating VCP::Dest and limiting VCP::Rev
       and VCP::Dest optimizations.  Breaks test suite in minor
       way.
#23 2973 Barrie Slaymaker Fix handling of branched but unchanged files
#22 2926 John Fetkovich remove --state-location switch
       add --db-dir and --repo-id switches
       build state location from concatenation of those two.
#21 2915 Barrie Slaymaker Default to *not* changing the first rev of a branch,
       add --change-branch-rev-1 to enable the non-default
       behavior (which is what is used by most of the test suite).
#20 2909 Barrie Slaymaker Update this test script to current
#19 2896 John Fetkovich updated to use --continue and --state-location.
       not entirely working yet.
#18 2895 Barrie Slaymaker Tweak to not delete branch_ids, add TODOs, make sure a stubbed out
       test gets run.
#17 2859 Barrie Slaymaker Work on Source::p4 branching issues
#16 2802 John Fetkovich Added a source_repo_id to each revision, and repo_id to each
Source and Dest.  The repo_ids include repository type
(cvs,p4,revml,vss,...) and the repo_server fields.  Changed the
$self->...->set() and $self->...->get() lines in VCP::Dest::* to
pass in a conglomerated key value, by passing in the key as an
ARRAY ref.  Also various restructuring in VCP::DB.pm,
VCP::DB_file.pm and VCP::DB_file::sdbm.pm related to this
change.
#15 2756 John Fetkovich check skips if cvs not present
#14 2743 John Fetkovich Add fields to vcp:
         source_name,
         source_filebranch_id,
         source_branch_id,
         source_rev_id,
         source_change_id

        1. Alter revml.dtd to include the fields
        2. Alter bin/gentrevml to emit legal RevML
        3. Extend VCP::Rev to have the fields
        4. Extend VCP::{Source,Dest}::revml to read/write the fields
           (VCP::Dest::revml should die() if VCP tries to emit illegal
           RevML)
        5. Extend VCP::{Source,Dest}::{cvs,p4} to read the fields
        7. Get all tests through t/91*.t to pass
           except those that rely on ch_4 labels
#13 2714 Barrie Slaymaker Simplify t/90*cvs.t tests, remove make_cvsroots for speed and
       simplicity.
#12 2656 Barrie Slaymaker Remove remainder of winged-eel workarounds now that IPC::Run
       is fixed (in IPC::Run 0.75).
#11 2638 Barrie Slaymaker Require fixed IPC::Run, remove workaround for buggy IPC::Run
#10 2624 John Fetkovich minor fixes, including workaround for broken IPC::Run (to be removed)
#9 2344 Barrie Slaymaker Make the labelsync code more self-documenting
#8 2328 Barrie Slaymaker fix up minor bugs in VCP::Source::p4, get t/95cvs2p4.t
       passing
#7 2326 Barrie Slaymaker remove debug statement
#6 2325 Barrie Slaymaker Get most tests working
#5 2319 Barrie Slaymaker make t/test-*.revml be consistent with cvs2p4 and p42cvs scenarios
#4 2307 Barrie Slaymaker get VCP::Filter::map working, update docs
#3 2297 Barrie Slaymaker Adapt cvs, revml to a more realistic branching structure
#2 2267 Barrie Slaymaker factor out cvs2revml, test both --use-cvs and direct modes, with times
#1 2265 Barrie Slaymaker factor out t/95cvs2p4.pm and allow it to reuse the cvs repo for speed.