Commit 270303ca by Ben Straub

Moved more assertions inside Clar test helpers.

parent 9297b6e0
...@@ -26,49 +26,43 @@ static struct test_entry test_entries[] = { ...@@ -26,49 +26,43 @@ static struct test_entry test_entries[] = {
// Helpers // Helpers
static int copy_file(const char *src, const char *dst) static void copy_file(const char *src, const char *dst)
{ {
git_buf source_buf = GIT_BUF_INIT; git_buf source_buf = GIT_BUF_INIT;
git_file dst_fd; git_file dst_fd;
int error = GIT_ERROR; int error = GIT_ERROR;
if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS) cl_git_pass(git_futils_readbuffer(&source_buf, src));
return GIT_ENOTFOUND;
dst_fd = git_futils_creat_withpath(dst, 0777, 0666); dst_fd = git_futils_creat_withpath(dst, 0777, 0666);
if (dst_fd < 0) if (dst_fd < 0)
goto cleanup; goto cleanup;
error = p_write(dst_fd, source_buf.ptr, source_buf.size); cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size));
cleanup: cleanup:
git_buf_free(&source_buf); git_buf_free(&source_buf);
p_close(dst_fd); p_close(dst_fd);
return error;
} }
static int cmp_files(const char *a, const char *b) static void files_are_equal(const char *a, const char *b)
{ {
git_buf buf_a = GIT_BUF_INIT; git_buf buf_a = GIT_BUF_INIT;
git_buf buf_b = GIT_BUF_INIT; git_buf buf_b = GIT_BUF_INIT;
int error = GIT_ERROR; int pass;
if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS) if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS)
return GIT_ERROR; cl_assert(0);
if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) { if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) {
git_buf_free(&buf_a); git_buf_free(&buf_a);
return GIT_ERROR; cl_assert(0);
} }
if (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size)) pass = (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size));
error = GIT_SUCCESS;
git_buf_free(&buf_a); git_buf_free(&buf_a);
git_buf_free(&buf_b); git_buf_free(&buf_b);
return error;
} }
...@@ -168,13 +162,13 @@ void test_index_tests__write(void) ...@@ -168,13 +162,13 @@ void test_index_tests__write(void)
{ {
git_index *index; git_index *index;
cl_git_pass(copy_file(TEST_INDEXBIG_PATH, "index_rewrite")); copy_file(TEST_INDEXBIG_PATH, "index_rewrite");
cl_git_pass(git_index_open(&index, "index_rewrite")); cl_git_pass(git_index_open(&index, "index_rewrite"));
cl_assert(index->on_disk); cl_assert(index->on_disk);
cl_git_pass(git_index_write(index)); cl_git_pass(git_index_write(index));
cl_git_pass(cmp_files(TEST_INDEXBIG_PATH, "index_rewrite")); files_are_equal(TEST_INDEXBIG_PATH, "index_rewrite");
git_index_free(index); git_index_free(index);
......
...@@ -6,9 +6,13 @@ ...@@ -6,9 +6,13 @@
#include "data.h" #include "data.h"
static int hash_object(git_oid *oid, git_rawobj *obj) static void hash_object_pass(git_oid *oid, git_rawobj *obj)
{ {
return git_odb_hash(oid, obj->data, obj->len, obj->type); cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static void hash_object_fail(git_oid *oid, git_rawobj *obj)
{
cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
} }
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511"; static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
...@@ -74,28 +78,28 @@ void test_object_raw_hash__hash_junk_data(void) ...@@ -74,28 +78,28 @@ void test_object_raw_hash__hash_junk_data(void)
/* invalid types: */ /* invalid types: */
junk_obj.data = some_data; junk_obj.data = some_data;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJ__EXT1; junk_obj.type = GIT_OBJ__EXT1;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJ__EXT2; junk_obj.type = GIT_OBJ__EXT2;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJ_OFS_DELTA; junk_obj.type = GIT_OBJ_OFS_DELTA;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJ_REF_DELTA; junk_obj.type = GIT_OBJ_REF_DELTA;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
/* data can be NULL only if len is zero: */ /* data can be NULL only if len is zero: */
junk_obj.type = GIT_OBJ_BLOB; junk_obj.type = GIT_OBJ_BLOB;
junk_obj.data = NULL; junk_obj.data = NULL;
cl_git_pass(hash_object(&id, &junk_obj)); hash_object_pass(&id, &junk_obj);
cl_assert(git_oid_cmp(&id, &id_zero) == 0); cl_assert(git_oid_cmp(&id, &id_zero) == 0);
junk_obj.len = 1; junk_obj.len = 1;
cl_git_fail(hash_object(&id, &junk_obj)); hash_object_fail(&id, &junk_obj);
} }
void test_object_raw_hash__hash_commit_object(void) void test_object_raw_hash__hash_commit_object(void)
...@@ -103,7 +107,7 @@ void test_object_raw_hash__hash_commit_object(void) ...@@ -103,7 +107,7 @@ void test_object_raw_hash__hash_commit_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, commit_id)); cl_git_pass(git_oid_fromstr(&id1, commit_id));
cl_git_pass(hash_object(&id2, &commit_obj)); hash_object_pass(&id2, &commit_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -112,7 +116,7 @@ void test_object_raw_hash__hash_tree_object(void) ...@@ -112,7 +116,7 @@ void test_object_raw_hash__hash_tree_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tree_id)); cl_git_pass(git_oid_fromstr(&id1, tree_id));
cl_git_pass(hash_object(&id2, &tree_obj)); hash_object_pass(&id2, &tree_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -121,7 +125,7 @@ void test_object_raw_hash__hash_tag_object(void) ...@@ -121,7 +125,7 @@ void test_object_raw_hash__hash_tag_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tag_id)); cl_git_pass(git_oid_fromstr(&id1, tag_id));
cl_git_pass(hash_object(&id2, &tag_obj)); hash_object_pass(&id2, &tag_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -130,7 +134,7 @@ void test_object_raw_hash__hash_zero_length_object(void) ...@@ -130,7 +134,7 @@ void test_object_raw_hash__hash_zero_length_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, zero_id)); cl_git_pass(git_oid_fromstr(&id1, zero_id));
cl_git_pass(hash_object(&id2, &zero_obj)); hash_object_pass(&id2, &zero_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -139,7 +143,7 @@ void test_object_raw_hash__hash_one_byte_object(void) ...@@ -139,7 +143,7 @@ void test_object_raw_hash__hash_one_byte_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, one_id)); cl_git_pass(git_oid_fromstr(&id1, one_id));
cl_git_pass(hash_object(&id2, &one_obj)); hash_object_pass(&id2, &one_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -148,7 +152,7 @@ void test_object_raw_hash__hash_two_byte_object(void) ...@@ -148,7 +152,7 @@ void test_object_raw_hash__hash_two_byte_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, two_id)); cl_git_pass(git_oid_fromstr(&id1, two_id));
cl_git_pass(hash_object(&id2, &two_obj)); hash_object_pass(&id2, &two_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -157,6 +161,6 @@ void test_object_raw_hash__hash_multi_byte_object(void) ...@@ -157,6 +161,6 @@ void test_object_raw_hash__hash_multi_byte_object(void)
git_oid id1, id2; git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, some_id)); cl_git_pass(git_oid_fromstr(&id1, some_id));
cl_git_pass(hash_object(&id2, &some_obj)); hash_object_pass(&id2, &some_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
} }
...@@ -16,73 +16,43 @@ void test_body(object_data *d, git_rawobj *o); ...@@ -16,73 +16,43 @@ void test_body(object_data *d, git_rawobj *o);
// Helpers // Helpers
static int remove_object_files(object_data *d) static void remove_object_files(object_data *d)
{ {
if (p_unlink(d->file) < 0) { cl_git_pass(p_unlink(d->file));
fprintf(stderr, "can't delete object file \"%s\"\n", d->file); cl_git_pass(p_rmdir(d->dir));
return -1; cl_assert(errno != ENOTEMPTY);
} cl_git_pass(p_rmdir(odb_dir) < 0);
if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1;
}
if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
return 0;
} }
static int streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw) static void streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw)
{ {
git_odb_stream *stream; git_odb_stream *stream;
int error; int error;
if ((error = git_odb_open_wstream(&stream, odb, raw->len, raw->type)) < GIT_SUCCESS) cl_git_pass(git_odb_open_wstream(&stream, odb, raw->len, raw->type));
return error;
stream->write(stream, raw->data, raw->len); stream->write(stream, raw->data, raw->len);
error = stream->finalize_write(oid, stream); error = stream->finalize_write(oid, stream);
stream->free(stream); stream->free(stream);
cl_git_pass(error);
return error;
} }
static int check_object_files(object_data *d) static void check_object_files(object_data *d)
{ {
if (git_path_exists(d->dir) < 0) cl_git_pass(git_path_exists(d->dir));
return -1; cl_git_pass(git_path_exists(d->file));
if (git_path_exists(d->file) < 0)
return -1;
return 0;
} }
static int cmp_objects(git_rawobj *o1, git_rawobj *o2) static void cmp_objects(git_rawobj *o1, git_rawobj *o2)
{ {
if (o1->type != o2->type) cl_assert(o1->type == o2->type);
return -1; cl_assert(o1->len == o2->len);
if (o1->len != o2->len) if (o1->len > 0)
return -1; cl_assert(memcmp(o1->data, o2->data, o1->len) == 0);
if ((o1->len > 0) && (memcmp(o1->data, o2->data, o1->len) != 0))
return -1;
return 0;
} }
static int make_odb_dir(void) static void make_odb_dir(void)
{ {
if (p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE) < 0) { cl_git_pass(p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE));
int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST)
fprintf(stderr, " (already exists)");
fprintf(stderr, "\n");
return -1;
}
return 0;
} }
...@@ -93,20 +63,20 @@ void test_body(object_data *d, git_rawobj *o) ...@@ -93,20 +63,20 @@ void test_body(object_data *d, git_rawobj *o)
git_oid id1, id2; git_oid id1, id2;
git_odb_object *obj; git_odb_object *obj;
cl_git_pass(make_odb_dir()); make_odb_dir();
cl_git_pass(git_odb_open(&db, odb_dir)); cl_git_pass(git_odb_open(&db, odb_dir));
cl_git_pass(git_oid_fromstr(&id1, d->id)); cl_git_pass(git_oid_fromstr(&id1, d->id));
cl_git_pass(streaming_write(&id2, db, o)); streaming_write(&id2, db, o);
cl_assert(git_oid_cmp(&id1, &id2) == 0); cl_assert(git_oid_cmp(&id1, &id2) == 0);
cl_git_pass(check_object_files(d)); check_object_files(d);
cl_git_pass(git_odb_read(&obj, db, &id1)); cl_git_pass(git_odb_read(&obj, db, &id1));
cl_git_pass(cmp_objects(&obj->raw, o)); cmp_objects(&obj->raw, o);
git_odb_object_free(obj); git_odb_object_free(obj);
git_odb_free(db); git_odb_free(db);
cl_git_pass(remove_object_files(d)); remove_object_files(d);
} }
......
...@@ -12,7 +12,7 @@ static git_repository *g_repo; ...@@ -12,7 +12,7 @@ static git_repository *g_repo;
// Helpers // Helpers
static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches) static void ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches)
{ {
git_strarray tag_list; git_strarray tag_list;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
...@@ -25,7 +25,7 @@ static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, c ...@@ -25,7 +25,7 @@ static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, c
exit: exit:
git_strarray_free(&tag_list); git_strarray_free(&tag_list);
return error; cl_git_pass(error);
} }
...@@ -87,13 +87,13 @@ void test_object_tag_read__list(void) ...@@ -87,13 +87,13 @@ void test_object_tag_read__list(void)
void test_object_tag_read__list_pattern(void) void test_object_tag_read__list_pattern(void)
{ {
// list all tag names from the repository matching a specified pattern // list all tag names from the repository matching a specified pattern
cl_git_pass(ensure_tag_pattern_match(g_repo, "", 3)); ensure_tag_pattern_match(g_repo, "", 3);
cl_git_pass(ensure_tag_pattern_match(g_repo, "*", 3)); ensure_tag_pattern_match(g_repo, "*", 3);
cl_git_pass(ensure_tag_pattern_match(g_repo, "t*", 1)); ensure_tag_pattern_match(g_repo, "t*", 1);
cl_git_pass(ensure_tag_pattern_match(g_repo, "*b", 2)); ensure_tag_pattern_match(g_repo, "*b", 2);
cl_git_pass(ensure_tag_pattern_match(g_repo, "e", 0)); ensure_tag_pattern_match(g_repo, "e", 0);
cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810b", 1)); ensure_tag_pattern_match(g_repo, "e90810b", 1);
cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810[ab]", 1)); ensure_tag_pattern_match(g_repo, "e90810[ab]", 1);
} }
void test_object_tag_read__parse_without_tagger(void) void test_object_tag_read__parse_without_tagger(void)
......
...@@ -42,17 +42,15 @@ static void locate_loose_object(const char *repository_folder, git_object *objec ...@@ -42,17 +42,15 @@ static void locate_loose_object(const char *repository_folder, git_object *objec
*out_folder = top_folder; *out_folder = top_folder;
} }
static int loose_object_mode(const char *repository_folder, git_object *object) static void loose_object_mode(const char *repository_folder, git_object *object)
{ {
char *object_path; char *object_path;
struct stat st; struct stat st;
locate_loose_object(repository_folder, object, &object_path, NULL); locate_loose_object(repository_folder, object, &object_path, NULL);
if (p_stat(object_path, &st) < 0) cl_git_pass(p_stat(object_path, &st));
return 0;
free(object_path); free(object_path);
cl_assert((st.st_mode & 0777) == GIT_OBJECT_FILE_MODE);
return st.st_mode;
} }
#endif #endif
...@@ -117,7 +115,7 @@ void test_object_tag_write__basic(void) ...@@ -117,7 +115,7 @@ void test_object_tag_write__basic(void)
cl_git_pass(git_reference_delete(ref_tag)); cl_git_pass(git_reference_delete(ref_tag));
#ifndef GIT_WIN32 #ifndef GIT_WIN32
// TODO: Get this to work on Linux // TODO: Get this to work on Linux
// cl_assert((loose_object_mode("testrepo", (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE); //loose_object_mode("testrepo/", (git_object *)tag);
#endif #endif
git_tag_free(tag); git_tag_free(tag);
......
...@@ -13,24 +13,13 @@ static git_repository *g_repo; ...@@ -13,24 +13,13 @@ static git_repository *g_repo;
// helpers // helpers
static int assert_signature(git_signature *expected, git_signature *actual) static void assert_signature(git_signature *expected, git_signature *actual)
{ {
if (actual == NULL) cl_assert(actual);
return GIT_ERROR; cl_assert(0 == strcmp(expected->name, actual->name));
cl_assert(0 == strcmp(expected->email, actual->email));
if (strcmp(expected->name, actual->name) != 0) cl_assert(expected->when.offset == actual->when.offset);
return GIT_ERROR; cl_assert(expected->when.time == actual->when.time);
if (strcmp(expected->email, actual->email) != 0)
return GIT_ERROR;
if (expected->when.offset != actual->when.offset)
return GIT_ERROR;
if (expected->when.time != actual->when.time)
return GIT_ERROR;
return GIT_SUCCESS;
} }
...@@ -82,7 +71,7 @@ void test_refs_reflog__write_then_read(void) ...@@ -82,7 +71,7 @@ void test_refs_reflog__write_then_read(void)
cl_assert(reflog->entries.length == 2); cl_assert(reflog->entries.length == 2);
entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0); entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0);
cl_git_pass(assert_signature(committer, entry->committer)); assert_signature(committer, entry->committer);
git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
cl_assert(strcmp("0000000000000000000000000000000000000000", oid_str) == 0); cl_assert(strcmp("0000000000000000000000000000000000000000", oid_str) == 0);
git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
...@@ -90,7 +79,7 @@ void test_refs_reflog__write_then_read(void) ...@@ -90,7 +79,7 @@ void test_refs_reflog__write_then_read(void)
cl_assert(entry->msg == NULL); cl_assert(entry->msg == NULL);
entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1); entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1);
cl_git_pass(assert_signature(committer, entry->committer)); assert_signature(committer, entry->committer);
git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
cl_assert(strcmp(current_master_tip, oid_str) == 0); cl_assert(strcmp(current_master_tip, oid_str) == 0);
git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
......
...@@ -23,61 +23,45 @@ ...@@ -23,61 +23,45 @@
#define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3" #define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3"
#define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo" #define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo"
static int ensure_repository_discover(const char *start_path, const char *ceiling_dirs, const char *expected_path) static void ensure_repository_discover(const char *start_path, const char *ceiling_dirs, const char *expected_path)
{ {
int error;
char found_path[GIT_PATH_MAX]; char found_path[GIT_PATH_MAX];
cl_git_pass(git_repository_discover(found_path, sizeof(found_path), start_path, 0, ceiling_dirs));
error = git_repository_discover(found_path, sizeof(found_path), start_path, 0, ceiling_dirs);
//across_fs is always 0 as we can't automate the filesystem change tests //across_fs is always 0 as we can't automate the filesystem change tests
cl_assert(0 == strcmp(found_path, expected_path));
if (error < GIT_SUCCESS)
return error;
return strcmp(found_path, expected_path) ? GIT_ERROR : GIT_SUCCESS;
} }
static int write_file(const char *path, const char *content) static void write_file(const char *path, const char *content)
{ {
int error;
git_file file; git_file file;
int error;
if (git_path_exists(path) == GIT_SUCCESS) { if (git_path_exists(path) == GIT_SUCCESS) {
error = p_unlink(path); cl_git_pass(p_unlink(path));
if (error < GIT_SUCCESS)
return error;
} }
file = git_futils_creat_withpath(path, 0777, 0666); file = git_futils_creat_withpath(path, 0777, 0666);
if (file < GIT_SUCCESS) cl_assert(file >= 0);
return file;
error = p_write(file, content, strlen(content) * sizeof(char)); error = p_write(file, content, strlen(content) * sizeof(char));
p_close(file); p_close(file);
cl_git_pass(error);
return error;
} }
//no check is performed on ceiling_dirs length, so be sure it's long enough //no check is performed on ceiling_dirs length, so be sure it's long enough
static int append_ceiling_dir(git_buf *ceiling_dirs, const char *path) static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
{ {
git_buf pretty_path = GIT_BUF_INIT; git_buf pretty_path = GIT_BUF_INIT;
int error;
char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' }; char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
error = git_path_prettify_dir(&pretty_path, path, NULL); cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL));
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to append ceiling directory.");
if (ceiling_dirs->size > 0) if (ceiling_dirs->size > 0)
git_buf_puts(ceiling_dirs, ceiling_separator); git_buf_puts(ceiling_dirs, ceiling_separator);
git_buf_puts(ceiling_dirs, pretty_path.ptr); git_buf_puts(ceiling_dirs, pretty_path.ptr);
git_buf_free(&pretty_path); git_buf_free(&pretty_path);
cl_git_pass(git_buf_lasterror(ceiling_dirs));
return git_buf_lasterror(ceiling_dirs);
} }
void test_repo_discover__0(void) void test_repo_discover__0(void)
...@@ -92,7 +76,7 @@ void test_repo_discover__0(void) ...@@ -92,7 +76,7 @@ void test_repo_discover__0(void)
const mode_t mode = 0777; const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode); git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode);
cl_git_pass(append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER)); append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf); ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
cl_assert(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO); cl_assert(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO);
...@@ -106,33 +90,33 @@ void test_repo_discover__0(void) ...@@ -106,33 +90,33 @@ void test_repo_discover__0(void)
cl_git_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); cl_git_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode));
cl_git_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode)); cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode));
cl_git_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
cl_git_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
cl_git_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../")); write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../");
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path);
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode));
cl_git_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:")); write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, NULL, mode));
cl_git_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:")); write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, NULL, mode));
cl_git_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n")); write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode)); cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode));
cl_git_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist")); write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist");
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
cl_git_pass(append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER)); append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER);
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf); ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
//this must pass as ceiling_directories cannot predent the current //this must pass as ceiling_directories cannot predent the current
...@@ -143,10 +127,10 @@ void test_repo_discover__0(void) ...@@ -143,10 +127,10 @@ void test_repo_discover__0(void)
cl_git_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs)); cl_git_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
//.gitfile redirection should not be affected by ceiling directories //.gitfile redirection should not be affected by ceiling directories
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path);
cl_git_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path);
cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
git_repository_free(repo); git_repository_free(repo);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment