diff options
| author | Russell Belfer <arrbee@arrbee.com> | 2011-12-28 23:28:50 -0800 |
|---|---|---|
| committer | Russell Belfer <arrbee@arrbee.com> | 2011-12-29 00:01:10 -0800 |
| commit | 73b51450a3194ddaa2ac180a1fea25fdf66971bb (patch) | |
| tree | 4a6f4f0cfc90ded7f7734da2b6a9353d9bb0890b /tests-clay/attr | |
| parent | ee1f0b1aed7798908d9e038b006b66f868613fc3 (diff) | |
| download | libgit2-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')
| -rw-r--r-- | tests-clay/attr/file.c | 35 | ||||
| -rw-r--r-- | tests-clay/attr/lookup.c | 38 | ||||
| -rw-r--r-- | tests-clay/attr/repo.c | 48 |
3 files changed, 87 insertions, 34 deletions
diff --git a/tests-clay/attr/file.c b/tests-clay/attr/file.c index 0a5bff59d..d9e2d5701 100644 --- a/tests-clay/attr/file.c +++ b/tests-clay/attr/file.c @@ -8,7 +8,7 @@ void test_attr_file__simple_read(void) { git_attr_file *file = NULL; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr0"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), &file)); cl_assert_strequal(cl_fixture("attr/attr0"), file->path); cl_assert(file->rules.length == 1); @@ -16,15 +16,12 @@ void test_attr_file__simple_read(void) cl_assert(rule != NULL); cl_assert_strequal("*", rule->match.pattern); cl_assert(rule->match.length == 1); - cl_assert(!rule->match.negative); - cl_assert(!rule->match.directory); - cl_assert(!rule->match.fullpath); + cl_assert(rule->match.flags == 0); cl_assert(rule->assigns.length == 1); git_attr_assignment *assign = get_assign(rule, 0); cl_assert(assign != NULL); cl_assert_strequal("binary", assign->name); - cl_assert(assign->name_len == 6); cl_assert(assign->value == GIT_ATTR_TRUE); cl_assert(!assign->is_allocated); @@ -37,7 +34,7 @@ void test_attr_file__match_variants(void) git_attr_rule *rule; git_attr_assignment *assign; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr1"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), &file)); cl_assert_strequal(cl_fixture("attr/attr1"), file->path); cl_assert(file->rules.length == 10); @@ -48,38 +45,31 @@ void test_attr_file__match_variants(void) cl_assert(rule); cl_assert_strequal("pat0", rule->match.pattern); cl_assert(rule->match.length == strlen("pat0")); - cl_assert(!rule->match.negative); - cl_assert(!rule->match.directory); - cl_assert(!rule->match.fullpath); + cl_assert(rule->match.flags == 0); cl_assert(rule->assigns.length == 1); assign = get_assign(rule,0); cl_assert_strequal("attr0", assign->name); cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); - cl_assert(assign->name_len == strlen("attr0")); cl_assert(assign->value == GIT_ATTR_TRUE); cl_assert(!assign->is_allocated); rule = get_rule(1); cl_assert_strequal("pat1", rule->match.pattern); cl_assert(rule->match.length == strlen("pat1")); - cl_assert(rule->match.negative); + cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_NEGATIVE); rule = get_rule(2); cl_assert_strequal("pat2", rule->match.pattern); cl_assert(rule->match.length == strlen("pat2")); - cl_assert(rule->match.directory); - cl_assert(!rule->match.fullpath); + cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_DIRECTORY); rule = get_rule(3); cl_assert_strequal("pat3dir/pat3file", rule->match.pattern); - cl_assert(!rule->match.directory); - cl_assert(rule->match.fullpath); + cl_assert(rule->match.flags == GIT_ATTR_FNMATCH_FULLPATH); rule = get_rule(4); cl_assert_strequal("pat4.*", rule->match.pattern); - cl_assert(!rule->match.negative); - cl_assert(!rule->match.directory); - cl_assert(!rule->match.fullpath); + cl_assert(rule->match.flags == 0); rule = get_rule(5); cl_assert_strequal("*.pat5", rule->match.pattern); @@ -94,9 +84,7 @@ void test_attr_file__match_variants(void) rule = get_rule(8); cl_assert_strequal("pat8 with spaces", rule->match.pattern); cl_assert(rule->match.length == strlen("pat8 with spaces")); - cl_assert(!rule->match.negative); - cl_assert(!rule->match.directory); - cl_assert(!rule->match.fullpath); + cl_assert(rule->match.flags == 0); rule = get_rule(9); cl_assert_strequal("pat9", rule->match.pattern); @@ -120,7 +108,6 @@ static void check_one_assign( cl_assert(rule->assigns.length == 1); cl_assert_strequal(name, assign->name); cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name)); - cl_assert(assign->name_len == strlen(name)); cl_assert(assign->is_allocated == is_allocated); if (is_allocated) cl_assert_strequal(value, assign->value); @@ -134,7 +121,7 @@ void test_attr_file__assign_variants(void) git_attr_rule *rule; git_attr_assignment *assign; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr2"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), &file)); cl_assert_strequal(cl_fixture("attr/attr2"), file->path); cl_assert(file->rules.length == 11); @@ -199,7 +186,7 @@ void test_attr_file__check_attr_examples(void) git_attr_rule *rule; git_attr_assignment *assign; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr3"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), &file)); cl_assert_strequal(cl_fixture("attr/attr3"), file->path); cl_assert(file->rules.length == 3); diff --git a/tests-clay/attr/lookup.c b/tests-clay/attr/lookup.c index 870dcd343..fcade5225 100644 --- a/tests-clay/attr/lookup.c +++ b/tests-clay/attr/lookup.c @@ -1,5 +1,5 @@ #include "clay_libgit2.h" -#include "attr.h" +#include "attr_file.h" void test_attr_lookup__simple(void) { @@ -7,7 +7,7 @@ void test_attr_lookup__simple(void) git_attr_path path; const char *value = NULL; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr0"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr0"), &file)); cl_assert_strequal(cl_fixture("attr/attr0"), file->path); cl_assert(file->rules.length == 1); @@ -41,10 +41,6 @@ static void run_test_cases(git_attr_file *file, test_case *cases) int error; for (c = cases; c->path != NULL; c++) { - /* Put this in because I was surprised that all the tests passed */ - /* fprintf(stderr, "checking '%s' attr %s == %s\n", */ - /* c->path, c->attr, c->expected); */ - cl_git_pass(git_attr_path__init(&path, c->path)); if (c->force_dir) @@ -136,7 +132,7 @@ void test_attr_lookup__match_variants(void) { NULL, NULL, NULL, 0, 0 } }; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr1"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr1"), &file)); cl_assert_strequal(cl_fixture("attr/attr1"), file->path); cl_assert(file->rules.length == 10); @@ -194,7 +190,7 @@ void test_attr_lookup__assign_variants(void) { NULL, NULL, NULL, 0, 0 } }; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr2"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr2"), &file)); cl_assert(file->rules.length == 11); run_test_cases(file, cases); @@ -228,7 +224,31 @@ void test_attr_lookup__check_attr_examples(void) { NULL, NULL, NULL, 0, 0 } }; - cl_git_pass(git_attr_file__from_file(&file, cl_fixture("attr/attr3"))); + cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), &file)); + cl_assert(file->rules.length == 3); + + run_test_cases(file, cases); + + git_attr_file__free(file); +} + +void test_attr_lookup__from_buffer(void) +{ + git_attr_file *file = NULL; + test_case cases[] = { + { "abc", "foo", GIT_ATTR_TRUE, 0, 0 }, + { "abc", "bar", GIT_ATTR_TRUE, 0, 0 }, + { "abc", "baz", GIT_ATTR_TRUE, 0, 0 }, + { "aaa", "foo", GIT_ATTR_TRUE, 0, 0 }, + { "aaa", "bar", NULL, 0, 0 }, + { "aaa", "baz", GIT_ATTR_TRUE, 0, 0 }, + { "qqq", "foo", NULL, 0, 0 }, + { "qqq", "bar", NULL, 0, 0 }, + { "qqq", "baz", GIT_ATTR_TRUE, 0, 0 }, + { NULL, NULL, NULL, 0, 0 } + }; + + cl_git_pass(git_attr_file__from_buffer(NULL, "a* foo\nabc bar\n* baz", &file)); cl_assert(file->rules.length == 3); run_test_cases(file, cases); 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]); +} |
