]>
git.proxmox.com Git - libgit2.git/blob - tests/object/tag/list.c
8a1a2d26d2df36e66d0c63c55c3e0199eb77b12f
1 #include "clar_libgit2.h"
5 static git_repository
*g_repo
;
7 #define MAX_USED_TAGS 6
12 const size_t expected_matches
;
13 const char* expected_results
[MAX_USED_TAGS
];
17 static void ensure_tag_pattern_match(git_repository
*repo
,
18 const struct pattern_match_t
* data
)
20 int already_found
[MAX_USED_TAGS
] = { 0 };
21 git_strarray tag_list
;
23 size_t sucessfully_found
= 0;
26 cl_assert(data
->expected_matches
<= MAX_USED_TAGS
);
28 if ((error
= git_tag_list_match(&tag_list
, data
->pattern
, repo
)) < 0)
31 if (tag_list
.count
!= data
->expected_matches
)
37 /* we have to be prepared that tags come in any order. */
38 for (i
= 0; i
< tag_list
.count
; i
++)
40 for (j
= 0; j
< data
->expected_matches
; j
++)
42 if (!already_found
[j
] && !strcmp(data
->expected_results
[j
], tag_list
.strings
[i
]))
50 cl_assert_equal_i((int)sucessfully_found
, (int)data
->expected_matches
);
53 git_strarray_dispose(&tag_list
);
57 /* Fixture setup and teardown */
58 void test_object_tag_list__initialize(void)
60 g_repo
= cl_git_sandbox_init("testrepo");
63 void test_object_tag_list__cleanup(void)
65 cl_git_sandbox_cleanup();
68 void test_object_tag_list__list_all(void)
70 /* list all tag names from the repository */
71 git_strarray tag_list
;
73 cl_git_pass(git_tag_list(&tag_list
, g_repo
));
75 cl_assert_equal_i((int)tag_list
.count
, 6);
77 git_strarray_dispose(&tag_list
);
80 static const struct pattern_match_t matches
[] = {
81 /* All tags, including a packed one and two namespaced ones. */
82 { "", 6, { "e90810b", "point_to_blob", "test", "packed-tag", "foo/bar", "foo/foo/bar" } },
85 { "t*", 1, { "test" } },
88 { "*b", 2, { "e90810b", "point_to_blob" } },
92 { "e90810b", 1, { "e90810b" } },
95 { "e90810[ab]", 1, { "e90810b" } },
97 /* glob in the middle */
98 { "foo/*/bar", 1, { "foo/foo/bar" } },
101 * The matching of '*' is based on plain string matching analog to the regular expression ".*"
102 * => a '/' in the tag name has no special meaning.
103 * Compare to `git tag -l "*bar"`
105 { "*bar", 2, { "foo/bar", "foo/foo/bar" } },
111 void test_object_tag_list__list_by_pattern(void)
113 /* list all tag names from the repository matching a specified pattern */
115 while (matches
[i
].pattern
)
116 ensure_tag_pattern_match(g_repo
, &matches
[i
++]);