summaryrefslogtreecommitdiff
path: root/tests-clay/attr/repo.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2011-12-30 15:00:14 -0800
committerRussell Belfer <arrbee@arrbee.com>2011-12-30 15:00:14 -0800
commitbd370b14fefdba3844a9bf0bbf87171ca48f49be (patch)
treeb16a3e4ee778d33fb7782b26c7cffb3068b63087 /tests-clay/attr/repo.c
parentc6d2a2c0946ff32c16578b68b39824f4fea8f782 (diff)
downloadlibgit2-bd370b14fefdba3844a9bf0bbf87171ca48f49be.tar.gz
Improved gitattributes macro implementation
This updates to implementation of gitattribute macros to be much more similar to core git (albeit not 100%) and to handle expansion of macros within macros, etc. It also cleans up the refcounting usage with macros to be much cleaner. Also, this adds a new vector function `git_vector_insert_sorted()` which allows you to maintain a sorted list as you go. In order to write that function, this changes the function `git__bsearch()` to take a somewhat different set of parameters, although the core functionality is still the same.
Diffstat (limited to 'tests-clay/attr/repo.c')
-rw-r--r--tests-clay/attr/repo.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests-clay/attr/repo.c b/tests-clay/attr/repo.c
index e80e24dbf..f87e7bf55 100644
--- a/tests-clay/attr/repo.c
+++ b/tests-clay/attr/repo.c
@@ -40,8 +40,11 @@ void test_attr_repo__get_one(void)
{ "root_test2", "repoattr", GIT_ATTR_TRUE },
{ "root_test2", "rootattr", GIT_ATTR_FALSE },
{ "root_test2", "missingattr", NULL },
+ { "root_test2", "multiattr", GIT_ATTR_FALSE },
{ "root_test3", "repoattr", GIT_ATTR_TRUE },
{ "root_test3", "rootattr", NULL },
+ { "root_test3", "multiattr", "3" },
+ { "root_test3", "multi2", NULL },
{ "subdir/subdir_test1", "repoattr", GIT_ATTR_TRUE },
{ "subdir/subdir_test1", "rootattr", GIT_ATTR_TRUE },
{ "subdir/subdir_test1", "missingattr", NULL },
@@ -166,21 +169,68 @@ 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 *names3[3] = { "macro2", "multi2", "multi3" };
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[1] == GIT_ATTR_TRUE);
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[0] == GIT_ATTR_TRUE);
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]);
+
+ cl_git_pass(git_attr_get_many(g_repo, "macro_test", 3, names3, values));
+
+ cl_assert(values[0] == GIT_ATTR_TRUE);
+ cl_assert(values[1] == GIT_ATTR_FALSE);
+ cl_assert_strequal("answer", values[2]);
+}
+
+void test_attr_repo__bad_macros(void)
+{
+ const char *names[6] = { "rootattr", "positive", "negative",
+ "firstmacro", "secondmacro", "thirdmacro" };
+ const char *values[6];
+
+ cl_git_pass(git_attr_get_many(g_repo, "macro_bad", 6, names, values));
+
+ /* these three just confirm that the "mymacro" rule ran */
+ cl_assert(values[0] == NULL);
+ cl_assert(values[1] == GIT_ATTR_TRUE);
+ cl_assert(values[2] == GIT_ATTR_FALSE);
+
+ /* file contains:
+ * # let's try some malicious macro defs
+ * [attr]firstmacro -thirdmacro -secondmacro
+ * [attr]secondmacro firstmacro -firstmacro
+ * [attr]thirdmacro secondmacro=hahaha -firstmacro
+ * macro_bad firstmacro secondmacro thirdmacro
+ *
+ * firstmacro assignment list ends up with:
+ * -thirdmacro -secondmacro
+ * secondmacro assignment list expands "firstmacro" and ends up with:
+ * -thirdmacro -secondmacro -firstmacro
+ * thirdmacro assignment don't expand so list ends up with:
+ * secondmacro="hahaha"
+ *
+ * macro_bad assignment list ends up with:
+ * -thirdmacro -secondmacro firstmacro &&
+ * -thirdmacro -secondmacro -firstmacro secondmacro &&
+ * secondmacro="hahaha" thirdmacro
+ *
+ * so summary results should be:
+ * -firstmacro secondmacro="hahaha" thirdmacro
+ */
+ cl_assert(values[3] == GIT_ATTR_FALSE);
+ cl_assert_strequal("hahaha", values[4]);
+ cl_assert(values[5] == GIT_ATTR_TRUE);
}