61map.t #16

  • //
  • guest/
  • perforce_software/
  • revml/
  • t/
  • 61map.t
  • View
  • Commits
  • Open Download .zip Download (4 KB)
#!/usr/local/bin/perl -w

=head1 NAME

map.t - test VCP::Filter::map

=cut

use VCP::Dest;

@ISA = qw( VCP::Dest );

use strict ;

use Carp ;
use File::Spec ;
use Test ;
use VCP::TestUtils ;

## These next few are for in vitro testing
use VCP::Filter::map;
use VCP::Rev;

my @vcp = vcp_cmd ;

my $prev_rev;

sub r {
   my ( $name, $branch_id, $labels ) =
      $_[0] =~ /\A(?:(.+?))?(?:<((?!\@).*?)>)?(?:<\@(.*?)>)?\z/
      or die "Couldn't parse '$_[0]'";

   my $r = VCP::Rev->new(
      id          => $_[0],
      rev_id      => "1",
      name        => $name,
      branch_id   => $branch_id,
      previous_id => $prev_rev ? $prev_rev->id : undef,
      labels      => [split /,/, $labels||"" ],
   );
   $prev_rev = $r;
   return $r;
}

my $filter;

my $r_out;

my $r_count;
my $r_handled_count;
my @received_revs;

sub rev_count { $r_count = $_[1] }

sub _skip_rev {
    ++$r_handled_count;
}

sub handle_header {
   $prev_rev = undef;
   @received_revs = ();
}

sub handle_rev {
   my $self = shift;
   my ( $r ) = @_;
   ++$r_handled_count;
   $r_out = join "", $r->name || "", "<", $r->branch_id || "", ">";
   $r_out = join "", $r_out, "<\@", join( ",", $r->labels ), ">"
       if $r->labels;
   push @received_revs, $r_out;
}

sub t {
    return skip "compilation failed", 1 unless $filter;

    my ( $expr, $expected ) = @_;

    $r_out = undef;
    $r_handled_count = 0;
    $r_count = 0;

    $filter->handle_rev( r $expr );

    @_ = ( $r_out || "<<skip>>ed", @_ > 1 ? $expected || "<<skip>>ed" : () );
    goto &ok;
}

