Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJason Penny <jasonpenny4@gmail.com>2011-07-09 07:51:05 +0400
committerVicent Marti <tanoku@gmail.com>2011-07-09 15:49:50 +0400
commit2b90cc26de1c6b71059a7fc43be32a3be7fb35b9 (patch)
treec8eac227ac3bc9de5c6f6563fd44bb23897f9ef3 /tests
parent34dfea2774c10257eb13aae515d79ea2c224b911 (diff)
status: consolidate some test code
Refactored copy of test repo to a function.
Diffstat (limited to 'tests')
-rw-r--r--tests/t18-status.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/tests/t18-status.c b/tests/t18-status.c
index 3c8a296e8..dfd87b3ab 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) {