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