From: Vincent Pit Date: Tue, 7 Oct 2008 20:06:36 +0000 (+0200) Subject: Test policies X-Git-Tag: v0.04~8 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Frgit.git;a=commitdiff_plain;h=84976874ba7cc16560a20dc013ac336fb5aec4b5 Test policies --- diff --git a/t/20-each.t b/t/20-each.t index ca87e8a..dfc139b 100644 --- a/t/20-each.t +++ b/t/20-each.t @@ -7,8 +7,9 @@ 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 + 11 * (3 + 1 + 3 + 6); +use App::Rgit::Utils qw/:codes/; use App::Rgit; sub build { @@ -91,13 +92,15 @@ is(grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references'); '^n' ], @expected; -for my $cmd (qw/commit FAIL/) { +sub try { + my ($cmd, $exp, $policy) = @_; my ($fh, $filename) = tempfile(UNLINK => 1); 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/ ], + policy => $policy, ); isnt($ar, undef, "each $cmd has a defined object"); my $exit = $ar->run; @@ -105,7 +108,7 @@ for my $cmd (qw/commit FAIL/) { 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; @@ -118,3 +121,11 @@ SKIP: } } } + +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 };