]>
git.proxmox.com Git - libgit2.git/blob - tests/blame/blame_helpers.c
1 #include "blame_helpers.h"
3 void hunk_message(size_t idx
, const git_blame_hunk
*hunk
, const char *fmt
, ...)
7 printf("Hunk %"PRIuZ
" (line %"PRIuZ
" +%"PRIuZ
"): ", idx
,
8 hunk
->final_start_line_number
, hunk
->lines_in_hunk
-1);
10 va_start(arglist
, fmt
);
11 vprintf(fmt
, arglist
);
17 void check_blame_hunk_index(git_repository
*repo
, git_blame
*blame
, int idx
,
18 size_t start_line
, size_t len
, char boundary
, const char *commit_id
, const char *orig_path
)
20 char expected
[GIT_OID_HEXSZ
+1] = {0}, actual
[GIT_OID_HEXSZ
+1] = {0};
21 const git_blame_hunk
*hunk
= git_blame_get_hunk_byindex(blame
, idx
);
24 if (!strncmp(commit_id
, "0000", 4)) {
25 strcpy(expected
, "0000000000000000000000000000000000000000");
28 cl_git_pass(git_revparse_single(&obj
, repo
, commit_id
));
29 git_oid_fmt(expected
, git_object_id(obj
));
33 if (hunk
->final_start_line_number
!= start_line
) {
34 hunk_message(idx
, hunk
, "mismatched start line number: expected %"PRIuZ
", got %"PRIuZ
,
35 start_line
, hunk
->final_start_line_number
);
37 cl_assert_equal_i(hunk
->final_start_line_number
, start_line
);
39 if (hunk
->lines_in_hunk
!= len
) {
40 hunk_message(idx
, hunk
, "mismatched line count: expected %"PRIuZ
", got %"PRIuZ
,
41 len
, hunk
->lines_in_hunk
);
43 cl_assert_equal_i(hunk
->lines_in_hunk
, len
);
45 git_oid_fmt(actual
, &hunk
->final_commit_id
);
46 if (strcmp(expected
, actual
)) {
47 hunk_message(idx
, hunk
, "has mismatched original id (got %s, expected %s)\n",
50 cl_assert_equal_s(actual
, expected
);
51 cl_assert_equal_oid(&hunk
->final_commit_id
, &hunk
->orig_commit_id
);
54 if (strcmp(hunk
->orig_path
, orig_path
)) {
55 hunk_message(idx
, hunk
, "has mismatched original path (got '%s', expected '%s')\n",
56 hunk
->orig_path
, orig_path
);
58 cl_assert_equal_s(hunk
->orig_path
, orig_path
);
60 if (hunk
->boundary
!= boundary
) {
61 hunk_message(idx
, hunk
, "doesn't match boundary flag (got %d, expected %d)\n",
62 hunk
->boundary
, boundary
);
64 cl_assert_equal_i(boundary
, hunk
->boundary
);