summaryrefslogtreecommitdiff
path: root/tests-clar/attr/file.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-03-02 03:51:45 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-02 03:51:45 +0100
commitc63793ee81ee6961b2430e88379d491fa8e91bfb (patch)
tree2a754dec992f12a21afb19925622682c71c7b1fc /tests-clar/attr/file.c
parent47a899ffed3c71080e10e73eda092a716f1be168 (diff)
downloadlibgit2-c63793ee81ee6961b2430e88379d491fa8e91bfb.tar.gz
attr: Change the attribute check macros
The point of having `GIT_ATTR_TRUE` and `GIT_ATTR_FALSE` macros is to be able to change the way that true and false values are stored inside of the returned gitattributes value pointer. However, if these macros are implemented as a simple rename for the `git_attr__true` pointer, they will always be used with the `==` operator, and hence we cannot really change the implementation to any other way that doesn't imply using special pointer values and comparing them! We need to do the same thing that core Git does, which is using a function macro. With `GIT_ATTR_TRUE(attr)`, we can change internally the way that these values are stored to anything we want. This commit does that, and rewrites a large chunk of the attributes test suite to remove duplicated code for expected attributes, and to properly test the function macro behavior instead of comparing pointers.
Diffstat (limited to 'tests-clar/attr/file.c')
-rw-r--r--tests-clar/attr/file.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/tests-clar/attr/file.c b/tests-clar/attr/file.c
index af50cd38e..132b906cd 100644
--- a/tests-clar/attr/file.c
+++ b/tests-clar/attr/file.c
@@ -1,5 +1,6 @@
#include "clar_libgit2.h"
#include "attr_file.h"
+#include "attr_expect.h"
#define get_rule(X) ((git_attr_rule *)git_vector_get(&file->rules,(X)))
#define get_assign(R,Y) ((git_attr_assignment *)git_vector_get(&(R)->assigns,(Y)))
@@ -25,7 +26,7 @@ void test_attr_file__simple_read(void)
assign = get_assign(rule, 0);
cl_assert(assign != NULL);
cl_assert_strequal("binary", assign->name);
- cl_assert(assign->value == GIT_ATTR_TRUE);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
cl_assert(!assign->is_allocated);
git_attr_file__free(file);
@@ -54,7 +55,7 @@ void test_attr_file__match_variants(void)
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->value == GIT_ATTR_TRUE);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
cl_assert(!assign->is_allocated);
rule = get_rule(1);
@@ -83,7 +84,7 @@ void test_attr_file__match_variants(void)
cl_assert(rule->assigns.length == 1);
assign = get_assign(rule,0);
cl_assert_strequal("attr7", assign->name);
- cl_assert(assign->value == GIT_ATTR_TRUE);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
rule = get_rule(8);
cl_assert_strequal("pat8 with spaces", rule->match.pattern);
@@ -102,8 +103,8 @@ static void check_one_assign(
int assign_idx,
const char *pattern,
const char *name,
- const char *value,
- int is_allocated)
+ enum attr_expect_t expected,
+ const char *expected_str)
{
git_attr_rule *rule = get_rule(rule_idx);
git_attr_assignment *assign = get_assign(rule, assign_idx);
@@ -112,11 +113,8 @@ 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->is_allocated == is_allocated);
- if (is_allocated)
- cl_assert_strequal(value, assign->value);
- else
- cl_assert(assign->value == value);
+
+ attr_check_expected(expected, expected_str, assign->value);
}
void test_attr_file__assign_variants(void)
@@ -130,14 +128,14 @@ void test_attr_file__assign_variants(void)
cl_assert_strequal(cl_fixture("attr/attr2"), file->path);
cl_assert(file->rules.length == 11);
- check_one_assign(file, 0, 0, "pat0", "simple", GIT_ATTR_TRUE, 0);
- check_one_assign(file, 1, 0, "pat1", "neg", GIT_ATTR_FALSE, 0);
- check_one_assign(file, 2, 0, "*", "notundef", GIT_ATTR_TRUE, 0);
- check_one_assign(file, 3, 0, "pat2", "notundef", NULL, 0);
- check_one_assign(file, 4, 0, "pat3", "assigned", "test-value", 1);
- check_one_assign(file, 5, 0, "pat4", "rule-with-more-chars", "value-with-more-chars", 1);
- check_one_assign(file, 6, 0, "pat5", "empty", GIT_ATTR_TRUE, 0);
- check_one_assign(file, 7, 0, "pat6", "negempty", GIT_ATTR_FALSE, 0);
+ check_one_assign(file, 0, 0, "pat0", "simple", EXPECT_TRUE, NULL);
+ check_one_assign(file, 1, 0, "pat1", "neg", EXPECT_FALSE, NULL);
+ check_one_assign(file, 2, 0, "*", "notundef", EXPECT_TRUE, NULL);
+ check_one_assign(file, 3, 0, "pat2", "notundef", EXPECT_UNDEFINED, NULL);
+ check_one_assign(file, 4, 0, "pat3", "assigned", EXPECT_STRING, "test-value");
+ check_one_assign(file, 5, 0, "pat4", "rule-with-more-chars", EXPECT_STRING, "value-with-more-chars");
+ check_one_assign(file, 6, 0, "pat5", "empty", EXPECT_TRUE, NULL);
+ check_one_assign(file, 7, 0, "pat6", "negempty", EXPECT_FALSE, NULL);
rule = get_rule(8);
cl_assert_strequal("pat7", rule->match.pattern);
@@ -148,11 +146,11 @@ void test_attr_file__assign_variants(void)
assign = git_attr_rule__lookup_assignment(rule, "multiple");
cl_assert(assign);
cl_assert_strequal("multiple", assign->name);
- cl_assert(assign->value == GIT_ATTR_TRUE);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "single");
cl_assert(assign);
cl_assert_strequal("single", assign->name);
- cl_assert(assign->value == GIT_ATTR_FALSE);
+ cl_assert(GIT_ATTR_FALSE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "values");
cl_assert(assign);
cl_assert_strequal("values", assign->name);
@@ -174,13 +172,13 @@ void test_attr_file__assign_variants(void)
assign = git_attr_rule__lookup_assignment(rule, "again");
cl_assert(assign);
cl_assert_strequal("again", assign->name);
- cl_assert(assign->value == GIT_ATTR_TRUE);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "another");
cl_assert(assign);
cl_assert_strequal("another", assign->name);
cl_assert_strequal("12321", assign->value);
- check_one_assign(file, 10, 0, "pat9", "at-eof", GIT_ATTR_FALSE, 0);
+ check_one_assign(file, 10, 0, "pat9", "at-eof", EXPECT_FALSE, NULL);
git_attr_file__free(file);
}
@@ -204,10 +202,10 @@ void test_attr_file__check_attr_examples(void)
cl_assert_strequal("java", assign->value);
assign = git_attr_rule__lookup_assignment(rule, "crlf");
cl_assert_strequal("crlf", assign->name);
- cl_assert(GIT_ATTR_FALSE == assign->value);
+ cl_assert(GIT_ATTR_FALSE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "myAttr");
cl_assert_strequal("myAttr", assign->name);
- cl_assert(GIT_ATTR_TRUE == assign->value);
+ cl_assert(GIT_ATTR_TRUE(assign->value));
assign = git_attr_rule__lookup_assignment(rule, "missing");
cl_assert(assign == NULL);