diff: refactor git_diff_tree_to_tree() tests
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index 442e53b..cd951a1 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -2,13 +2,28 @@
#include "diff_helpers.h"
static git_repository *g_repo = NULL;
+static git_diff_options opts;
+static git_diff_list *diff;
+static git_tree *a, *b;
+static diff_expects exp;
void test_diff_tree__initialize(void)
{
+ GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION);
+
+ memset(&exp, 0, sizeof(exp));
+
+ diff = NULL;
+ a = NULL;
+ b = NULL;
}
void test_diff_tree__cleanup(void)
{
+ git_diff_list_free(diff);
+ git_tree_free(a);
+ git_tree_free(b);
+
cl_git_sandbox_cleanup();
}
@@ -18,10 +33,7 @@ void test_diff_tree__0(void)
const char *a_commit = "605812a";
const char *b_commit = "370fe9ec22";
const char *c_commit = "f5b0af1fb4f5c";
- git_tree *a, *b, *c;
- git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
- diff_expects exp;
+ git_tree *c;
g_repo = cl_git_sandbox_init("attr");
@@ -32,7 +44,6 @@ void test_diff_tree__0(void)
opts.context_lines = 1;
opts.interhunk_lines = 1;
- memset(&exp, 0, sizeof(exp));
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
@@ -73,10 +84,6 @@ void test_diff_tree__0(void)
cl_assert_equal_i(1, exp.line_adds);
cl_assert_equal_i(7 + 14, exp.line_dels);
- git_diff_list_free(diff);
-
- git_tree_free(a);
- git_tree_free(b);
git_tree_free(c);
}
@@ -87,9 +94,7 @@ void test_diff_tree__options(void)
const char *b_commit = "605812ab7fe421fdd";
const char *c_commit = "f5b0af1fb4f5";
const char *d_commit = "a97cc019851";
- git_tree *a, *b, *c, *d;
- git_diff_options opts = {0};
- git_diff_list *diff = NULL;
+ git_tree *c, *d;
diff_expects actual;
int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 };
git_diff_options test_options[] = {
@@ -164,8 +169,6 @@ void test_diff_tree__options(void)
diff = NULL;
}
- git_tree_free(a);
- git_tree_free(b);
git_tree_free(c);
git_tree_free(d);
}
@@ -174,10 +177,6 @@ void test_diff_tree__bare(void)
{
const char *a_commit = "8496071c1b46c85";
const char *b_commit = "be3563ae3f79";
- git_tree *a, *b;
- git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
- diff_expects exp;
g_repo = cl_git_sandbox_init("testrepo.git");
@@ -187,8 +186,6 @@ void test_diff_tree__bare(void)
opts.context_lines = 1;
opts.interhunk_lines = 1;
- memset(&exp, 0, sizeof(exp));
-
cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
cl_git_pass(git_diff_foreach(
@@ -205,10 +202,6 @@ void test_diff_tree__bare(void)
cl_assert_equal_i(0, exp.line_ctxt);
cl_assert_equal_i(3, exp.line_adds);
cl_assert_equal_i(1, exp.line_dels);
-
- git_diff_list_free(diff);
- git_tree_free(a);
- git_tree_free(b);
}
void test_diff_tree__merge(void)
@@ -217,9 +210,8 @@ void test_diff_tree__merge(void)
const char *a_commit = "605812a";
const char *b_commit = "370fe9ec22";
const char *c_commit = "f5b0af1fb4f5c";
- git_tree *a, *b, *c;
+ git_tree *c;
git_diff_list *diff1 = NULL, *diff2 = NULL;
- diff_expects exp;
g_repo = cl_git_sandbox_init("attr");
@@ -231,16 +223,12 @@ void test_diff_tree__merge(void)
cl_git_pass(git_diff_tree_to_tree(&diff2, g_repo, c, b, NULL));
- git_tree_free(a);
- git_tree_free(b);
git_tree_free(c);
cl_git_pass(git_diff_merge(diff1, diff2));
git_diff_list_free(diff2);
- memset(&exp, 0, sizeof(exp));
-
cl_git_pass(git_diff_foreach(
diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
@@ -263,9 +251,6 @@ void test_diff_tree__larger_hunks(void)
{
const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69";
const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10";
- git_tree *a, *b;
- git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
size_t d, num_d, h, num_h, l, num_l, header_len, line_len;
const git_diff_delta *delta;
git_diff_patch *patch;
@@ -312,21 +297,12 @@ void test_diff_tree__larger_hunks(void)
cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d));
cl_assert_equal_i(2, (int)num_d);
-
- git_diff_list_free(diff);
- diff = NULL;
-
- git_tree_free(a);
- git_tree_free(b);
}
void test_diff_tree__checks_options_version(void)
{
const char *a_commit = "8496071c1b46c85";
const char *b_commit = "be3563ae3f79";
- git_tree *a, *b;
- git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- git_diff_list *diff = NULL;
const git_error *err;
g_repo = cl_git_sandbox_init("testrepo.git");
@@ -343,7 +319,4 @@ void test_diff_tree__checks_options_version(void)
opts.version = 1024;
cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
err = giterr_last();
-
- git_tree_free(a);
- git_tree_free(b);
}