Bug fix for merge diffs and a test.
[catagits/Gitalist.git] / t / 02git_object.t
index 750398e..2f5a4c8 100644 (file)
@@ -1,6 +1,7 @@
+use FindBin qw/$Bin/;
+BEGIN { do "$FindBin::Bin/../script/env" or die $@ }
 use strict;
 use warnings;
-use FindBin qw/$Bin/;
 use Test::More;
 use Test::Exception;
 use Data::Dumper;
@@ -58,8 +59,6 @@ my $commit_obj = Gitalist::Git::Object::Commit->new(
 );
 isa_ok($commit_obj, 'Gitalist::Git::Object::Commit', "commit object");
 my ($tree, $patch) = $commit_obj->diff(
-    parent => undef,
-    file => undef,
     patch => 1,
 );
 $patch = $patch->[0];
@@ -78,7 +77,9 @@ is($patch->{diff}, '--- a/file1
 ', 'patch->{diff} is correct');
 is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
 
-ok(index(do { local $/; my $fh = $commit_obj->get_patch; <$fh> },
+{
+    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>
 Date: Tue, 6 Mar 2007 20:39:45 +0100
@@ -95,10 +96,17 @@ index 257cc56..5716ca5 100644
 @@ -1 +1 @@
 -foo
 +bar
---') == 0, 'commit_obj->get_patch can return a patch');
-
-like(do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> },
-    qr!PATCH 2/2!, 'commit_obj->get_patch can return a patchset');
+--') == 0, 'commit_obj->get_patch can return a patch')
+    or warn("Got instead: $contents");
+}
 
+# Note - 2 patches = 3 parts due to where we split.
+{
+    my $contents = do { local $/; my $fh = $commit_obj->get_patch(undef, 3); <$fh> };
+    my @bits = split /Subject: \[PATC/, $contents;
+    is(scalar(@bits), 3,
+        'commit_obj->get_patch can return a patchset')
+        or warn("Contents was $contents");
+}
 done_testing;