File: 20-pathspec.t

package info (click to toggle)
libgit-raw-perl 0.90%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,456 kB
  • sloc: perl: 5,426; ansic: 182; makefile: 6
file content (135 lines) | stat: -rw-r--r-- 3,114 bytes parent folder | download | duplicates (3)
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
131
132
133
134
135
#!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 @status = $repo->status({});

ok (!eval { Git::Raw::PathSpec -> new });
my $error = $@;
isa_ok $error, 'Git::Raw::Error';
is $error -> code, Git::Raw::Error -> USAGE;
is $error -> category, Git::Raw::Error::Category -> INTERNAL;

ok (!eval { Git::Raw::PathSpec -> new($repo) });
$error = $@;
isa_ok $error, 'Git::Raw::Error';

my $spec = Git::Raw::PathSpec -> new('blah');
isa_ok $spec, 'Git::Raw::PathSpec';

my $list;

ok (!eval { $spec -> match('') });
$error = $@;
isa_ok $error, 'Git::Raw::Error';
is $error -> code, Git::Raw::Error -> USAGE;
is $error -> category, Git::Raw::Error::Category -> INTERNAL;

ok (!eval { $list = $spec -> match($repo, {
	'flags' => {
		'no_match_error' => 1
	}
}) });

$list = $spec -> match($repo);
isa_ok $list, 'Git::Raw::PathSpec::MatchList';

is $list -> count, 0;
is $list -> failed_count, 0;

$list = $spec -> match($repo, {
	'flags' => {
		'find_failures' => 1
	}
});

is $list -> count, 0;
is $list -> failed_count, 1;

my @failures = $list -> failed_entries;
is scalar(@failures), 1;
my $failure = shift @failures;
is $failure, 'blah';

$spec = Git::Raw::PathSpec -> new('t*');
$list = $spec -> match($repo);
is $list -> count, 2;

my @entries = $list -> entries;
is scalar(@entries), 2;
is_deeply [ @entries ], ['test', 'test2'];

$list = $spec -> match($repo -> index);
is $list -> count, 2;

$spec = Git::Raw::PathSpec -> new('t*', 'untra*');
$list = $spec -> match($repo, {
	'flags' => {
		'find_failures' => 1
	}
});

is $list -> count, 2;
is $list -> failed_count, 1;

$spec = Git::Raw::PathSpec -> new('T*');
$list = $spec -> match($repo, {
	'flags' => {
		'find_failures' => 1,
		'ignore_case'   => 1
	}
});

is $list -> count, 2;

my $filter_branch = Git::Raw::Branch -> lookup($repo, 'filter_branch', 1);
isa_ok $filter_branch, 'Git::Raw::Branch';

$spec = Git::Raw::PathSpec -> new('T*', 'f*');
$list = $spec -> match($filter_branch -> target -> tree, {
	'flags' => {
		'ignore_case'   => 1
	}
});

@entries = $list -> entries;
is $list -> count, 3;
is_deeply [ @entries ], ['filterfile', 'test', 'test2'];

my $some_branch = Git::Raw::Branch -> lookup($repo, 'some_branch', 1);
isa_ok $some_branch, 'Git::Raw::Branch';
isa_ok $some_branch, 'Git::Raw::Reference';
my $commit = $some_branch -> target;
isa_ok $commit, 'Git::Raw::Commit';

$list = $spec -> match($commit -> tree, {
	'flags' => {
		'ignore_case'   => 1
	}
});
is $list -> count, 3;

@entries = $list -> entries;
is_deeply [ @entries ], ['test', 'test2', 'test3/under/the/tree/test3'];

$spec = Git::Raw::PathSpec -> new('test*');
$list = $spec -> match($commit -> tree);
is $list -> count, 3;

@entries = $list -> entries;
is_deeply [ @entries ], ['test', 'test2', 'test3/under/the/tree/test3'];

$spec = Git::Raw::PathSpec -> new('**/test*');
$list = $spec -> match($commit -> tree);
is $list -> count, 1;

@entries = $list -> entries;
is_deeply [ @entries ], ['test3/under/the/tree/test3'];

done_testing;