summaryrefslogtreecommitdiff
path: root/tests/diff/patch.c
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2013-12-13 06:20:19 -0800
committerVicent Marti <vicent@github.com>2013-12-13 06:20:19 -0800
commit79194bcdc956406979cd27ac99198826860d3f20 (patch)
tree407594b97b6e39ef3ac0723dc33aa3162ce933cc /tests/diff/patch.c
parent25a1fab0a96fd87e4ebc4ec195ac59a4213e92ad (diff)
parent7a16d54b5457aa9f60c25a204277ae0ce609ad2e (diff)
downloadlibgit2-79194bcdc956406979cd27ac99198826860d3f20.tar.gz
Merge pull request #1986 from libgit2/rb/error-handling-cleanups
Clean up some error handling and change callback error behavior
Diffstat (limited to 'tests/diff/patch.c')
-rw-r--r--tests/diff/patch.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/diff/patch.c b/tests/diff/patch.c
index bd1598b21..0cef3bd3a 100644
--- a/tests/diff/patch.c
+++ b/tests/diff/patch.c
@@ -30,8 +30,6 @@ static int check_removal_cb(
const git_diff_line *line,
void *payload)
{
- GIT_UNUSED(payload);
-
switch (line->origin) {
case GIT_DIFF_LINE_FILE_HDR:
cl_assert_equal_s(EXPECTED_HEADER, line->content);
@@ -40,10 +38,12 @@ static int check_removal_cb(
case GIT_DIFF_LINE_HUNK_HDR:
cl_assert_equal_s(EXPECTED_HUNK, line->content);
- /* Fall through */
+ goto check_hunk;
case GIT_DIFF_LINE_CONTEXT:
case GIT_DIFF_LINE_DELETION:
+ if (payload != NULL)
+ return *(int *)payload;
goto check_hunk;
default:
@@ -101,6 +101,39 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void)
git_tree_free(one);
}
+void test_diff_patch__can_cancel_diff_print(void)
+{
+ const char *one_sha = "26a125e";
+ const char *another_sha = "735b6a2";
+ git_tree *one, *another;
+ git_diff *diff;
+ int fail_with;
+
+ g_repo = cl_git_sandbox_init("status");
+
+ one = resolve_commit_oid_to_tree(g_repo, one_sha);
+ another = resolve_commit_oid_to_tree(g_repo, another_sha);
+
+ cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, one, another, NULL));
+
+ fail_with = -2323;
+
+ cl_git_fail_with(git_diff_print(
+ diff, GIT_DIFF_FORMAT_PATCH, check_removal_cb, &fail_with),
+ fail_with);
+
+ fail_with = 45;
+
+ cl_git_fail_with(git_diff_print(
+ diff, GIT_DIFF_FORMAT_PATCH, check_removal_cb, &fail_with),
+ fail_with);
+
+ git_diff_free(diff);
+
+ git_tree_free(another);
+ git_tree_free(one);
+}
+
void test_diff_patch__to_string(void)
{
const char *one_sha = "26a125e";