Commit 4a7f704f by Patrick Steinhardt

tests: attr: implement tests to verify attribute rewriting behaviour

Implement some tests that verify that we are correctly updating
gitattributes when rewriting or unlinking the corresponding files.
parent ed854aa0
......@@ -89,3 +89,36 @@ void test_attr_macro__bad_macros(void)
cl_assert_equal_s("hahaha", values[4]);
cl_assert(GIT_ATTR_IS_TRUE(values[5]));
}
void test_attr_macro__macros_in_root_wd_apply(void)
{
const char *value;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(p_mkdir("empty_standard_repo/dir", 0777));
cl_git_rewritefile("empty_standard_repo/.gitattributes", "[attr]customattr key=value\n");
cl_git_rewritefile("empty_standard_repo/dir/.gitattributes", "file customattr\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "dir/file", "key"));
cl_assert_equal_s(value, "value");
}
void test_attr_macro__changing_macro_in_root_wd_updates_attributes(void)
{
const char *value;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_rewritefile("empty_standard_repo/.gitattributes",
"[attr]customattr key=first\n"
"file customattr\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
cl_assert_equal_s(value, "first");
cl_git_rewritefile("empty_standard_repo/.gitattributes",
"[attr]customattr key=second\n"
"file customattr\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "key"));
cl_assert_equal_s(value, "second");
}
......@@ -351,3 +351,55 @@ void test_attr_repo__sysdir_with_session(void)
git_buf_dispose(&sysdir);
git_attr_session__free(&session);
}
void test_attr_repo__rewrite(void)
{
const char *value;
cl_git_rewritefile("attr/.gitattributes", "file.txt foo=first\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
cl_assert_equal_s(value, "first");
cl_git_rewritefile("attr/.gitattributes", "file.txt foo=second\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
cl_assert_equal_s(value, "second");
cl_git_rewritefile("attr/.gitattributes", "file.txt other=value\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
cl_assert_equal_p(value, NULL);
}
void test_attr_repo__rewrite_sysdir(void)
{
git_buf sysdir = GIT_BUF_INIT;
const char *value;
cl_git_pass(p_mkdir("system", 0777));
cl_git_pass(git_buf_joinpath(&sysdir, clar_sandbox_path(), "system"));
cl_git_pass(git_sysdir_set(GIT_SYSDIR_SYSTEM, sysdir.ptr));
g_repo = cl_git_sandbox_reopen();
cl_git_rewritefile("system/gitattributes", "file foo=first");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
cl_assert_equal_s(value, "first");
cl_git_rewritefile("system/gitattributes", "file foo=second");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file", "foo"));
cl_assert_equal_s(value, "second");
git_buf_dispose(&sysdir);
}
void test_attr_repo__unlink(void)
{
const char *value;
cl_git_rewritefile("attr/.gitattributes", "file.txt foo=value1\n");
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
cl_assert_equal_s(value, "value1");
cl_git_pass(p_unlink("attr/.gitattributes"));
cl_git_pass(git_attr_get(&value, g_repo, 0, "file.txt", "foo"));
cl_assert_equal_p(value, NULL);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment