Test fixes and cleanup This fixes some places where the new tests were leaving the test area in a bad state or were freeing data they should not free. It also removes code that is extraneous to the core issue and fixes an invalid SHA being looked up in one of the tests (which was failing, but for the wrong reason).
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index 6dfa95d..33506a6 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -497,7 +497,7 @@ void test_checkout_index__issue_1397(void)
g_repo = cl_git_sandbox_init("issue_1397");
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 0f0ac69..2a8fbc4 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -485,33 +485,22 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
void test_checkout_tree__issue_1397(void)
{
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
- git_config *cfg;
const char *partial_oid = "8a7ef04";
- size_t len = strlen(partial_oid);
- git_oid oid;
- git_object *obj = NULL;
- git_tree *tree = NULL;
+ git_object *tree = NULL;
+
+ test_checkout_tree__cleanup(); /* cleanup default checkout */
g_repo = cl_git_sandbox_init("issue_1397");
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", true));
- git_config_free(cfg);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
- if (git_oid_fromstrn(&oid, partial_oid, len) == 0)
- git_object_lookup_prefix(&obj, g_repo, &oid, len, GIT_OBJ_ANY);
- cl_assert(obj);
- cl_assert(git_object_type(obj) == GIT_OBJ_COMMIT);
- cl_git_pass(git_commit_tree(&tree, (git_commit *)obj));
- git_object_free(obj);
+ cl_git_pass(git_revparse_single(&tree, g_repo, partial_oid));
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_assert(tree != NULL);
-
- git_checkout_tree(g_repo, (git_object *)tree, &opts);
+ cl_git_pass(git_checkout_tree(g_repo, tree, &opts));
test_file_contents("./issue_1397/crlf_file.txt", "first line\r\nsecond line\r\nboth with crlf");
- git_tree_free(tree);
+ git_object_free(tree);
}
diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c
index 06e6499..850feef 100644
--- a/tests-clar/diff/tree.c
+++ b/tests-clar/diff/tree.c
@@ -434,13 +434,11 @@ void test_diff_tree__regular_blob_mode_changed_to_executable_file(void)
void test_diff_tree__issue_1397(void)
{
- // this test shows, that it is not needed
- git_config *cfg;
+ /* this test shows that it is not needed */
+
g_repo = cl_git_sandbox_init("issue_1397");
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", true));
- git_config_free(cfg);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_assert((a = resolve_commit_oid_to_tree(g_repo, "8a7ef04")) != NULL);
cl_assert((b = resolve_commit_oid_to_tree(g_repo, "7f483a7")) != NULL);
diff --git a/tests-clar/diff/workdir.c b/tests-clar/diff/workdir.c
index 7e66671..f67f09a 100644
--- a/tests-clar/diff/workdir.c
+++ b/tests-clar/diff/workdir.c
@@ -1085,112 +1085,66 @@ void test_diff_workdir__can_diff_empty_file(void)
git_diff_list_free(diff);
}
-static void set_config_entry_to(const char *entry_name, bool value)
-{
- git_config *cfg;
-
- cl_git_pass(git_repository_config(&cfg, g_repo));
- cl_git_pass(git_config_set_bool(cfg, entry_name, value));
-
- git_config_free(cfg);
-}
-
-static void set_core_autocrlf_to(bool value)
-{
- set_config_entry_to("core.autocrlf", value);
-}
-
void test_diff_workdir__to_index_issue_1397(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
diff_expects exp;
- int use_iterator;
g_repo = cl_git_sandbox_init("issue_1397");
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
opts.context_lines = 3;
opts.interhunk_lines = 1;
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
- memset(&exp, 0, sizeof(exp));
-
- if (use_iterator)
- cl_git_pass(diff_foreach_via_iterator(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- else
- cl_git_pass(git_diff_foreach(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
-
- cl_assert_equal_i(0, exp.files);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
-
- cl_assert_equal_i(0, exp.hunks);
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert_equal_i(0, exp.lines);
- cl_assert_equal_i(0, exp.line_ctxt);
- cl_assert_equal_i(0, exp.line_adds);
- cl_assert_equal_i(0, exp.line_dels);
- }
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
diff = NULL;
- memset(&exp, 0, sizeof(exp));
- cl_git_rewritefile("issue_1397/crlf_file.txt", "first line\r\nsecond line modified\r\nboth with crlf");
+ cl_git_rewritefile("issue_1397/crlf_file.txt",
+ "first line\r\nsecond line modified\r\nboth with crlf");
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
- for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
- memset(&exp, 0, sizeof(exp));
-
- if (use_iterator)
- cl_git_pass(diff_foreach_via_iterator(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- else
- cl_git_pass(git_diff_foreach(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert_equal_i(1, exp.files);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
- cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
+ cl_assert_equal_i(1, exp.files);
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(1, exp.hunks);
+ cl_assert_equal_i(1, exp.hunks);
- cl_assert_equal_i(5, exp.lines);
- cl_assert_equal_i(3, exp.line_ctxt);
- cl_assert_equal_i(1, exp.line_adds);
- cl_assert_equal_i(1, exp.line_dels);
- }
+ cl_assert_equal_i(5, exp.lines);
+ cl_assert_equal_i(3, exp.line_ctxt);
+ cl_assert_equal_i(1, exp.line_adds);
+ cl_assert_equal_i(1, exp.line_dels);
git_diff_list_free(diff);
}
void test_diff_workdir__to_tree_issue_1397(void)
{
- /* grabbed a couple of commit oids from the history of the attr repo */
- const char *a_commit = "51883ad"; /* the current HEAD */
+ const char *a_commit = "7f483a738"; /* the current HEAD */
git_tree *a;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff = NULL;
git_diff_list *diff2 = NULL;
diff_expects exp;
- int use_iterator;
g_repo = cl_git_sandbox_init("issue_1397");
- set_core_autocrlf_to(true);
+ cl_repo_set_bool(g_repo, "core.autocrlf", true);
a = resolve_commit_oid_to_tree(g_repo, a_commit);
@@ -1199,66 +1153,29 @@ void test_diff_workdir__to_tree_issue_1397(void)
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
- for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
- memset(&exp, 0, sizeof(exp));
-
- if (use_iterator)
- cl_git_pass(diff_foreach_via_iterator(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- else
- cl_git_pass(git_diff_foreach(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
-
- cl_assert_equal_i(0, exp.files);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
- }
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- /* Since there is no git diff equivalent, let's just assume that the
- * text diffs produced by git_diff_foreach are accurate here. We will
- * do more apples-to-apples test comparison below.
- */
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
diff = NULL;
- memset(&exp, 0, sizeof(exp));
- /* This is a compatible emulation of "git diff <sha>" which looks like
- * a workdir to tree diff (even though it is not really). This is what
- * you would get from "git diff --name-status 26a125ee1bf"
- */
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
cl_git_pass(git_diff_index_to_workdir(&diff2, g_repo, NULL, &opts));
cl_git_pass(git_diff_merge(diff, diff2));
git_diff_list_free(diff2);
- for (use_iterator = 0; use_iterator <= 1; use_iterator++) {
- memset(&exp, 0, sizeof(exp));
-
- if (use_iterator)
- cl_git_pass(diff_foreach_via_iterator(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- else
- cl_git_pass(git_diff_foreach(
- diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
-
- cl_assert_equal_i(0, exp.files);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_IGNORED]);
- cl_assert_equal_i(0, exp.file_status[GIT_DELTA_UNTRACKED]);
-
- cl_assert_equal_i(0, exp.hunks);
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
- cl_assert_equal_i(0, exp.lines);
- cl_assert_equal_i(0, exp.line_ctxt);
- cl_assert_equal_i(0, exp.line_adds);
- cl_assert_equal_i(0, exp.line_dels);
- }
+ cl_assert_equal_i(0, exp.files);
+ cl_assert_equal_i(0, exp.hunks);
+ cl_assert_equal_i(0, exp.lines);
git_diff_list_free(diff);
git_tree_free(a);
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 49defd0..88e374e 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -251,21 +251,24 @@ void test_index_tests__add(void)
git_repository_free(repo);
}
+static void cleanup_1397(void *opaque)
+{
+ GIT_UNUSED(opaque);
+ cl_git_sandbox_cleanup();
+}
+
void test_index_tests__add_issue_1397(void)
{
git_index *index;
- git_config *cfg;
git_repository *repo;
const git_index_entry *entry;
git_oid id1;
- cl_set_cleanup(&cleanup_myrepo, NULL);
+ cl_set_cleanup(&cleanup_1397, NULL);
repo = cl_git_sandbox_init("issue_1397");
- cl_git_pass(git_repository_config(&cfg, repo));
- cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", true));
- git_config_free(cfg);
+ cl_repo_set_bool(repo, "core.autocrlf", true);
/* Ensure we're the only guy in the room */
cl_git_pass(git_repository_index(&index, repo));
@@ -278,17 +281,16 @@ void test_index_tests__add_issue_1397(void)
/* Make sure the initial SHA-1 is correct */
cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL);
- cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+ cl_assert_(git_oid_cmp(&id1, &entry->oid) == 0, "first oid check");
/* Update the index */
cl_git_pass(git_index_add_bypath(index, "crlf_file.txt"));
/* Check the new SHA-1 */
cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL);
- cl_assert(git_oid_cmp(&id1, &entry->oid) == 0);
+ cl_assert_(git_oid_cmp(&id1, &entry->oid) == 0, "second oid check");
git_index_free(index);
- git_repository_free(repo);
}
void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void)
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 61f0982..a9b8a12 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -544,12 +544,9 @@ void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf_issue_1397(void)
{
git_repository *repo = cl_git_sandbox_init("issue_1397");
- git_config *config;
unsigned int status;
- cl_git_pass(git_repository_config(&config, repo));
- cl_git_pass(git_config_set_bool(config, "core.autocrlf", true));
- git_config_free(config);
+ cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_pass(git_status_file(&status, repo, "crlf_file.txt"));