Commit 471bb8b120fab5969df5778aa5c8d1c22c30d876

Vicent Martí 2012-04-03T04:52:52

tests: Cleanup & fix test suite

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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
diff --git a/tests-clar/commit/write.c b/tests-clar/commit/write.c
index 66fe2bf..5a8e0c4 100644
--- a/tests-clar/commit/write.c
+++ b/tests-clar/commit/write.c
@@ -77,10 +77,6 @@ void test_commit_write__from_memory(void)
    cl_assert(committer1->when.offset == 60);
 
    cl_assert(strcmp(git_commit_message(commit), commit_message) == 0);
-
-#ifndef GIT_WIN32
-   cl_assert((loose_object_mode(REPOSITORY_FOLDER, (git_object *)commit) & 0777) == GIT_OBJECT_FILE_MODE);
-#endif
 }
 
 
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 9edcabe..ead42ec 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -30,7 +30,6 @@ static void copy_file(const char *src, const char *dst)
 {
 	git_buf source_buf = GIT_BUF_INIT;
 	git_file dst_fd;
-	int error = GIT_ERROR;
 
 	cl_git_pass(git_futils_readbuffer(&source_buf, src));
 
diff --git a/tests-clar/object/tag/write.c b/tests-clar/object/tag/write.c
index 10db0f3..791e1ac 100644
--- a/tests-clar/object/tag/write.c
+++ b/tests-clar/object/tag/write.c
@@ -9,56 +9,6 @@ static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
 
 static git_repository *g_repo;
 
-
-// Helpers
-#ifndef GIT_WIN32
-#include "odb.h"
-
-static void locate_loose_object(const char *repository_folder,
-                                git_object *object,
-                                char **out,
-                                char **out_folder)
-{
-	static const char *objects_folder = "objects/";
-
-	char *ptr, *full_path, *top_folder;
-	int path_length, objects_length;
-
-	assert(repository_folder && object);
-
-	objects_length = strlen(objects_folder);
-	path_length = strlen(repository_folder);
-	ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3);
-
-	strcpy(ptr, repository_folder);
-	strcpy(ptr + path_length, objects_folder);
-
-	ptr = top_folder = ptr + path_length + objects_length;
-	*ptr++ = '/';
-	git_oid_pathfmt(ptr, git_object_id(object));
-	ptr += GIT_OID_HEXSZ + 1;
-	*ptr = 0;
-
-	*out = full_path;
-
-	if (out_folder)
-		*out_folder = top_folder;
-}
-
-static void loose_object_mode(const char *repository_folder, git_object *object)
-{
-	char *object_path;
-	struct stat st;
-
-	locate_loose_object(repository_folder, object, &object_path, NULL);
-	cl_git_pass(p_stat(object_path, &st));
-	free(object_path);
-	cl_assert((st.st_mode & 0777) == GIT_OBJECT_FILE_MODE);
-}
-#endif
-
-
-
 // Fixture setup and teardown
 void test_object_tag_write__initialize(void)
 {
@@ -70,8 +20,6 @@ void test_object_tag_write__cleanup(void)
    cl_git_sandbox_cleanup();
 }
 
-
-
 void test_object_tag_write__basic(void)
 {
    // write a tag to the repository and read it again
@@ -88,14 +36,10 @@ void test_object_tag_write__basic(void)
 	/* create signature */
 	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
 
-	cl_git_pass(git_tag_create(
-                              &tag_id, /* out id */
-                              g_repo,
-                              "the-tag",
-                              target,
-                              tagger,
-                              tagger_message,
-                              0));
+	cl_git_pass(
+		git_tag_create(&tag_id, g_repo,
+		  "the-tag", target, tagger, tagger_message, 0)
+	);
 
 	git_object_free(target);
 	git_signature_free(tagger);
@@ -116,10 +60,6 @@ void test_object_tag_write__basic(void)
 	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
 	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
 	cl_git_pass(git_reference_delete(ref_tag));
-#ifndef GIT_WIN32
-	// TODO: Get this to work on Linux
-	//loose_object_mode("testrepo/", (git_object *)tag);
-#endif
 
 	git_tag_free(tag);
 }
