File: 04-walker.t

package info (click to toggle)
libgit-raw-perl 0.79-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,448 kB
  • sloc: perl: 5,267; ansic: 182; makefile: 6
file content (130 lines) | stat: -rw-r--r-- 3,475 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!perl

use Test::More;

use Git::Raw;
use File::Spec::Functions qw(catfile rel2abs);

my $path = rel2abs(catfile('t', 'test_repo'));
my $repo = Git::Raw::Repository -> open($path);

my $walk = $repo -> walker;
ok (!eval { $walk -> sorting (['blah']) });
ok (!eval { $walk -> sorting ([[], undef]) });

$walk -> sorting (['time']);
$walk -> push($repo -> head -> target);
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next -> message, "initial commit\n";

is $walk -> next, undef;

$walk -> push($repo -> head -> target);
$walk->all();

$walk -> push($repo -> head -> target);
my $count = $walk->all();
is $count, 3;

$walk -> push($repo -> head -> target);
my @all = $walk->all();
is scalar(@all), 3;
is $all[0] -> summary, "third commit";
is $all[1] -> message, "second commit\n";
is $all[2] -> message, "initial commit\n";

# next after reset returns undef
$walk -> reset;
is $walk -> next, undef;

$walk -> push($repo -> head -> target);
$walk -> hide(($repo -> head -> target -> parents())[0]);
is $walk -> next -> summary, "third commit";
is $walk -> next, undef;

$walk -> push_glob('heads/*');
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next -> message, "initial commit\n";
is $walk -> next, undef;

$walk -> push_head;
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next -> message, "initial commit\n";
is $walk -> next, undef;


$walk -> push_head;
$walk -> sorting (['reverse', 'topological']);
is $walk -> next -> message, "initial commit\n";
is $walk -> next -> message, "second commit\n";
is $walk -> next -> summary, "third commit";
is $walk -> next, undef;
$walk -> sorting (['none']);

$walk -> push_ref('refs/heads/master');
my $end = $walk -> next;
is $end -> summary, "third commit";
is $walk -> next -> message, "second commit\n";

my $start = $walk -> next;
is $start -> message, "initial commit\n";
is $walk -> next, undef;

$walk -> push_head;

my $commit = $walk -> next;
isnt $commit, undef;
is   $commit -> summary, "third commit";
isnt $commit -> tree, undef;
isnt $commit -> parents, undef;

$walk -> reset;
$walk -> push_head;
$walk -> hide_head;
is $walk -> next, undef;

$walk -> reset;
$walk -> push_head;
$walk -> hide_ref('refs/heads/master');
is $walk -> next, undef;

$walk -> reset;
$walk -> push_head;
$walk -> hide_ref('refs/heads/master');
is $walk -> next, undef;

$walk -> reset;
$walk -> push_head;
$walk -> hide_glob('refs/heads/notmaster');
isnt $walk -> next, undef;

$walk -> reset;
ok (!eval { $walk -> push_range('zzz', $end) });
ok (!eval { $walk -> push_range($start, 'zzz') });

$walk -> reset;
$walk -> push_range($start, $end);
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next, undef;

$walk -> reset;
$walk -> push_range($start -> id . ".." . $end -> id);
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next, undef;

$walk -> reset;
$walk -> push_range(substr($start -> id, 0, 8), substr($end -> id, 0, 8));
is $walk -> next -> summary, "third commit";
is $walk -> next -> message, "second commit\n";
is $walk -> next, undef;

ok (!eval { $walk -> push_range(); });
ok (!eval { $walk -> push_range($start -> id . "." . $end -> id) });
ok (!eval { $walk -> push_range($start -> id . "..." . $end -> id) });

done_testing;