More tests for files with no newline at end
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c
index c9a13f7..6181ffb 100644
--- a/tests-clar/diff/patch.c
+++ b/tests-clar/diff/patch.c
@@ -323,7 +323,9 @@ void test_diff_patch__hunks_have_correct_line_numbers(void)
}
static void check_single_patch_stats(
- git_repository *repo, size_t hunks, size_t adds, size_t dels, size_t ctxt)
+ git_repository *repo, size_t hunks,
+ size_t adds, size_t dels, size_t ctxt,
+ const char *expected)
{
git_diff_list *diff;
git_diff_patch *patch;
@@ -346,6 +348,13 @@ static void check_single_patch_stats(
cl_assert_equal_sz(adds, actual_adds);
cl_assert_equal_sz(dels, actual_dels);
+ if (expected != NULL) {
+ char *text;
+ cl_git_pass(git_diff_patch_to_str(&text, patch));
+ cl_assert_equal_s(expected, text);
+ git__free(text);
+ }
+
git_diff_patch_free(patch);
git_diff_list_free(diff);
}
@@ -370,14 +379,14 @@ void test_diff_patch__line_counts_with_eofnl(void)
git_buf_consume(&content, end);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 1, 0, 1, 3);
+ check_single_patch_stats(g_repo, 1, 0, 1, 3, NULL);
/* remove trailing whitespace */
git_buf_rtrim(&content);
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 2, 1, 2, 6);
+ check_single_patch_stats(g_repo, 2, 1, 2, 6, NULL);
/* add trailing whitespace */
@@ -389,7 +398,7 @@ void test_diff_patch__line_counts_with_eofnl(void)
cl_git_pass(git_buf_putc(&content, '\n'));
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 1, 1, 1, 3);
+ check_single_patch_stats(g_repo, 1, 1, 1, 3, NULL);
/* no trailing whitespace as context line */
@@ -411,7 +420,23 @@ void test_diff_patch__line_counts_with_eofnl(void)
}
cl_git_rewritefile("renames/songof7cities.txt", content.ptr);
- check_single_patch_stats(g_repo, 1, 1, 1, 6);
+ check_single_patch_stats(
+ g_repo, 1, 1, 1, 6,
+ /* below is pasted output of 'git diff' with fn context removed */
+ "diff --git a/songof7cities.txt b/songof7cities.txt\n"
+ "index 378a7d9..3d0154e 100644\n"
+ "--- a/songof7cities.txt\n"
+ "+++ b/songof7cities.txt\n"
+ "@@ -42,7 +42,7 @@\n"
+ " \n"
+ " To the sound of trumpets shall their seed restore my Cities\n"
+ " Wealthy and well-weaponed, that once more may I behold\n"
+ "-All the world go softly when it walks before my Cities,\n"
+ "+#All the world go softly when it walks before my Cities,\n"
+ " And the horses and the chariots fleeing from them as of old!\n"
+ " \n"
+ " -- Rudyard Kipling\n"
+ "\\ No newline at end of file\n");
git_buf_free(&content);
git_config_free(cfg);