diff --git a/tests-clar/object/tree/write.c b/tests-clar/object/tree/write.c
index 7916886..941b045 100644
--- a/tests-clar/object/tree/write.c
+++ b/tests-clar/object/tree/write.c
@@ -39,74 +39,6 @@ static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth)
 	return GIT_SUCCESS;
 }
 
-static void locate_loose_object(const char *repository_folder,
-                                git_object *object,
-                                char **out,
-                                char **out_folder)
-{
-	static const char *objects_folder = "objects/";
-
-	char *ptr, *full_path, *top_folder;
-	int path_length, objects_length;
-
-	assert(repository_folder && object);
-
-	objects_length = strlen(objects_folder);
-	path_length = strlen(repository_folder);
-	ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3);
-
-	strcpy(ptr, repository_folder);
-	strcpy(ptr + path_length, objects_folder);
-
-	ptr = top_folder = ptr + path_length + objects_length;
-	*ptr++ = '/';
-	git_oid_pathfmt(ptr, git_object_id(object));
-	ptr += GIT_OID_HEXSZ + 1;
-	*ptr = 0;
-
-	*out = full_path;
-
-	if (out_folder)
-		*out_folder = top_folder;
-}
-
-static int loose_object_mode(const char *repository_folder, git_object *object)
-{
-	char *object_path;
-	struct stat st;
-
-	locate_loose_object(repository_folder, object, &object_path, NULL);
-	if (p_stat(object_path, &st) < 0)
-		return 0;
-	free(object_path);
-
-	return st.st_mode;
-}
-
-static int loose_object_dir_mode(const char *repository_folder, git_object *object)
-{
-	char *object_path;
-	size_t pos;
-	struct stat st;
-
-	locate_loose_object(repository_folder, object, &object_path, NULL);
-
-	pos = strlen(object_path);
-	while (pos--) {
-		if (object_path[pos] == '/') {
-			object_path[pos] = 0;
-			break;
-		}
-	}
-
-	if (p_stat(object_path, &st) < 0)
-		return 0;
-	free(object_path);
-
-	return st.st_mode;
-}
-
-
 // Fixture setup and teardown
 void test_object_tree_write__initialize(void)
 {
@@ -118,21 +50,6 @@ void test_object_tree_write__cleanup(void)
    cl_git_sandbox_cleanup();
 }
 
-
-#if 0
-void xtest_object_tree_write__print(void)
-{
-   // write a tree from an index
-	git_index *index;
-	git_oid tree_oid;
-
-	cl_git_pass(git_repository_index(&index, g_repo));
-
-	cl_git_pass(git_tree_create_fromindex(&tree_oid, index));
-	cl_git_pass(print_tree(g_repo, &tree_oid, 0));
-}
-#endif
-
 void test_object_tree_write__from_memory(void)
 {
    // write a tree from a memory
@@ -193,10 +110,5 @@ void test_object_tree_write__subtree(void)
 	// check data is correct
 	cl_git_pass(git_tree_lookup(&tree, g_repo, &id_hiearar));
 	cl_assert(2 == git_tree_entrycount(tree));
-#ifndef GIT_WIN32
-   // TODO: fix these
-	//cl_assert((loose_object_dir_mode("testrepo", (git_object *)tree) & 0777) == GIT_OBJECT_DIR_MODE);
-	//cl_assert((loose_object_mode("testrespo", (git_object *)tree) & 0777) == GIT_OBJECT_FILE_MODE);
-#endif
 	git_tree_free(tree);
 }
diff --git a/tests-clar/refs/create.c b/tests-clar/refs/create.c
index e8f99a2..3674022 100644
--- a/tests-clar/refs/create.c
+++ b/tests-clar/refs/create.c
@@ -9,21 +9,17 @@ static const char *current_head_target = "refs/heads/master";
 
 static git_repository *g_repo;
 
