summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests-clar/checkout/checkout_helpers.c29
-rw-r--r--tests-clar/checkout/checkout_helpers.h16
-rw-r--r--tests-clar/checkout/crlf.c46
-rw-r--r--tests-clar/checkout/index.c42
-rw-r--r--tests-clar/checkout/tree.c6
5 files changed, 80 insertions, 59 deletions
diff --git a/tests-clar/checkout/checkout_helpers.c b/tests-clar/checkout/checkout_helpers.c
index 79e80c13a..ab93a89bd 100644
--- a/tests-clar/checkout/checkout_helpers.c
+++ b/tests-clar/checkout/checkout_helpers.c
@@ -50,35 +50,44 @@ void reset_index_to_treeish(git_object *treeish)
git_index_free(index);
}
-static void test_file_contents_internal(
- const char *path, const char *expectedcontents, bool strip_cr)
+static void check_file_contents_internal(
+ const char *path,
+ const char *expected_content,
+ bool strip_cr,
+ const char *file,
+ int line,
+ const char *msg)
{
int fd;
char data[1024] = {0};
git_buf buf = GIT_BUF_INIT;
- size_t expectedlen = strlen(expectedcontents);
+ size_t expected_len = expected_content ? strlen(expected_content) : 0;
fd = p_open(path, O_RDONLY);
cl_assert(fd >= 0);
buf.ptr = data;
- buf.size = p_read(fd, buf.ptr, 1024);
+ buf.size = p_read(fd, buf.ptr, sizeof(data));
cl_git_pass(p_close(fd));
if (strip_cr)
strip_cr_from_buf(&buf);
- cl_assert_equal_i((int)expectedlen, (int)buf.size);
- cl_assert_equal_s(expectedcontents, buf.ptr);
+ clar__assert_equal_i((int)expected_len, (int)buf.size, file, line, "strlen(expected_content) != strlen(actual_content)", 1);
+ clar__assert_equal_s(expected_content, buf.ptr, file, line, msg, 1);
}
-void test_file_contents(const char *path, const char *expected)
+void check_file_contents_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg)
{
- test_file_contents_internal(path, expected, false);
+ check_file_contents_internal(path, expected, false, file, line, msg);
}
-void test_file_contents_nocr(const char *path, const char *expected)
+void check_file_contents_nocr_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg)
{
- test_file_contents_internal(path, expected, true);
+ check_file_contents_internal(path, expected, true, file, line, msg);
}
diff --git a/tests-clar/checkout/checkout_helpers.h b/tests-clar/checkout/checkout_helpers.h
index 2c3a4b5bb..34053809d 100644
--- a/tests-clar/checkout/checkout_helpers.h
+++ b/tests-clar/checkout/checkout_helpers.h
@@ -5,5 +5,17 @@
extern void strip_cr_from_buf(git_buf *buf);
extern void assert_on_branch(git_repository *repo, const char *branch);
extern void reset_index_to_treeish(git_object *treeish);
-extern void test_file_contents(const char *path, const char *expected);
-extern void test_file_contents_nocr(const char *path, const char *expected);
+
+extern void check_file_contents_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg);
+
+extern void check_file_contents_nocr_at_line(
+ const char *path, const char *expected,
+ const char *file, int line, const char *msg);
+
+#define check_file_contents(PATH,EXP) \
+ check_file_contents_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
+
+#define check_file_contents_nocr(PATH,EXP) \
+ check_file_contents_nocr_at_line(PATH,EXP,__FILE__,__LINE__,"String mismatch: " #EXP " != " #PATH)
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
index 40f083c1c..285b1f272 100644
--- a/tests-clar/checkout/crlf.c
+++ b/tests-clar/checkout/crlf.c
@@ -28,7 +28,6 @@ void test_checkout_crlf__cleanup(void)
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
{
-#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -36,14 +35,12 @@ void test_checkout_crlf__detect_crlf_autocrlf_false(void)
git_checkout_head(g_repo, &opts);
- test_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
- test_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-#endif
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
}
void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
{
-#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
@@ -62,12 +59,10 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
cl_assert(entry->file_size == strlen(ALL_CRLF_TEXT_RAW));
git_index_free(index);
-#endif
}
void test_checkout_crlf__detect_crlf_autocrlf_true(void)
{
-#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -75,14 +70,16 @@ void test_checkout_crlf__detect_crlf_autocrlf_true(void)
git_checkout_head(g_repo, &opts);
- test_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
- test_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-#endif
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
+
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
}
void test_checkout_crlf__more_lf_autocrlf_true(void)
{
-#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -90,13 +87,14 @@ void test_checkout_crlf__more_lf_autocrlf_true(void)
git_checkout_head(g_repo, &opts);
- test_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
-#endif
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/more-lf", MORE_LF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/more-lf", MORE_LF_TEXT_AS_CRLF);
}
void test_checkout_crlf__more_crlf_autocrlf_true(void)
{
-#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -104,13 +102,14 @@ void test_checkout_crlf__more_crlf_autocrlf_true(void)
git_checkout_head(g_repo, &opts);
- test_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
-#endif
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_RAW);
+ else
+ check_file_contents("./crlf/more-crlf", MORE_CRLF_TEXT_AS_CRLF);
}
void test_checkout_crlf__all_crlf_autocrlf_true(void)
{
-#ifdef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
@@ -118,13 +117,11 @@ void test_checkout_crlf__all_crlf_autocrlf_true(void)
git_checkout_head(g_repo, &opts);
- test_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
-#endif
+ check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
}
void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
{
-#ifdef GIT_WIN32
git_index *index;
const git_index_entry *entry;
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
@@ -137,11 +134,14 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
git_repository_index(&index, g_repo);
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
- cl_assert(entry->file_size == strlen(ALL_LF_TEXT_AS_CRLF));
+
+ if (GIT_EOL_NATIVE == GIT_EOL_LF)
+ cl_assert_equal_sz(strlen(ALL_LF_TEXT_RAW), entry->file_size);
+ else
+ cl_assert_equal_sz(strlen(ALL_LF_TEXT_AS_CRLF), entry->file_size);
cl_assert((entry = git_index_get_bypath(index, "all-crlf", 0)) != NULL);
- cl_assert(entry->file_size == strlen(ALL_CRLF_TEXT_RAW));
+ cl_assert_equal_sz(strlen(ALL_CRLF_TEXT_RAW), entry->file_size);
git_index_free(index);
-#endif
}
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index 33506a669..78ff5ac62 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -48,9 +48,9 @@ void test_checkout_index__can_create_missing_files(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/README", "hey there\n");
- test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
- test_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/README", "hey there\n");
+ check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
}
void test_checkout_index__can_remove_untracked_files(void)
@@ -88,8 +88,8 @@ void test_checkout_index__honor_the_specified_pathspecs(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
- test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
- test_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
}
void test_checkout_index__honor_the_gitattributes_directives(void)
@@ -106,9 +106,9 @@ void test_checkout_index__honor_the_gitattributes_directives(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/README", "hey there\n");
- test_file_contents("./testrepo/new.txt", "my new file\n");
- test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n");
+ check_file_contents("./testrepo/README", "hey there\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n");
}
void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
@@ -124,7 +124,7 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/README", expected_readme_text);
+ check_file_contents("./testrepo/README", expected_readme_text);
#endif
}
@@ -139,7 +139,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
#ifdef GIT_WIN32
- test_file_contents("./testrepo/link_to_new.txt", "new.txt");
+ check_file_contents("./testrepo/link_to_new.txt", "new.txt");
#else
{
char link_data[1024];
@@ -149,7 +149,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
link_data[link_size] = '\0';
cl_assert_equal_i(link_size, strlen("new.txt"));
cl_assert_equal_s(link_data, "new.txt");
- test_file_contents("./testrepo/link_to_new.txt", "my new file\n");
+ check_file_contents("./testrepo/link_to_new.txt", "my new file\n");
}
#endif
}
@@ -164,7 +164,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_false(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/link_to_new.txt", "new.txt");
+ check_file_contents("./testrepo/link_to_new.txt", "new.txt");
}
void test_checkout_index__donot_overwrite_modified_file_by_default(void)
@@ -180,7 +180,7 @@ void test_checkout_index__donot_overwrite_modified_file_by_default(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/new.txt", "This isn't what's stored!");
+ check_file_contents("./testrepo/new.txt", "This isn't what's stored!");
}
void test_checkout_index__can_overwrite_modified_file(void)
@@ -193,7 +193,7 @@ void test_checkout_index__can_overwrite_modified_file(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
}
void test_checkout_index__options_disable_filters(void)
@@ -207,14 +207,14 @@ void test_checkout_index__options_disable_filters(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/new.txt", "my new file\r\n");
+ check_file_contents("./testrepo/new.txt", "my new file\r\n");
p_unlink("./testrepo/new.txt");
opts.disable_filters = true;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/new.txt", "my new file\n");
+ check_file_contents("./testrepo/new.txt", "my new file\n");
}
void test_checkout_index__options_dir_modes(void)
@@ -274,7 +274,7 @@ void test_checkout_index__options_open_flags(void)
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
+ check_file_contents("./testrepo/new.txt", "hi\nmy new file\n");
}
struct notify_data {
@@ -469,9 +469,9 @@ void test_checkout_index__can_update_prefixed_files(void)
/* remove untracked will remove the .gitattributes file before the blobs
* were created, so they will have had crlf filtering applied on Windows
*/
- test_file_contents_nocr("./testrepo/README", "hey there\n");
- test_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n");
- test_file_contents_nocr("./testrepo/new.txt", "my new file\n");
+ check_file_contents_nocr("./testrepo/README", "hey there\n");
+ check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents_nocr("./testrepo/new.txt", "my new file\n");
cl_assert(!git_path_exists("testrepo/READ"));
cl_assert(!git_path_exists("testrepo/README.after"));
@@ -503,5 +503,5 @@ void test_checkout_index__issue_1397(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
- test_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
+ check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
}
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 2a8fbc457..5a2eacea1 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -248,7 +248,7 @@ void test_checkout_tree__can_update_only(void)
cl_assert(!git_path_isdir("testrepo/a"));
- test_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
+ check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n");
/* now checkout branch but with update only */
@@ -269,7 +269,7 @@ void test_checkout_tree__can_update_only(void)
cl_assert(!git_path_isdir("testrepo/a"));
/* but this file still should have been updated */
- test_file_contents_nocr("testrepo/branch_file.txt", "hi\n");
+ check_file_contents_nocr("testrepo/branch_file.txt", "hi\n");
git_object_free(obj);
}
@@ -500,7 +500,7 @@ void test_checkout_tree__issue_1397(void)
cl_git_pass(git_checkout_tree(g_repo, tree, &opts));
- test_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
+ check_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
git_object_free(tree);
}