Skip to content

Commit df417a4

Browse files
committed
tests: attr: verify that in-memory macros are respected
Add some tests to ensure that the `git_attr_add_macro` function works as expected.
1 parent 4a7f704 commit df417a4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/attr/macro.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
#include "clar_libgit2.h"
9+
10+
#include "git2/sys/repository.h"
911
#include "attr.h"
1012

1113
static git_repository *g_repo = NULL;
@@ -122,3 +124,56 @@ void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void)
122124
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
123125
cl_assert_equal_s(value, "second");
124126
}
127+
128+
void test_attr_macro__adding_macro_succeeds(void)
129+
{
130+
const char *value;
131+
132+
g_repo = cl_git_sandbox_init("empty_standard_repo");
133+
cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value"));
134+
cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro\n");
135+
136+
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
137+
cl_assert_equal_s(value, "value");
138+
}
139+
140+
void test_attr_macro__adding_boolean_macros_succeeds(void)
141+
{
142+
const char *value;
143+
144+
g_repo = cl_git_sandbox_init("empty_standard_repo");
145+
cl_git_pass(git_attr_add_macro(g_repo, "macro-pos", "positive"));
146+
cl_git_pass(git_attr_add_macro(g_repo, "macro-neg", "-negative"));
147+
cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro-pos macro-neg\n");
148+
149+
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "positive"));
150+
cl_assert(GIT_ATTR_IS_TRUE(value));
151+
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "negative"));
152+
cl_assert(GIT_ATTR_IS_FALSE(value));
153+
}
154+
155+
void test_attr_macro__redefining_macro_succeeds(void)
156+
{
157+
const char *value;
158+
159+
g_repo = cl_git_sandbox_init("empty_standard_repo");
160+
cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value1"));
161+
cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value2"));
162+
cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro");
163+
164+
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
165+
cl_assert_equal_s(value, "value2");
166+
}
167+
168+
void test_attr_macro__recursive_macro_resolves(void)
169+
{
170+
const char *value;
171+
172+
g_repo = cl_git_sandbox_init("empty_standard_repo");
173+
cl_git_pass(git_attr_add_macro(g_repo, "expandme", "key=value"));
174+
cl_git_pass(git_attr_add_macro(g_repo, "macro", "expandme"));
175+
cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro");
176+
177+
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key"));
178+
cl_assert_equal_s(value, "value");
179+
}

0 commit comments

Comments
 (0)