]> git.vpit.fr Git - perl/modules/rgit.git/blob - t/20-each.t
Import rgit-0.01
[perl/modules/rgit.git] / t / 20-each.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Cwd qw/cwd abs_path/;
7 use File::Spec::Functions qw/catdir/;
8 use File::Temp qw/tempfile/;
9
10 use Test::More tests => 3 * 2;
11
12 use App::Rgit;
13
14 my $n = 3;
15
16 my @expected = (
17  undef,
18  [ [ 'a', 'a/.git', 'a',     'a.git' ] ],
19  [ [ 'b', 'b.git',  'b.git', 'b.git' ] ],
20  [
21    [ 'c', 'x/c/.git', 'x/c',     'x/c.git' ],
22    [ 'd', 'y/d.git',  'y/d.git', 'y/d.git' ],
23  ],
24 );
25
26 my $cwd = cwd;
27 my @repos = (undef, 
28              map { catdir $cwd, 't', 'repos', sprintf("%02d", $_) } 1 .. $n);
29 for my $i (1 .. $n) {
30  for my $a (@{$expected[$i]}) {
31   $a->[$_+3] = catdir($repos[$i], $a->[$_]) for 1 .. 3;
32   push @$a, $repos[$i], '^';
33  }
34 }
35
36 for (1 .. $n) {
37  my ($fh, $filename) = tempfile(UNLINK => 1);
38  my $exit = App::Rgit->new(
39   git  => abs_path('t/bin/git'),
40   root => $repos[$_],
41   cmd  => 'commit',
42   args => [ abs_path($filename), 'commit', qw/^n ^g ^w ^b ^G ^W ^B ^R ^^/ ]
43  )->run;
44  is($exit, 0, "each $_ returned 0");
45  my @lines = sort split /\n/, do { local $/; <$fh> };
46  my $res = [ map [ split /\|/, $_ ], @lines ];
47  my $exp = [ map [ 'commit', @$_ ], @{$expected[$_]} ];
48  is_deeply($res, $exp, "each $_ did the right thing");
49 }