]> git.vpit.fr Git - perl/modules/rgit.git/blobdiff - t/20-each.t
Test loading all modules
[perl/modules/rgit.git] / t / 20-each.t
index 1c582464dcd9a9b566e66a2a0abd95b15b4ebf0a..ea70268904f03bc49d9881b9eb82876e16bcf728 100644 (file)
@@ -7,10 +7,15 @@ use Cwd qw/cwd abs_path/;
 use File::Spec::Functions qw/catdir catfile/;
 use File::Temp qw/tempfile tempdir/;
 
-use Test::More tests => 2 + 2 * 2 + 11 * (3 + 1);
+use Test::More tests => 2 + 2 * 4 + 12 * (3 + 1 + 3 + 6);
 
+use App::Rgit::Utils qw/:codes/;
 use App::Rgit;
 
+use lib 't/lib';
+
+use App::Rgit::Policy::Callback;
+
 sub build {
  my ($tree, $prefix) = @_;
  my @ret;
@@ -88,24 +93,35 @@ is(grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references');
              @$_,
              map({ catdir($tmpdir, $_) } @{$_}[1 .. 3]),
              $tmpdir,
-             '^n'
+             '%n', '%x'
             ], @expected;
 
-for my $cmd (qw/commit FAIL/) {
+sub try {
+ my ($cmd, $exp) = @_;
  my ($fh, $filename) = tempfile(UNLINK => 1);
+ my $policy = App::Rgit::Policy->new(
+  @_ > 2 ? (name => 'Callback', callback => $_[2])
+         : (name => 'Default')
+ );
  my $ar = App::Rgit->new(
-  git  => abs_path('t/bin/git'),
-  root => $tmpdir,
-  cmd  => $cmd,
-  args => [ abs_path($filename), $cmd, qw/^n ^g ^w ^b ^G ^W ^B ^R ^^n/ ]
+  git    => abs_path('t/bin/git'),
+  root   => $tmpdir,
+  cmd    => $cmd,
+  args   => [ abs_path($filename), $cmd, qw/%n %g %w %b %G %W %B %R %%n %x/ ],
+  policy => $policy,
  );
  isnt($ar, undef, "each $cmd has a defined object");
- my $exit = $ar->run;
+ my $exit;
  my $fail = $cmd eq 'FAIL' ? 1 : 0;
- is($exit, $fail << 8, "each $cmd returned $fail");
+ if ($fail) {
+  ($exit, undef) = $ar->run;
+ } else {
+  $exit = $ar->run;
+ }
+ is($exit, $fail, "each $cmd returned $fail");
  my @lines = split /\n/, do { local $/; <$fh> };
  my $res = [ map [ split /\|/, $_ ], @lines ];
my $exp = [ map [ $cmd, @$_ ], $fail ? $expected[0] : @expected ];
$exp = [ map [ $cmd, @$_ ], @$exp ];
  for my $i (0 .. $#$exp) {
   my $e = $exp->[$i];
   my $r = shift @$res;
@@ -113,8 +129,17 @@ for my $cmd (qw/commit FAIL/) {
 SKIP:
   {
    skip 'didn\'t visited that repo' => 10 unless defined $r;
+   s/[\r\n]*$// for @$r;
    is($r->[$_], $e->[$_], "each $cmd argument $_ for repository $i is ok")
-    for 0 .. 9;
+    for 0 .. 10;
   }
  }
 }
+
+try 'commit', [ @expected ];
+try 'FAIL',   [ $expected[0] ];
+try 'FAIL',   [ @expected ],
+              sub { NEXT | SAVE };
+my $c = 0;
+try 'FAIL',   [ map { ($expected[$_]) x 2 } 0 .. $#expected ],
+              sub { my $ret = $c ? undef : REDO; $c = 1 - $c; $ret };