X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Frgit.git;a=blobdiff_plain;f=t%2F21-once.t;h=51224ab8b5d38aa2442a1bcaba75434520b7acfb;hp=4e0c4ac8219bb671e5e9de5e7e7a3b264c2940eb;hb=HEAD;hpb=11ce663f56d70cbc0373c27c6dbe146823106e90 diff --git a/t/21-once.t b/t/21-once.t index 4e0c4ac..51224ab 100644 --- a/t/21-once.t +++ b/t/21-once.t @@ -3,32 +3,51 @@ use strict; use warnings; -use Cwd qw/abs_path/; -use File::Temp qw/tempfile/; +use Cwd qw; +use File::Temp qw; -use Test::More tests => 9 * 5; +use Test::More; use App::Rgit; +use lib 't/lib'; +use App::Rgit::TestUtils qw; + +my ($can_run, $reason) = can_run_git; +if ($can_run) { + plan tests => 9 * 5; +} else { + plan skip_all => "Can't run the mock git executable on this system: $reason"; +} + my @expected = ( - ([ [ qw/^n ^g ^w ^b ^^/ ] ]) x 5 + ([ [ qw<%n %g %w %b %%> ] ]) x 5 ); -for my $cmd (qw/daemon gui help init version/) { +local $ENV{GIT_DIR} = 't'; +local $ENV{GIT_EXEC_PATH} = 't/bin/git'; + +for my $cmd (qw) { my ($fh, $filename) = tempfile(UNLINK => 1); + my $ar = App::Rgit->new( - git => abs_path('t/bin/git'), - root => 't', + git => $ENV{GIT_EXEC_PATH}, + root => $ENV{GIT_DIR}, cmd => $cmd, - args => [ abs_path($filename), $cmd, qw/^n ^g ^w ^b ^^/ ] + args => [ abs_path($filename), $cmd, qw<%n %g %w %b %%> ], ); - isnt($ar, undef, "once $cmd has a defined object"); + isa_ok $ar, 'App::Rgit', "once $cmd is an App::Rgit object"; + my $exit = $ar->run; - is($exit, 0, "once $cmd returned 0"); + is $exit, 0, "once $cmd returned 0"; + my @lines = sort split /\n/, do { local $/; <$fh> }; - is(@lines, 1, "once $cmd visited only one repo"); + is @lines, 1, "once $cmd visited only one repo"; + my $r = [ split /\|/, defined $lines[0] ? $lines[0] : '' ]; - my $e = [ $cmd, qw/^n ^g ^w ^b ^^/ ]; - is($r->[$_], $e->[$_], "once $cmd argument $_ is ok") - for 0 .. 5; + my $e = [ $cmd, qw<%n %g %w %b %%> ]; + s/[\r\n]*$// for @$r; + for (0 .. 5) { + is $r->[$_], $e->[$_], "once $cmd argument $_ is ok"; + } }