diff options
author | Erik Aigner <aigner.erik@gmail.com> | 2019-07-11 12:12:04 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2019-07-11 12:14:27 +0200 |
commit | b08932824e1ca202f1fcb81e94d329b77715a17c (patch) | |
tree | 90f7b6161a2be2392db48527c325d91cc843abe9 /tests/patch | |
parent | 3f855fe863e7260ea4b7bc36a0c78ea2bff37b68 (diff) | |
download | libgit2-b08932824e1ca202f1fcb81e94d329b77715a17c.tar.gz |
patch_parse: ensure valid patch output with EOFNL
Diffstat (limited to 'tests/patch')
-rw-r--r-- | tests/patch/parse.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/patch/parse.c b/tests/patch/parse.c index 8c29e311a..8dc2082e0 100644 --- a/tests/patch/parse.c +++ b/tests/patch/parse.c @@ -27,6 +27,18 @@ static void ensure_patch_validity(git_patch *patch) cl_assert_equal_i(0, delta->new_file.size); } +static void ensure_identical_patch_inout(const char *content) { + git_buf buf = GIT_BUF_INIT; + git_patch *patch; + + cl_git_pass(git_patch_from_buffer(&patch, content, strlen(content), NULL)); + cl_git_pass(git_patch_to_buf(&buf, patch)); + cl_assert_equal_strn(git_buf_cstr(&buf), content, strlen(content)); + + git_patch_free(patch); + git_buf_dispose(&buf); +} + void test_patch_parse__original_to_change_middle(void) { git_patch *patch; @@ -104,21 +116,15 @@ void test_patch_parse__invalid_patches_fails(void) void test_patch_parse__no_newline_at_end_of_new_file(void) { - git_patch *patch; - cl_git_pass(git_patch_from_buffer(&patch, PATCH_APPEND_NO_NL, strlen(PATCH_APPEND_NO_NL), NULL)); - git_patch_free(patch); + ensure_identical_patch_inout(PATCH_APPEND_NO_NL); } void test_patch_parse__no_newline_at_end_of_old_file(void) { - git_patch *patch; - cl_git_pass(git_patch_from_buffer(&patch, PATCH_APPEND_NO_NL_IN_OLD_FILE, strlen(PATCH_APPEND_NO_NL_IN_OLD_FILE), NULL)); - git_patch_free(patch); + ensure_identical_patch_inout(PATCH_APPEND_NO_NL_IN_OLD_FILE); } void test_patch_parse__files_with_whitespaces_succeeds(void) { - git_patch *patch; - cl_git_pass(git_patch_from_buffer(&patch, PATCH_NAME_WHITESPACE, strlen(PATCH_NAME_WHITESPACE), NULL)); - git_patch_free(patch); + ensure_identical_patch_inout(PATCH_NAME_WHITESPACE); } |