mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
status: refactor the tests to remove some code duplication
This commit is contained in:
parent
467545d0a5
commit
d4760a42f9
@ -196,8 +196,7 @@ BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping
|
|||||||
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
|
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
#define EMPTY_BARE_REPOSITORY_NAME "empty_bare.git"
|
#define EMPTY_BARE_REPOSITORY_FOLDER TEST_RESOURCES "/empty_bare.git/"
|
||||||
#define EMPTY_BARE_REPOSITORY_FOLDER TEST_RESOURCES "/" EMPTY_BARE_REPOSITORY_NAME "/"
|
|
||||||
|
|
||||||
BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git")
|
BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git")
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
@ -213,18 +212,15 @@ BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git"
|
|||||||
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
|
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
#define SOURCE_EMPTY_REPOSITORY_NAME "empty_standard_repo/.gitted"
|
#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/"
|
||||||
#define EMPTY_REPOSITORY_NAME "empty_standard_repo/.git"
|
|
||||||
#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/" SOURCE_EMPTY_REPOSITORY_NAME "/"
|
|
||||||
#define DEST_REPOSITORY_FOLDER TEMP_REPO_FOLDER DOT_GIT "/"
|
|
||||||
|
|
||||||
BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git")
|
BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git")
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
|
|
||||||
must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, DEST_REPOSITORY_FOLDER));
|
must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER));
|
||||||
must_pass(remove_placeholders(DEST_REPOSITORY_FOLDER, "dummy-marker.txt"));
|
must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt"));
|
||||||
|
|
||||||
must_pass(git_repository_open(&repo, DEST_REPOSITORY_FOLDER));
|
must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
|
||||||
must_be_true(git_repository_path(repo, GIT_REPO_PATH) != NULL);
|
must_be_true(git_repository_path(repo, GIT_REPO_PATH) != NULL);
|
||||||
must_be_true(git_repository_path(repo, GIT_REPO_PATH_WORKDIR) != NULL);
|
must_be_true(git_repository_path(repo, GIT_REPO_PATH_WORKDIR) != NULL);
|
||||||
|
|
||||||
|
@ -22,57 +22,33 @@
|
|||||||
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test_lib.h"
|
#include "test_lib.h"
|
||||||
#include "test_helpers.h"
|
#include "test_helpers.h"
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
#include "git2/status.h"
|
#include "git2/status.h"
|
||||||
|
|
||||||
#define STATUS_FOLDER TEST_RESOURCES "/status"
|
|
||||||
#define TEMP_STATUS_FOLDER TEMP_FOLDER "status"
|
|
||||||
|
|
||||||
static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a";
|
static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a";
|
||||||
|
|
||||||
static int copy_status_repo(char *path_statusfiles, char *temp_path)
|
#define STATUS_WORKDIR_FOLDER TEST_RESOURCES "/status/"
|
||||||
{
|
#define STATUS_REPOSITORY_TEMP_FOLDER TEMP_REPO_FOLDER ".gitted/"
|
||||||
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")
|
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;
|
git_oid expected_id, actual_id;
|
||||||
|
char filename[] = "new_file";
|
||||||
|
int fd;
|
||||||
|
|
||||||
must_pass(copy_status_repo(path_statusfiles, temp_path));
|
fd = p_creat(filename, 0644);
|
||||||
|
must_pass(fd);
|
||||||
|
must_pass(p_write(fd, "new_file\n", 9));
|
||||||
|
must_pass(p_close(fd));
|
||||||
|
|
||||||
git_path_join(temp_path, path_statusfiles, "new_file");
|
must_pass(git_odb_hashfile(&actual_id, filename, GIT_OBJ_BLOB));
|
||||||
|
|
||||||
must_pass(git_futils_exists(temp_path));
|
|
||||||
|
|
||||||
git_oid_fromstr(&expected_id, test_blob_oid);
|
|
||||||
must_pass(git_odb_hashfile(&actual_id, temp_path, GIT_OBJ_BLOB));
|
|
||||||
|
|
||||||
|
must_pass(git_oid_fromstr(&expected_id, test_blob_oid));
|
||||||
must_be_true(git_oid_cmp(&expected_id, &actual_id) == 0);
|
must_be_true(git_oid_cmp(&expected_id, &actual_id) == 0);
|
||||||
|
|
||||||
git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1);
|
must_pass(p_unlink(filename));
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
static const char *entry_paths[] = {
|
static const char *entry_paths[] = {
|
||||||
@ -144,14 +120,12 @@ static int status_cb(const char *path, unsigned int status_flags, void *payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository")
|
BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository")
|
||||||
char path_statusfiles[GIT_PATH_MAX];
|
|
||||||
char temp_path[GIT_PATH_MAX];
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
struct status_entry_counts counts;
|
struct status_entry_counts counts;
|
||||||
|
|
||||||
must_pass(copy_status_repo(path_statusfiles, temp_path));
|
must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER));
|
||||||
|
must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER));
|
||||||
must_pass(git_repository_open(&repo, temp_path));
|
must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
|
||||||
|
|
||||||
memset(&counts, 0x0, sizeof(struct status_entry_counts));
|
memset(&counts, 0x0, sizeof(struct status_entry_counts));
|
||||||
git_status_foreach(repo, status_cb, &counts);
|
git_status_foreach(repo, status_cb, &counts);
|
||||||
@ -160,19 +134,17 @@ BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository")
|
|||||||
|
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
|
||||||
git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1);
|
git_futils_rmdir_r(TEMP_REPO_FOLDER, 1);
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
BEGIN_TEST(singlestatus0, "test retrieving status for single file")
|
BEGIN_TEST(singlestatus0, "test retrieving status for single file")
|
||||||
char path_statusfiles[GIT_PATH_MAX];
|
|
||||||
char temp_path[GIT_PATH_MAX];
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
unsigned int status_flags;
|
unsigned int status_flags;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
must_pass(copy_status_repo(path_statusfiles, temp_path));
|
must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER));
|
||||||
|
must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER));
|
||||||
must_pass(git_repository_open(&repo, temp_path));
|
must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
|
||||||
|
|
||||||
for (i = 0; i < ENTRY_COUNT; ++i) {
|
for (i = 0; i < ENTRY_COUNT; ++i) {
|
||||||
must_pass(git_status_file(&status_flags, repo, entry_paths[i]));
|
must_pass(git_status_file(&status_flags, repo, entry_paths[i]));
|
||||||
@ -181,19 +153,17 @@ BEGIN_TEST(singlestatus0, "test retrieving status for single file")
|
|||||||
|
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
|
||||||
git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1);
|
git_futils_rmdir_r(TEMP_REPO_FOLDER, 1);
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file")
|
BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file")
|
||||||
char path_statusfiles[GIT_PATH_MAX];
|
|
||||||
char temp_path[GIT_PATH_MAX];
|
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
unsigned int status_flags;
|
unsigned int status_flags;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
must_pass(copy_status_repo(path_statusfiles, temp_path));
|
must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER));
|
||||||
|
must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER));
|
||||||
must_pass(git_repository_open(&repo, temp_path));
|
must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER));
|
||||||
|
|
||||||
// "nonexistent" does not exist in HEAD, Index or the worktree
|
// "nonexistent" does not exist in HEAD, Index or the worktree
|
||||||
error = git_status_file(&status_flags, repo, "nonexistent");
|
error = git_status_file(&status_flags, repo, "nonexistent");
|
||||||
@ -201,12 +171,14 @@ BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file")
|
|||||||
|
|
||||||
git_repository_free(repo);
|
git_repository_free(repo);
|
||||||
|
|
||||||
git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1);
|
git_futils_rmdir_r(TEMP_REPO_FOLDER, 1);
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
BEGIN_SUITE(status)
|
BEGIN_SUITE(status)
|
||||||
ADD_TEST(file0);
|
ADD_TEST(file0);
|
||||||
|
|
||||||
ADD_TEST(statuscb0);
|
ADD_TEST(statuscb0);
|
||||||
|
|
||||||
ADD_TEST(singlestatus0);
|
ADD_TEST(singlestatus0);
|
||||||
ADD_TEST(singlestatus1);
|
ADD_TEST(singlestatus1);
|
||||||
END_SUITE
|
END_SUITE
|
@ -41,6 +41,7 @@
|
|||||||
#define TEMP_FOLDER ""
|
#define TEMP_FOLDER ""
|
||||||
#define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/"
|
#define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/"
|
||||||
#define TEMP_REPO_FOLDER_NS TEMP_FOLDER TEST_REPOSITORY_NAME
|
#define TEMP_REPO_FOLDER_NS TEMP_FOLDER TEST_REPOSITORY_NAME
|
||||||
|
#define TEST_STD_REPO_FOLDER TEMP_REPO_FOLDER ".git/"
|
||||||
|
|
||||||
typedef struct object_data {
|
typedef struct object_data {
|
||||||
unsigned char *bytes; /* (compressed) bytes stored in object store */
|
unsigned char *bytes; /* (compressed) bytes stored in object store */
|
||||||
|
Loading…
Reference in New Issue
Block a user