]> git.vpit.fr Git - perl/modules/rgit.git/commitdiff
Since we can't store our fake .git dirs in a git repo, generate them at test time
authorVincent Pit <vince@profvince.com>
Sun, 5 Oct 2008 21:27:14 +0000 (23:27 +0200)
committerVincent Pit <vince@profvince.com>
Sun, 5 Oct 2008 21:27:14 +0000 (23:27 +0200)
MANIFEST
t/20-each.t
t/repos/02/b.git/HEAD [deleted file]
t/repos/02/b.git/objects/dummy [deleted file]
t/repos/02/b.git/refs/dummy [deleted file]
t/repos/02/x.git/objects/dummy [deleted file]
t/repos/02/x.git/refs/dummy [deleted file]
t/repos/03/y/d.git/HEAD [deleted file]
t/repos/03/y/d.git/objects/dummy [deleted file]
t/repos/03/y/d.git/refs/dummy [deleted file]

index 9b11f252f06d65313990e0d38b74d1b5b4fc115d..1a06343add5770158961c4d232a07233cb54ed99 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -21,18 +21,3 @@ t/92-pod-coverage.t
 t/95-portability-files.t
 t/99-kwalitee.t
 t/bin/git
-t/repos/01/a/.git/HEAD
-t/repos/01/a/.git/objects/dummy
-t/repos/01/a/.git/refs/dummy
-t/repos/01/x/.git/refs/dummy
-t/repos/02/b.git/HEAD
-t/repos/02/b.git/objects/dummy
-t/repos/02/b.git/refs/dummy
-t/repos/02/x.git/refs/dummy
-t/repos/02/x.git/objects/dummy
-t/repos/03/x/c/.git/HEAD
-t/repos/03/x/c/.git/objects/dummy
-t/repos/03/x/c/.git/refs/dummy
-t/repos/03/y/d.git/HEAD
-t/repos/03/y/d.git/objects/dummy
-t/repos/03/y/d.git/refs/dummy
index 12223f6f0ee855d62010fd89fb9234c9a06dcd2b..5e8c8fdf6fdd1608e189d4fe19cc2fb4b929960c 100644 (file)
@@ -4,46 +4,106 @@ use strict;
 use warnings;
 
 use Cwd qw/cwd abs_path/;
-use File::Spec::Functions qw/catdir/;
-use File::Temp qw/tempfile/;
+use File::Spec::Functions qw/catdir catfile/;
+use File::Temp qw/tempfile tempdir/;
 
-use Test::More tests => 3 * 2;
+use Test::More tests => 2 + 3 * 1;
 
 use App::Rgit;
 
-my $n = 3;
+sub build {
+ my ($tree, $prefix) = @_;
+ my @ret;
+ my $r = delete $tree->{_};
+ while (my ($d, $v) = each %$tree) {
+  if (ref $v) {
+   my $dir = catdir $prefix, $d;
+   mkdir $dir or die "mkdir($dir): $!";
+   my @r = build($v, $dir);
+   push @ret, map [
+               $_->[0],
+               ref eq 'main' ? @{$_}[1 .. 3]
+                             : map { catdir($d, $_) } @{$_}[1 .. 3]
+              ], @r unless $r;
+  } else {
+   my $file = catfile($prefix, $d);
+   open my $fh, '>', $file or die "open($file): $!";
+   print $fh $v;
+   close $fh;
+  }
+ }
+ return $r ? bless $r, 'main' : @ret;
+}
 
-my @expected = (
- undef,
- [ [ 'a', 'a/.git', 'a',     'a.git' ] ],
- [ [ 'b', 'b.git',  'b.git', 'b.git' ] ],
- [
-   [ 'c', 'x/c/.git', 'x/c',     'x/c.git' ],
-   [ 'd', 'y/d.git',  'y/d.git', 'y/d.git' ],
- ],
-);
+my $repogit = {
+ HEAD    => 1,
+ refs    => { dummy => 1 },
+ objects => { dummy => 1 },
+};
+
+sub repo {
+ my ($n, $bare) = @_;
+ return $bare ? [ $n, "$n.git",           "$n.git", "$n.git" ]
+              : [ $n, catdir($n, '.git'), $n,       "$n.git" ]
+}
 
