|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use Test::More; |
| 5 | + |
| 6 | +# FILENAME: 08_has_ancestor.t |
| 7 | +# CREATED: 31/05/12 07:48:42 by Kent Fredric (kentnl) <kentfredric@gmail.com> |
| 8 | +# ABSTRACT: Tests for has_ancestor |
| 9 | +use strict; |
| 10 | +use warnings; |
| 11 | +use Test::More; |
| 12 | +use Git::PurePerl; |
| 13 | +use Path::Class; |
| 14 | + |
| 15 | +sub shatrim { |
| 16 | + return substr( shift, 0, 8 ); |
| 17 | +} |
| 18 | + |
| 19 | +sub repo_ancestor_check { |
| 20 | + my ( $repo, $commit, @ancestors ) = @_; |
| 21 | + my $git = Git::PurePerl->new( directory => $repo ); |
| 22 | + my $commit_obj = $git->get_object($commit); |
| 23 | + for my $ancestor (@ancestors) { |
| 24 | + my ( $tcommit, $tancestor ) = map { shatrim($_) } $commit, $ancestor; |
| 25 | + ok( |
| 26 | + $commit_obj->has_ancestor_sha1($ancestor), |
| 27 | + "$repo @ $tcommit has ancestor $tancestor" |
| 28 | + ); |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +sub repo_ancestor_not_check { |
| 33 | + my ( $repo, $commit, @ancestors ) = @_; |
| 34 | + my $git = Git::PurePerl->new( directory => $repo ); |
| 35 | + my $commit_obj = $git->get_object($commit); |
| 36 | + for my $ancestor (@ancestors) { |
| 37 | + my ( $tcommit, $tancestor ) = map { shatrim($_) } $commit, $ancestor; |
| 38 | + ok( |
| 39 | + !$commit_obj->has_ancestor_sha1($ancestor), |
| 40 | + "$repo @ $tcommit has no ancestor $tancestor" |
| 41 | + ); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +repo_ancestor_check( |
| 46 | + 'test-project' => '0c7b3d23c0f821e58cd20e60d5e63f5ed12ef391' => qw( |
| 47 | + a47f812b901251922153bac347a348604a24e372 |
| 48 | + d24a32a404ce934cd4f39fd632fc1d43c413f652 |
| 49 | + ) |
| 50 | +); |
| 51 | + |
| 52 | +repo_ancestor_check( |
| 53 | + 'test-project' => 'a47f812b901251922153bac347a348604a24e372' => qw( |
| 54 | + d24a32a404ce934cd4f39fd632fc1d43c413f652 |
| 55 | + ) |
| 56 | +); |
| 57 | + |
| 58 | +repo_ancestor_not_check( |
| 59 | + 'test-project' => '0c7b3d23c0f821e58cd20e60d5e63f5ed12ef391' => qw( |
| 60 | + deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
| 61 | + ) |
| 62 | +); |
| 63 | + |
| 64 | +repo_ancestor_not_check( |
| 65 | + 'test-project' => 'a47f812b901251922153bac347a348604a24e372' => qw( |
| 66 | + 0c7b3d23c0f821e58cd20e60d5e63f5ed12ef391 |
| 67 | + deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
| 68 | + ) |
| 69 | +); |
| 70 | +repo_ancestor_not_check( |
| 71 | + 'test-project' => 'd24a32a404ce934cd4f39fd632fc1d43c413f652' => qw( |
| 72 | + 0c7b3d23c0f821e58cd20e60d5e63f5ed12ef391 |
| 73 | + deadbeefdeadbeefdeadbeefdeadbeefdeadbeef |
| 74 | + a47f812b901251922153bac347a348604a24e372 |
| 75 | + ) |
| 76 | +); |
| 77 | + |
| 78 | +done_testing; |
| 79 | + |
0 commit comments