diff options
author | Patrick Steinhardt <ps@pks.im> | 2019-07-12 09:02:16 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-07-12 09:26:02 +0200 |
commit | df417a4325ddcc209bd208be197faf53a21e52d7 (patch) | |
tree | 82ba7dfadd83d12c8e2d2a1fa8879ec71dc7e8c9 | |
parent | 4a7f704fdb4f8dc2fa59eb664558c9a6d60ebad4 (diff) | |
download | libgit2-df417a4325ddcc209bd208be197faf53a21e52d7.tar.gz |
tests: attr: verify that in-memory macros are respected
Add some tests to ensure that the `git_attr_add_macro` function works as
expected.
-rw-r--r-- | tests/attr/macro.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/attr/macro.c b/tests/attr/macro.c index 79e8225eb..bdec90128 100644 --- a/tests/attr/macro.c +++ b/tests/attr/macro.c @@ -6,6 +6,8 @@ */ #include "clar_libgit2.h" + +#include "git2/sys/repository.h" #include "attr.h" static git_repository *g_repo = NULL; @@ -122,3 +124,56 @@ void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void) cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key")); cl_assert_equal_s(value, "second"); } + +void test_attr_macro__adding_macro_succeeds(void) +{ + const char *value; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value")); + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro\n"); + + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); + cl_assert_equal_s(value, "value"); +} + +void test_attr_macro__adding_boolean_macros_succeeds(void) +{ + const char *value; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_pass(git_attr_add_macro(g_repo, "macro-pos", "positive")); + cl_git_pass(git_attr_add_macro(g_repo, "macro-neg", "-negative")); + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro-pos macro-neg\n"); + + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "positive")); + cl_assert(GIT_ATTR_IS_TRUE(value)); + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "negative")); + cl_assert(GIT_ATTR_IS_FALSE(value)); +} + +void test_attr_macro__redefining_macro_succeeds(void) +{ + const char *value; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value1")); + cl_git_pass(git_attr_add_macro(g_repo, "macro", "key=value2")); + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro"); + + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); + cl_assert_equal_s(value, "value2"); +} + +void test_attr_macro__recursive_macro_resolves(void) +{ + const char *value; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + cl_git_pass(git_attr_add_macro(g_repo, "expandme", "key=value")); + cl_git_pass(git_attr_add_macro(g_repo, "macro", "expandme")); + cl_git_rewritefile("empty_standard_repo/.gitattributes", "file.txt macro"); + + cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "key")); + cl_assert_equal_s(value, "value"); +} |