+my $tmpdir = tempdir(CLEANUP => 1);
 my $cwd = cwd;
-my @repos = (undef, 
-             map { catdir $cwd, 't', 'repos', sprintf("%02d", $_) } 1 .. $n);
-for my $i (1 .. $n) {
- for my $a (@{$expected[$i]}) {
-  $a->[$_+3] = catdir($repos[$i], $a->[$_]) for 1 .. 3;
-  push @$a, $repos[$i], '^';
+chdir $tmpdir or die "chdir($tmpdir): $!";
+my @expected = sort { $a->[0] cmp $b->[0] } build({
+ x => {
+  a => {
+   _ => repo('a', 0),
+   '.git' => $repogit
+  },
+  z => {
+   '.git' => {
+    HEAD => 1
+   }
+  }
+ },
+ y => {
+  'b.git' => {
+   _ => repo('b', 1),
+   %$repogit
+  },
+  't' => {
+   't.git' => {
+    HEAD => 1,
+    refs => { dummy => 1 },
+   }
+  }
+ },
+ c => {
+  _ => repo('c', 0),
+  '.git' => $repogit
  }
-}
+}, '.');
+chdir $cwd or die "chdir($cwd): $!";
+
+is(@expected, 3, 'only three valid git repos');
+is(grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references');
+
+@expected = map [
+             @$_,
+             map({ catdir($tmpdir, $_) } @{$_}[1 .. 3]),
+             $tmpdir,
+             '^n'
+            ], @expected;
 
-for (1 .. $n) {
+for my $cmd (qw/commit/) {
  my ($fh, $filename) = tempfile(UNLINK => 1);
- my $exit = App::Rgit->new(
+ my $ar = App::Rgit->new(
   git  => abs_path('t/bin/git'),
-  root => $repos[$_],
-  cmd  => 'commit',
-  args => [ abs_path($filename), 'commit', qw/^n ^g ^w ^b ^G ^W ^B ^R ^^/ ]
- )->run;
- is($exit, 0, "each $_ returned 0");
+  root => $tmpdir,
+  cmd  => $cmd,
+  args => [ abs_path($filename), $cmd, qw/^n ^g ^w ^b ^G ^W ^B ^R ^^n/ ]
+ );
+ isnt($ar, undef, "each $cmd has a defined object");
+ my $exit = $ar->run;
+ is($exit, 0, "each $cmd returned 0");
  my @lines = sort split /\n/, do { local $/; <$fh> };
  my $res = [ map [ split /\|/, $_ ], @lines ];
- my $exp = [ map [ 'commit', @$_ ], @{$expected[$_]} ];
- is_deeply($res, $exp, "each $_ did the right thing");
+ my $exp = [ map [ $cmd, @$_ ], @expected ];
+ is_deeply($res, $exp, "each $cmd did the right thing");
 }
diff --git a/t/repos/02/b.git/HEAD b/t/repos/02/b.git/HEAD
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/02/b.git/objects/dummy b/t/repos/02/b.git/objects/dummy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/02/b.git/refs/dummy b/t/repos/02/b.git/refs/dummy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/02/x.git/objects/dummy b/t/repos/02/x.git/objects/dummy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/02/x.git/refs/dummy b/t/repos/02/x.git/refs/dummy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/03/y/d.git/HEAD b/t/repos/03/y/d.git/HEAD
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/03/y/d.git/objects/dummy b/t/repos/03/y/d.git/objects/dummy
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/t/repos/03/y/d.git/refs/dummy b/t/repos/03/y/d.git/refs/dummy
deleted file mode 100644 (file)
index e69de29..0000000