status: consolidate some test code Refactored copy of test repo to a function.
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
diff --git a/tests/t18-status.c b/tests/t18-status.c
index 3c8a296..dfd87b3 100644
--- a/tests/t18-status.c
+++ b/tests/t18-status.c
@@ -32,17 +32,37 @@
static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a";
-BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB")
+static int copy_status_repo(char *path_statusfiles, char *temp_path)
+{
char current_workdir[GIT_PATH_MAX];
+ char gitted[GIT_PATH_MAX];
+ int error;
+
+ error = p_getcwd(current_workdir, sizeof(current_workdir));
+ if (error < 0)
+ return error;
+ strcpy(path_statusfiles, current_workdir);
+ git_path_join(path_statusfiles, path_statusfiles, TEMP_STATUS_FOLDER);
+
+ error = copydir_recurs(STATUS_FOLDER, path_statusfiles);
+ if (error < 0)
+ return error;
+
+ git_path_join(gitted, path_statusfiles, ".gitted");
+ git_path_join(temp_path, path_statusfiles, ".git");
+ copydir_recurs(gitted, temp_path);
+ git_futils_rmdir_r(gitted, 1);
+
+ return GIT_SUCCESS;
+}
+
+BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB")
char path_statusfiles[GIT_PATH_MAX];
char temp_path[GIT_PATH_MAX];
git_oid expected_id, actual_id;
- must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- strcpy(path_statusfiles, current_workdir);
- git_path_join(path_statusfiles, path_statusfiles, TEMP_STATUS_FOLDER);
+ must_pass(copy_status_repo(path_statusfiles, temp_path));
- must_pass(copydir_recurs(STATUS_FOLDER, path_statusfiles));
git_path_join(temp_path, path_statusfiles, "new_file");
must_pass(git_futils_exists(temp_path));
@@ -124,23 +144,13 @@ static int status_cb(const char *path, unsigned int status_flags, void *payload)
}
BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository")
- char current_workdir[GIT_PATH_MAX];
char path_statusfiles[GIT_PATH_MAX];
char temp_path[GIT_PATH_MAX];
- char gitted[GIT_PATH_MAX];
git_repository *repo;
struct status_entry_counts counts;
- must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- strcpy(path_statusfiles, current_workdir);
- git_path_join(path_statusfiles, path_statusfiles, TEMP_STATUS_FOLDER);
-
- must_pass(copydir_recurs(STATUS_FOLDER, path_statusfiles));
+ must_pass(copy_status_repo(path_statusfiles, temp_path));
- git_path_join(gitted, path_statusfiles, ".gitted");
- git_path_join(temp_path, path_statusfiles, ".git");
- copydir_recurs(gitted, temp_path);
- git_futils_rmdir_r(gitted, 1);
must_pass(git_repository_open(&repo, temp_path));
memset(&counts, 0x0, sizeof(struct status_entry_counts));
@@ -154,24 +164,14 @@ BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository")
END_TEST
BEGIN_TEST(singlestatus0, "test retrieving status for single file")
- char current_workdir[GIT_PATH_MAX];
char path_statusfiles[GIT_PATH_MAX];
char temp_path[GIT_PATH_MAX];
- char gitted[GIT_PATH_MAX];
git_repository *repo;
unsigned int status_flags;
int i;
- must_pass(p_getcwd(current_workdir, sizeof(current_workdir)));
- strcpy(path_statusfiles, current_workdir);
- git_path_join(path_statusfiles, path_statusfiles, TEMP_STATUS_FOLDER);
-
- must_pass(copydir_recurs(STATUS_FOLDER, path_statusfiles));
+ must_pass(copy_status_repo(path_statusfiles, temp_path));
- git_path_join(gitted, path_statusfiles, ".gitted");
- git_path_join(temp_path, path_statusfiles, ".git");
- copydir_recurs(gitted, temp_path);
- git_futils_rmdir_r(gitted, 1);
must_pass(git_repository_open(&repo, temp_path));
for (i = 0; i < ENTRY_COUNT; ++i) {