6 use Cwd qw/cwd abs_path/;
7 use File::Spec::Functions qw/catdir catfile/;
8 use File::Temp qw/tempfile tempdir/;
10 use Test::More tests => 2 + 2 * 4 + 11 * (3 + 1 + 3 + 6);
12 use App::Rgit::Utils qw/:codes/;
16 my ($tree, $prefix) = @_;
18 my $r = delete $tree->{_};
19 while (my ($d, $v) = each %$tree) {
21 my $dir = catdir $prefix, $d;
22 mkdir $dir or die "mkdir($dir): $!";
23 my @r = build($v, $dir);
26 ref eq 'main' ? @{$_}[1 .. 3]
27 : map { catdir($d, $_) } @{$_}[1 .. 3]
30 my $file = catfile($prefix, $d);
31 open my $fh, '>', $file or die "open($file): $!";
36 return $r ? bless $r, 'main' : @ret;
41 refs => { dummy => 1 },
42 objects => { dummy => 1 },
47 return $bare ? [ $n, "$n.git", "$n.git", "$n.git" ]
48 : [ $n, catdir($n, '.git'), $n, "$n.git" ]
51 my $tmpdir = tempdir(CLEANUP => 1);
53 chdir $tmpdir or die "chdir($tmpdir): $!";
54 my @expected = sort { $a->[1] cmp $b->[1] } build({
62 refs => { dummy => 1 },
73 refs => { dummy => 1 },
74 objects => { dummy => 1 },
83 chdir $cwd or die "chdir($cwd): $!";
85 is(@expected, 3, 'only three valid git repos');
86 is(grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references');
90 map({ catdir($tmpdir, $_) } @{$_}[1 .. 3]),
96 my ($cmd, $exp, $policy) = @_;
97 my ($fh, $filename) = tempfile(UNLINK => 1);
98 my $ar = App::Rgit->new(
99 git => abs_path('t/bin/git'),
102 args => [ abs_path($filename), $cmd, qw/^n ^g ^w ^b ^G ^W ^B ^R ^^n/ ],
105 isnt($ar, undef, "each $cmd has a defined object");
107 my $fail = $cmd eq 'FAIL' ? 1 : 0;
109 ($exit, undef) = $ar->run;
113 is($exit, $fail, "each $cmd returned $fail");
114 my @lines = split /\n/, do { local $/; <$fh> };
115 my $res = [ map [ split /\|/, $_ ], @lines ];
116 $exp = [ map [ $cmd, @$_ ], @$exp ];
117 for my $i (0 .. $#$exp) {
120 isnt($r, undef, "each $cmd visited repository $i");
123 skip 'didn\'t visited that repo' => 10 unless defined $r;
124 is($r->[$_], $e->[$_], "each $cmd argument $_ for repository $i is ok")
130 try 'commit', [ @expected ];
131 try 'FAIL', [ $expected[0] ];
132 try 'FAIL', [ @expected ],
135 try 'FAIL', [ map { ($expected[$_]) x 2 } 0 .. $#expected ],
136 sub { my $ret = $c ? undef : REDO; $c = 1 - $c; $ret };