Skip to content

Commit a140c13

Browse files
committed
mailmap: Updates tests for new API and features
1 parent 8ff0504 commit a140c13

File tree

10 files changed

+153
-33
lines changed

10 files changed

+153
-33
lines changed

tests/mailmap/basic.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "clar_libgit2.h"
33

44
#include "common.h"
5-
#include "git2/mailmap.h"
5+
#include "mailmap.h"
66

77
static git_mailmap *mailmap = NULL;
88

@@ -41,27 +41,25 @@ void test_mailmap_basic__cleanup(void)
4141

4242
void test_mailmap_basic__entry(void)
4343
{
44+
size_t idx;
4445
const git_mailmap_entry *entry;
4546

46-
cl_assert_equal_sz(ARRAY_SIZE(expected), git_mailmap_entry_count(mailmap));
47+
/* Check that we have the expected # of entries */
48+
cl_assert_equal_sz(ARRAY_SIZE(expected), git_vector_length(&mailmap->entries));
49+
50+
for (idx = 0; idx < ARRAY_SIZE(expected); ++idx) {
51+
/* Try to look up each entry and make sure they match */
52+
entry = git_mailmap_entry_lookup(
53+
mailmap, expected[idx].replace_name, expected[idx].replace_email);
4754

48-
for (size_t i = 0; i < ARRAY_SIZE(expected); ++i) {
49-
entry = git_mailmap_entry_byindex(mailmap, i);
5055
cl_assert(entry);
51-
cl_assert_equal_s(entry->real_name, expected[i].real_name);
52-
cl_assert_equal_s(entry->real_email, expected[i].real_email);
53-
cl_assert_equal_s(entry->replace_name, expected[i].replace_name);
54-
cl_assert_equal_s(entry->replace_email, expected[i].replace_email);
56+
cl_assert_equal_s(entry->real_name, expected[idx].real_name);
57+
cl_assert_equal_s(entry->real_email, expected[idx].real_email);
58+
cl_assert_equal_s(entry->replace_name, expected[idx].replace_name);
59+
cl_assert_equal_s(entry->replace_email, expected[idx].replace_email);
5560
}
5661
}
5762

58-
void test_mailmap_basic__entry_large_index(void)
59-
{
60-
const git_mailmap_entry *entry =
61-
git_mailmap_entry_byindex(mailmap, 10000);
62-
cl_assert(!entry);
63-
}
64-
6563
void test_mailmap_basic__lookup_not_found(void)
6664
{
6765
const git_mailmap_entry *entry = git_mailmap_entry_lookup(

tests/mailmap/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "clar_libgit2.h"
22
#include "git2/repository.h"
33
#include "git2/blame.h"
4-
#include "git2/mailmap.h"
4+
#include "mailmap.h"
55
#include "mailmap_helpers.h"
66

77
static git_repository *g_repo;

tests/mailmap/mailmap_helpers.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "git2/mailmap.h"
1+
#include "mailmap.h"
22

33
typedef struct mailmap_entry {
44
const char *real_name;
@@ -42,11 +42,3 @@ static const mailmap_entry resolved[] = {
4242
{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
4343
{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" }
4444
};
45-
46-
static const mailmap_entry resolved_bare[] = {
47-
{ "xx", "untracked@company.xx", "xx", "untracked@company.xx" }
48-
};
49-
50-
static const mailmap_entry resolved_untracked[] = {
51-
{ "Untracked", "untracked@company.xx", "xx", "untracked@company.xx" }
52-
};

tests/mailmap/parsing.c

Lines changed: 133 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,41 @@
22
#include "repository.h"
33
#include "git2/sys/repository.h"
44
#include "mailmap_helpers.h"
5+
#include "buf_text.h"
56

67
static git_repository *g_repo;
78
static git_mailmap *g_mailmap;
9+
static git_config *g_config;
810

911
void test_mailmap_parsing__initialize(void)
1012
{
1113
g_repo = NULL;
1214
g_mailmap = NULL;
15+
g_config = NULL;
1316
}
1417

1518
void test_mailmap_parsing__cleanup(void)
1619
{
1720
git_mailmap_free(g_mailmap);
21+
git_config_free(g_config);
1822
cl_git_sandbox_cleanup();
1923
}
2024

2125
static void check_mailmap_entries(
2226
const git_mailmap *mailmap, const mailmap_entry *entries, size_t entries_size)
2327
{
24-
const git_mailmap_entry *parsed = NULL;
28+
const git_mailmap_entry *parsed;
2529
size_t idx;
2630

27-
/* Check that the parsed entries match */
28-
cl_assert_equal_sz(entries_size, git_mailmap_entry_count(mailmap));
31+
/* Check the correct # of entries were parsed */
32+
cl_assert_equal_sz(entries_size, git_vector_length(&mailmap->entries));
33+
34+
/* Make sure looking up each entry succeeds */
2935
for (idx = 0; idx < entries_size; ++idx) {
30-
parsed = git_mailmap_entry_byindex(mailmap, idx);
36+
parsed = git_mailmap_entry_lookup(
37+
mailmap, entries[idx].replace_name, entries[idx].replace_email);
38+
39+
cl_assert(parsed);
3140
cl_assert_equal_s(parsed->real_name, entries[idx].real_name);
3241
cl_assert_equal_s(parsed->real_email, entries[idx].real_email);
3342
cl_assert_equal_s(parsed->replace_name, entries[idx].replace_name);
@@ -52,6 +61,10 @@ static void check_mailmap_resolve(
5261
}
5362
}
5463

64+
static const mailmap_entry resolved_untracked[] = {
65+
{ "Untracked", "untracked@company.xx", "xx", "untracked@company.xx" }
66+
};
67+
5568
void test_mailmap_parsing__string(void)
5669
{
5770
git_buf buf = GIT_BUF_INIT;
@@ -77,7 +90,7 @@ void test_mailmap_parsing__windows_string(void)
7790
git_buf_text_lf_to_crlf(&winbuf, &unixbuf);
7891

7992
cl_git_pass(git_mailmap_from_buffer(&g_mailmap, &winbuf));
80-
git_buf_free(winbuf);
93+
git_buf_free(&winbuf);
8194

8295
/* We should have parsed all of the entries */
8396
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
@@ -93,7 +106,7 @@ void test_mailmap_parsing__fromrepo(void)
93106
g_repo = cl_git_sandbox_init("mailmap");
94107
cl_check(!git_repository_is_bare(g_repo));
95108

96-
cl_git_pass(git_mailmap_from_repo(&g_mailmap, g_repo));
109+
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
97110

98111
/* We should have parsed all of the entries */
99112
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries));
@@ -104,13 +117,17 @@ void test_mailmap_parsing__fromrepo(void)
104117
g_mailmap, resolved_untracked, ARRAY_SIZE(resolved_untracked));
105118
}
106119

120+
static const mailmap_entry resolved_bare[] = {
121+
{ "xx", "untracked@company.xx", "xx", "untracked@company.xx" }
122+
};
123+
107124
void test_mailmap_parsing__frombare(void)
108125
{
109126
g_repo = cl_git_sandbox_init("mailmap/.gitted");
110127
cl_git_pass(git_repository_set_bare(g_repo));
111128
cl_check(git_repository_is_bare(g_repo));
112129

113-
cl_git_pass(git_mailmap_from_repo(&g_mailmap, g_repo));
130+
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
114131

115132
/* We should have parsed all of the entries, except for the untracked one */
116133
check_mailmap_entries(g_mailmap, entries, ARRAY_SIZE(entries) - 1);
@@ -120,3 +137,112 @@ void test_mailmap_parsing__frombare(void)
120137
check_mailmap_resolve(
121138
g_mailmap, resolved_bare, ARRAY_SIZE(resolved_bare));
122139
}
140+
141+
static const mailmap_entry resolved_with_file_override[] = {
142+
{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
143+
{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
144+
{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
145+
{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
146+
{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
147+
{ "Other Author", "other@author.xx", "Some Garbage", "nick2@company.xx" },
148+
{ "Joseph", "joseph@company.xx", "Joseph", "bugs@company.xx" },
149+
{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
150+
{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
151+
152+
/* This name is overridden by file_override */
153+
{ "File Override", "phil@company.xx", "unknown", "phil@company.xx" },
154+
{ "Other Name", "fileoverridename@company.xx", "override", "fileoverridename@company.xx" }
155+
};
156+
157+
void test_mailmap_parsing__file_config(void)
158+
{
159+
g_repo = cl_git_sandbox_init("mailmap");
160+
cl_git_pass(git_repository_config(&g_config, g_repo));
161+
162+
cl_git_pass(git_config_set_string(
163+
g_config, "mailmap.file", cl_fixture("mailmap/file_override")));
164+
165+
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
166+
167+
/* Check we don't have duplicate entries */
168+
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
169+
170+
/* Check that resolving the entries works */
171+
check_mailmap_resolve(
172+
g_mailmap, resolved_with_file_override,
173+
ARRAY_SIZE(resolved_with_file_override));
174+
}
175+
176+
static const mailmap_entry resolved_with_blob_override[] = {
177+
{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
178+
{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
179+
{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
180+
{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
181+
{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
182+
{ "Other Author", "other@author.xx", "Some Garbage", "nick2@company.xx" },
183+
{ "Joseph", "joseph@company.xx", "Joseph", "bugs@company.xx" },
184+
{ "Santa Claus", "santa.claus@northpole.xx", "Clause", "me@company.xx" },
185+
{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
186+
187+
/* This name is overridden by blob_override */
188+
{ "Blob Override", "phil@company.xx", "unknown", "phil@company.xx" },
189+
{ "Other Name", "bloboverridename@company.xx", "override", "bloboverridename@company.xx" }
190+
};
191+
192+
void test_mailmap_parsing__blob_config(void)
193+
{
194+
g_repo = cl_git_sandbox_init("mailmap");
195+
cl_git_pass(git_repository_config(&g_config, g_repo));
196+
197+
cl_git_pass(git_config_set_string(
198+
g_config, "mailmap.blob", "HEAD:blob_override"));
199+
200+
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
201+
202+
/* Check we don't have duplicate entries */
203+
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 9);
204+
205+
/* Check that resolving the entries works */
206+
check_mailmap_resolve(
207+
g_mailmap, resolved_with_blob_override,
208+
ARRAY_SIZE(resolved_with_blob_override));
209+
}
210+
211+
static const mailmap_entry bare_resolved_with_blob_override[] = {
212+
/* As mailmap.blob is set, we won't load HEAD:.mailmap */
213+
{ "Brad", "cto@coompany.xx", "Brad", "cto@coompany.xx" },
214+
{ "Brad L", "cto@coompany.xx", "Brad L", "cto@coompany.xx" },
215+
{ "nick1", "bugs@company.xx", "nick1", "bugs@company.xx" },
216+
{ "nick2", "bugs@company.xx", "nick2", "bugs@company.xx" },
217+
{ "nick3", "bugs@company.xx", "nick3", "bugs@company.xx" },
218+
{ "Some Garbage", "nick2@company.xx", "Some Garbage", "nick2@company.xx" },
219+
{ "Joseph", "bugs@company.xx", "Joseph", "bugs@company.xx" },
220+
{ "Clause", "me@company.xx", "Clause", "me@company.xx" },
221+
{ "Charles", "charles@charles.xx", "Charles", "charles@charles.xx" },
222+
223+
/* This name is overridden by blob_override */
224+
{ "Blob Override", "phil@company.xx", "unknown", "phil@company.xx" },
225+
{ "Other Name", "bloboverridename@company.xx", "override", "bloboverridename@company.xx" }
226+
};
227+
228+
void test_mailmap_parsing__bare_blob_config(void)
229+
{
230+
g_repo = cl_git_sandbox_init("mailmap/.gitted");
231+
cl_git_pass(git_repository_set_bare(g_repo));
232+
cl_check(git_repository_is_bare(g_repo));
233+
234+
cl_git_pass(git_repository_config(&g_config, g_repo));
235+
236+
cl_git_pass(git_config_set_string(
237+
g_config, "mailmap.blob", "HEAD:blob_override"));
238+
239+
cl_git_pass(git_mailmap_from_repository(&g_mailmap, g_repo));
240+
241+
/* Check that we only have the 2 entries */
242+
cl_assert_equal_sz(git_vector_length(&g_mailmap->entries), 2);
243+
244+
/* Check that resolving the entries works */
245+
check_mailmap_resolve(
246+
g_mailmap, bare_resolved_with_blob_override,
247+
ARRAY_SIZE(bare_resolved_with_blob_override));
248+
}
80 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��[j�0E�U���B�_��2Ҍ��mE-$���;�߹.�\�u�`z�8`dm���)YK�32�x��(��S���`�t�$ρ%ю�#�<��K
2+
ل�V�ӧ��k�|��%��m_�>��/�\�3�`���!‡�Z���]޼�+3�����+��,�}ZL{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7100e631fb4d5deba31fdc8acc98f4fb5c1573fd
1+
f63578091d884c3066a003c50eb6c85ae7542269
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
File Override <phil@company.xx>
2+
Other Name <fileoverridename@company.xx>

0 commit comments

Comments
 (0)