summaryrefslogtreecommitdiff
path: root/tests-clay/attr/repo.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-12-28 23:28:50 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-29 00:01:10 -0800
commit73b51450a3194ddaa2ac180a1fea25fdf66971bb (patch)
tree4a6f4f0cfc90ded7f7734da2b6a9353d9bb0890b /tests-clay/attr/repo.c
parentee1f0b1aed7798908d9e038b006b66f868613fc3 (diff)
downloadlibgit2-73b51450a3194ddaa2ac180a1fea25fdf66971bb.tar.gz
Add support for macros and cache flush API.
Add support for git attribute macro definitions. Also, add support for cache flush API to clear the attribute file content cache when needed. Additionally, improved the handling of global and system files, making common utility functions in fileops and converting config and attr to both use the common functions. Adds a bunch more tests and fixed some memory leaks. Note that adding macros required me to use refcounted attribute assignment definitions, which complicated, but probably improved memory usage.
Diffstat (limited to 'tests-clay/attr/repo.c')
-rw-r--r--tests-clay/attr/repo.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests-clay/attr/repo.c b/tests-clay/attr/repo.c
index b6815f3ba..e80e24dbf 100644
--- a/tests-clay/attr/repo.c
+++ b/tests-clay/attr/repo.c
@@ -6,11 +6,14 @@ static git_repository *g_repo = NULL;
void test_attr_repo__initialize(void)
{
- /* before each test, instantiate the attr repo from the fixtures and
+ /* Before each test, instantiate the attr repo from the fixtures and
* rename the .gitted to .git so it is a repo with a working dir.
+ * Also rename gitattributes to .gitattributes, because it contains
+ * macro definitions which are only allowed in the root.
*/
cl_fixture_sandbox("attr");
cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
+ cl_git_pass(p_rename("attr/gitattributes", "attr/.gitattributes"));
cl_git_pass(git_repository_open(&g_repo, "attr/.git"));
}
@@ -138,3 +141,46 @@ void test_attr_repo__foreach(void)
&count_attrs, &count));
cl_assert(count == 5); /* repoattr, rootattr, subattr, negattr, another */
}
+
+void test_attr_repo__manpage_example(void)
+{
+ const char *value;
+
+ cl_git_pass(git_attr_get(g_repo, "subdir/abc", "foo", &value));
+ cl_assert(value == GIT_ATTR_TRUE);
+
+ cl_git_pass(git_attr_get(g_repo, "subdir/abc", "bar", &value));
+ cl_assert(value == NULL);
+
+ cl_git_pass(git_attr_get(g_repo, "subdir/abc", "baz", &value));
+ cl_assert(value == GIT_ATTR_FALSE);
+
+ cl_git_pass(git_attr_get(g_repo, "subdir/abc", "merge", &value));
+ cl_assert_strequal("filfre", value);
+
+ cl_git_pass(git_attr_get(g_repo, "subdir/abc", "frotz", &value));
+ cl_assert(value == NULL);
+}
+
+void test_attr_repo__macros(void)
+{
+ const char *names[5] = { "rootattr", "binary", "diff", "crlf", "frotz" };
+ const char *names2[5] = { "mymacro", "positive", "negative", "rootattr", "another" };
+ const char *values[5];
+
+ cl_git_pass(git_attr_get_many(g_repo, "binfile", 5, names, values));
+
+ cl_assert(values[0] == GIT_ATTR_TRUE);
+ cl_assert(values[1] == NULL);
+ cl_assert(values[2] == GIT_ATTR_FALSE);
+ cl_assert(values[3] == GIT_ATTR_FALSE);
+ cl_assert(values[4] == NULL);
+
+ cl_git_pass(git_attr_get_many(g_repo, "macro_test", 5, names2, values));
+
+ cl_assert(values[0] == NULL);
+ cl_assert(values[1] == GIT_ATTR_TRUE);
+ cl_assert(values[2] == GIT_ATTR_FALSE);
+ cl_assert(values[3] == NULL);
+ cl_assert_strequal("77", values[4]);
+}