-
-
-void test_ref_create__initialize(void)
+void test_refs_create__initialize(void)
 {
    g_repo = cl_git_sandbox_init("testrepo");
 }
 
-void test_ref_create__cleanup(void)
+void test_refs_create__cleanup(void)
 {
    cl_git_sandbox_cleanup();
 }
 
-
-
-void test_ref_create__symbolic(void)
+void test_refs_create__symbolic(void)
 {
    // create a new symbolic reference
 	git_reference *new_reference, *looked_up_ref, *resolved_ref;
@@ -71,7 +67,7 @@ void test_ref_create__symbolic(void)
 	git_reference_free(resolved_ref);
 }
 
-void test_ref_create__deep_symbolic(void)
+void test_refs_create__deep_symbolic(void)
 {
    // create a deep symbolic reference
 	git_reference *new_reference, *looked_up_ref, *resolved_ref;
@@ -94,7 +90,7 @@ void test_ref_create__deep_symbolic(void)
 	git_buf_free(&ref_path);
 }
 
-void test_ref_create__oid(void)
+void test_refs_create__oid(void)
 {
    // create a new OID reference
 	git_reference *new_reference, *looked_up_ref;
@@ -135,7 +131,7 @@ void test_ref_create__oid(void)
 	git_buf_free(&ref_path);
 }
 