my @tests = (
## In vitro tests
sub {
   eval { $filter = VCP::Filter::map->new( "",
   [
      '<b>',            '<B>',
      'a',              'A',
      'a',              'NONONO',
      'c<d>',           'C<D>',
      'xyz',            '<<keep>>',
      'x*',             '<<skip>>',
      's(*)v<(...)>',   'S$1V${2}Y<>',
      's(*)v<>',        'NONONO',
      '(...)<@(l...)>', '<<branch_to("tags/$2/$1")>>',
   ] ) }; 
   ok $filter ? 1 : $@, 1;
   if ( $filter ) {
      $filter->dest( main->new );
      $filter->handle_header( {} );
   }
},

sub { t "a<b>",     "a<B>"       },
sub { ok $r_handled_count, 1 },
sub { t "a<c>",     "A<c>"       },
sub { ok $r_handled_count, 1 },
sub { t "c<d>",     "C<D>"       },
sub { ok $r_handled_count, 1 },
sub { t "c<e>",     "c<e>"       },
sub { ok $r_handled_count, 1 },
sub { t "e<d>",     "e<d>"       },
sub { ok $r_handled_count, 1 },
sub { t "xab",      undef        },
sub { ok $r_handled_count, 1 },
sub { t "Z<Z>",     "Z<Z>"       },
sub { ok $r_handled_count, 1 },
sub { t "xyz",      "xyz<>"      },
sub { ok $r_handled_count, 1 },
sub { t "stuv<wx>", "StuVwxY<>"  },
sub { ok $r_handled_count, 1 },
sub { t "stuv<wx>", "StuVwxY<>"  },
sub { ok $r_handled_count, 1 },
sub { @received_revs = ();
      t "f<\@l1,l2,A,B>" },
sub { ok 0+@received_revs, 3 },
sub { ok $received_revs[0], "f<><\@l1,l2,A,B>" },
sub { ok $received_revs[1], "tags/l1/f<>" },
sub { ok $received_revs[2], "tags/l2/f<>" },
sub {
   $filter->handle_footer( {} ) if $filter;
   ok 1;
},

sub {
   eval { $filter = VCP::Filter::map->new( "",
   [
      '<b>',           '<B>',
      '/tags/(*)/...','<<label_parent($1)>>',
   ] ) }; 
   ok $filter ? 1 : $@, 1;
   if ( $filter ) {
      $filter->dest( main->new );
      $filter->handle_header( {} );
   }
},

sub { t "a<b>",       undef  },
sub { t "/tags/l/f",  undef  },

sub {
   $filter->handle_footer( {} ) if $filter;
   ok 1;
},

sub { ok $received_revs[0], "a<B><\@l>" },
sub { ok 0+@received_revs, 1 },

## In vivo tests
sub {
  eval {
     my $out ;
     my $infile = "t/test-revml-in-0-no-big-files.revml";
     ## $in and $out allow us to avoide execing diff most of the time.
     run [ @vcp, "vcp:-" ], \<<'END_VCP', \$out;
Source: t/test-revml-in-0-no-big-files.revml

Sort:

Destination: -

Map:
END_VCP

     my $in = slurp $infile;
     assert_eq $infile, $in, $out ;
  } ;
  ok $@ || '', '', 'diff' ;
},

sub {
  eval {
     my $out ;
     my $infile = "t/test-revml-in-0-no-big-files.revml";
     ## $in and $out allow us to avoid execing diff most of the time.
     run [ @vcp, "vcp:-" ], \<<'END_VCP', \$out;
Source: t/test-revml-in-0-no-big-files.revml

Sort:

Destination: -

Map:
    add/f(1)   hey/a$1b
    add/f(2)   hey/a${1}b
    add/f(*)   hey/a${1}b
END_VCP
     my $in = slurp $infile;

     $in =~ s{(<name>)add/f([^<]*)}{$1hey/a$2b}g;
     
     assert_eq $infile, $in, $out ;
  } ;
  ok $@ || '', '', 'diff' ;
},

) ;

plan tests => scalar( @tests ) ;

$_->() for @tests ;
# Change User Description Committed
#16 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.
#15 4486 Barrie Slaymaker - 61map.t adapted to skip_rev() logging code
#14 4481 Barrie Slaymaker - VCP::Filter::map calls skip_rev when deleting a rev (spotted by clkao)
#13 3155 Barrie Slaymaker Convert to logging using VCP::Logger to reduce stdout/err spew.
       Simplify & speed up debugging quite a bit.
       Provide more verbose information in logs.
       Print to STDERR progress reports to keep users from wondering
       what's going on.
       Breaks test; halfway through upgrading run3() to an inline
       function for speed and for VCP specific features.
#12 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.
#11 3091 Barrie Slaymaker Factor out rules list parsing; it's useful elsewhere and
       should not have been copy & edited in to two files
       in the first place.
#10 3016 Barrie Slaymaker and fix test suite breakage due to last change
#9 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
#8 2694 Barrie Slaymaker Remove spurious variable
#7 2693 Barrie Slaymaker Fix typoe.
#6 2371 John Fetkovich Modified to use vcp_cmd from VCP::TestUtils.
#5 2317 Barrie Slaymaker Get map working on revml->revml
#4 2316 Barrie Slaymaker intermediate checkin
#3 2315 Barrie Slaymaker update docs, implement a bit more mapping code
#2 2307 Barrie Slaymaker get VCP::Filter::map working, update docs
#1 2304 Barrie Slaymaker VCP::Filter::map docs and infrastructure