Commit c8c91433 by Russell Belfer

More ** tests for pattern rules

parent 2b6b85f1
......@@ -16,13 +16,20 @@ void test_attr_ignore__cleanup(void)
g_repo = NULL;
}
void assert_is_ignored(bool expected, const char *filepath)
void assert_is_ignored_(
bool expected, const char *filepath, const char *file, int line)
{
int is_ignored;
int is_ignored = 0;
cl_git_pass(git_ignore_path_is_ignored(&is_ignored, g_repo, filepath));
cl_assert_equal_b(expected, is_ignored);
cl_git_pass_(
git_ignore_path_is_ignored(&is_ignored, g_repo, filepath), file, line);
clar__assert_equal(
file, line, "expected != is_ignored", 1, "%d",
(int)(expected != 0), (int)(is_ignored != 0));
}
#define assert_is_ignored(expected, filepath) \
assert_is_ignored_(expected, filepath, __FILE__, __LINE__)
void test_attr_ignore__honor_temporary_rules(void)
{
......@@ -65,8 +72,47 @@ void test_attr_ignore__full_paths(void)
assert_is_ignored(true, "Folder/Middle/Contained");
assert_is_ignored(true, "Folder/Middle/More/More/Contained");
cl_git_rewritefile("attr/.gitignore", "Folder/**/Contained/*/Child");
assert_is_ignored(true, "Folder/Middle/Contained/Happy/Child");
assert_is_ignored(false, "Folder/Middle/Contained/Not/Happy/Child");
assert_is_ignored(true, "Folder/Middle/More/More/Contained/Happy/Child");
assert_is_ignored(false, "Folder/Middle/More/More/Contained/Not/Happy/Child");
}
void test_attr_ignore__leading_stars(void)
{
cl_git_rewritefile(
"attr/.gitignore",
"*/onestar\n"
"**/twostars\n"
"*/parent1/kid1/*\n"
"**/parent2/kid2/*\n");
assert_is_ignored(true, "dir1/onestar");
assert_is_ignored(true, "dir1/onestar/child"); /* in ignored dir */
assert_is_ignored(false, "dir1/dir2/onestar");
assert_is_ignored(true, "dir1/twostars");
assert_is_ignored(true, "dir1/twostars/child"); /* in ignored dir */
assert_is_ignored(true, "dir1/dir2/twostars");
assert_is_ignored(true, "dir1/dir2/twostars/child"); /* in ignored dir */
assert_is_ignored(true, "dir1/dir2/dir3/twostars");
assert_is_ignored(true, "dir1/parent1/kid1/file");
assert_is_ignored(true, "dir1/parent1/kid1/file/inside/parent");
assert_is_ignored(false, "dir1/dir2/parent1/kid1/file");
assert_is_ignored(false, "dir1/parent1/file");
assert_is_ignored(false, "dir1/kid1/file");
assert_is_ignored(true, "dir1/parent2/kid2/file");
assert_is_ignored(true, "dir1/parent2/kid2/file/inside/parent");
assert_is_ignored(true, "dir1/dir2/parent2/kid2/file");
assert_is_ignored(true, "dir1/dir2/dir3/parent2/kid2/file");
assert_is_ignored(false, "dir1/parent2/file");
assert_is_ignored(false, "dir1/kid2/file");
}
void test_attr_ignore__skip_gitignore_directory(void)
{
......
......@@ -11,11 +11,13 @@
*
* Use this wrapper around all `git_` library calls that return error codes!
*/
#define cl_git_pass(expr) do { \
#define cl_git_pass(expr) cl_git_pass_(expr, __FILE__, __LINE__)
#define cl_git_pass_(expr, file, line) do { \
int _lg2_error; \
giterr_clear(); \
if ((_lg2_error = (expr)) != 0) \
cl_git_report_failure(_lg2_error, __FILE__, __LINE__, "Function call failed: " #expr); \
cl_git_report_failure(_lg2_error, file, line, "Function call failed: " #expr); \
} while (0)
/**
......
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