Make test for diff output more flexible.
[catagits/Gitalist.git] / t / 02git_object.t
index 16521a0..72b3755 100644 (file)
@@ -24,7 +24,7 @@ BEGIN {
     use_ok 'Gitalist::Git::Object::Blob';
     use_ok 'Gitalist::Git::Object::Commit';
     use_ok 'Gitalist::Git::Object::Tag';
-    }
+}
 
 my $object = Gitalist::Git::Object::Tree->new(
     repository => $repository,
@@ -54,7 +54,7 @@ cmp_deeply $object->pack, {
              __CLASS__   => 'Gitalist::Git::Repository',
              description => 'some test repository',
              is_bare     => 1,
-             last_change => '2009-11-12T19:00:34Z',
+             last_change => '2011-06-05T23:00:44Z',
              name        => 'repo1',
              owner       => code(\&is_system_account_name),
          },
@@ -93,7 +93,7 @@ cmp_deeply $obj2->pack,  {
              __CLASS__   => 'Gitalist::Git::Repository',
              description => 'some test repository',
              is_bare     => 1,
-             last_change => '2009-11-12T19:00:34Z',
+             last_change => '2011-06-05T23:00:44Z',
              name        => 'repo1',
              owner       => code(\&is_system_account_name),
          },
@@ -120,7 +120,7 @@ cmp_deeply $commit_obj->pack,  {
              __CLASS__   => 'Gitalist::Git::Repository',
              description => 'some test repository',
              is_bare     => 1,
-             last_change => '2009-11-12T19:00:34Z',
+             last_change => '2011-06-05T23:00:44Z',
              name        => 'repo1',
              owner       => code(\&is_system_account_name),
          },
@@ -137,7 +137,7 @@ cmp_deeply $commit_obj->pack,  {
                  __CLASS__   => 'Gitalist::Git::Repository',
                  description => 'some test repository',
                  is_bare     => 1,
-                 last_change => '2009-11-12T19:00:34Z',
+                 last_change => '2011-06-05T23:00:44Z',
                  name        => 'repo1',
                  owner       => code(\&is_system_account_name),
              },
@@ -169,15 +169,14 @@ is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is c
 
 {
     my $contents = do { local $/; my $fh = $commit_obj->get_patch; <$fh> };
-ok(index($contents,
-'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
-From: Florian Ragwitz <rafl@debian.org>
+like $contents, qr{^\QFrom 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
+From: Florian Ragwitz <\Erafl[@]debian\Q.org>
 Date: Tue, 6 Mar 2007 20:39:45 +0100
 Subject: [PATCH] bar
 
 ---
- file1 |    2 +-
- 1 files changed, 1 insertions(+), 1 deletions(-)
+ file1 |\E\s+2\Q +-
+ 1 \Efiles?\Q changed, 1 \Einsertions?\Q(+), 1 \Edeletions?\Q(-)
 
 diff --git a/file1 b/file1
 index 257cc56..5716ca5 100644
@@ -186,8 +185,7 @@ index 257cc56..5716ca5 100644
 @@ -1 +1 @@
 -foo
 +bar
---') == 0, 'commit_obj->get_patch can return a patch')
-    or warn("Got instead: $contents");
+--}, 'commit_obj->get_patch can return a patch';
 }
 
 # Note - 2 patches = 3 parts due to where we split.
@@ -198,6 +196,19 @@ index 257cc56..5716ca5 100644
         'commit_obj->get_patch can return a patchset')
         or warn("Contents was $contents");
 }
+
+my $blame_this = Gitalist::Git::Object::Commit->new(
+    repository => $repository,
+    sha1       => 'd6ddf8b26be63066e01d96a0922c87cd8d6e2270',
+);
+
+{
+    local $SIG{ALRM} = sub { die "Regressions suck!" };
+    alarm 1;
+    eval { $blame_this->blame('empty-for-a-reason', $blame_this->sha1) };
+    is $@, '', "Silly infinite loop didn't manifest for an empty file.";
+}
+
 done_testing;
 
 sub is_system_account_name {