-void test_ref_create__oid_unknown(void)
+void test_refs_create__oid_unknown(void)
 {
    // Can not create a new OID reference which targets at an unknown id
 	git_reference *new_reference, *looked_up_ref;
diff --git a/tests-clar/refs/overwrite.c b/tests-clar/refs/overwrite.c
index 60d3149..5c6fd54 100644
--- a/tests-clar/refs/overwrite.c
+++ b/tests-clar/refs/overwrite.c
@@ -11,21 +11,17 @@ static const char *ref_test_name = "refs/heads/test";
 
 static git_repository *g_repo;
 
-
-
-void test_ref_overwrite__initialize(void)
+void test_refs_overwrite__initialize(void)
 {
    g_repo = cl_git_sandbox_init("testrepo");
 }
 
-void test_ref_overwrite__cleanup(void)
+void test_refs_overwrite__cleanup(void)
 {
    cl_git_sandbox_cleanup();
 }
 
-
-
-void test_ref_overwrite__symbolic(void)
+void test_refs_overwrite__symbolic(void)
 {
    // Overwrite an existing symbolic reference
 	git_reference *ref, *branch_ref;
@@ -55,7 +51,7 @@ void test_ref_overwrite__symbolic(void)
 	git_reference_free(branch_ref);
 }
 
-void test_ref_overwrite__object_id(void)
+void test_refs_overwrite__object_id(void)
 {
    // Overwrite an existing object id reference
 	git_reference *ref;
@@ -87,7 +83,7 @@ void test_ref_overwrite__object_id(void)
 	git_reference_free(ref);
 }
 
-void test_ref_overwrite__object_id_with_symbolic(void)
+void test_refs_overwrite__object_id_with_symbolic(void)
 {
    // Overwrite an existing object id reference with a symbolic one
 	git_reference *ref;
@@ -112,7 +108,7 @@ void test_ref_overwrite__object_id_with_symbolic(void)
 	git_reference_free(ref);
 }
 
-void test_ref_overwrite__symbolic_with_object_id(void)
+void test_refs_overwrite__symbolic_with_object_id(void)
 {
    // Overwrite an existing symbolic reference with an object id one
 	git_reference *ref;
diff --git a/tests-clar/refs/pack.c b/tests-clar/refs/pack.c
index 6bb42cd..dca83d1 100644
--- a/tests-clar/refs/pack.c
+++ b/tests-clar/refs/pack.c
@@ -8,21 +8,17 @@ static const char *loose_tag_ref_name = "refs/tags/e90810b";
 
 static git_repository *g_repo;
 
-
-
-void test_ref_pack__initialize(void)
+void test_refs_pack__initialize(void)
 {
    g_repo = cl_git_sandbox_init("testrepo");
 }
 
-void test_ref_pack__cleanup(void)
+void test_refs_pack__cleanup(void)
 {
    cl_git_sandbox_cleanup();
 }
 
-
-
-void test_ref_pack__empty(void)
+void test_refs_pack__empty(void)
 {
    // create a packfile for an empty folder
 	git_buf temp_path = GIT_BUF_INIT;
@@ -34,7 +30,7 @@ void test_ref_pack__empty(void)
 	cl_git_pass(git_reference_packall(g_repo));
 }
 
-void test_ref_pack__loose(void)
+void test_refs_pack__loose(void)
 {
    // create a packfile from all the loose rn a repo
 	git_reference *reference;
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index f26fb63..c7e88ab 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -4,7 +4,6 @@
 #include "git2/reflog.h"
 #include "reflog.h"
 
-
 static const char *loose_tag_ref_name = "refs/tags/e90810b";
 static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist";
 static const char *head_tracker_sym_ref_name = "head-tracker";
@@ -15,21 +14,17 @@ static const char *packed_test_head_name = "refs/heads/packed-test";
 
 static git_repository *g_repo;
 
-
-
-void test_ref_read__initialize(void)
+void test_refs_read__initialize(void)
 {
    g_repo = cl_git_sandbox_init("testrepo");
 }
 
-void test_ref_read__cleanup(void)
+void test_refs_read__cleanup(void)
 {
    cl_git_sandbox_cleanup();
 }
 
-
-
-void test_ref_read__loose_tag(void)
+void test_refs_read__loose_tag(void)
 {
    // lookup a loose tag reference
 	git_reference *reference;
@@ -55,7 +50,7 @@ void test_ref_read__loose_tag(void)
 	git_reference_free(reference);
 }
 
-void test_ref_read__nonexisting_tag(void)
+void test_refs_read__nonexisting_tag(void)
 {
    // lookup a loose tag reference that doesn't exist
 	git_reference *reference;
@@ -66,7 +61,7 @@ void test_ref_read__nonexisting_tag(void)
 }
 
 
-void test_ref_read__symbolic(void)
+void test_refs_read__symbolic(void)
 {
    // lookup a symbolic reference
 	git_reference *reference, *resolved_ref;
@@ -94,7 +89,7 @@ void test_ref_read__symbolic(void)
 	git_reference_free(resolved_ref);
 }
 
-void test_ref_read__nested_symbolic(void)
+void test_refs_read__nested_symbolic(void)
 {
    // lookup a nested symbolic reference
 	git_reference *reference, *resolved_ref;
@@ -122,7 +117,7 @@ void test_ref_read__nested_symbolic(void)
 	git_reference_free(resolved_ref);
 }
 
-void test_ref_read__head_then_master(void)
+void test_refs_read__head_then_master(void)
 {
    // lookup the HEAD and resolve the master branch
 	git_reference *reference, *resolved_ref, *comp_base_ref;
@@ -146,7 +141,7 @@ void test_ref_read__head_then_master(void)
 	git_reference_free(comp_base_ref);
 }
 
-void test_ref_read__master_then_head(void)
+void test_refs_read__master_then_head(void)
 {
    // lookup the master branch and then the HEAD
 	git_reference *reference, *master_ref, *resolved_ref;
@@ -163,7 +158,7 @@ void test_ref_read__master_then_head(void)
 }
 
 
-void test_ref_read__packed(void)
+void test_refs_read__packed(void)
 {
    // lookup a packed reference
 	git_reference *reference;
@@ -183,7 +178,7 @@ void test_ref_read__packed(void)
 	git_reference_free(reference);
 }
 
-void test_ref_read__loose_first(void)
+void test_refs_read__loose_first(void)
 {
    // assure that a loose reference is looked up before a packed reference
 	git_reference *reference;