diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2011-09-02 13:44:42 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-09-15 01:14:36 +0200 |
| commit | 56453d346864e312ec138626a3fc920c39890f0d (patch) | |
| tree | 3653456e1c93d7e41e7688a306d3f519167e180b /tests | |
| parent | 3601c4bfce3df04ebfc8668e5db531ded39280a9 (diff) | |
| download | libgit2-56453d346864e312ec138626a3fc920c39890f0d.tar.gz | |
status: enhance determination of status for a single file
- fix retrieval of a file status when working against a newly initialized repository
- reduce memory pressure
- prevents a directory from being tested
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/t12-repo.c | 2 | ||||
| -rw-r--r-- | tests/t18-status.c | 63 | ||||
| -rw-r--r-- | tests/test_helpers.h | 1 |
3 files changed, 64 insertions, 2 deletions
diff --git a/tests/t12-repo.c b/tests/t12-repo.c index cc8942f40..1d9132cfd 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -212,8 +212,6 @@ BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git" must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); END_TEST -#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/" - BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git") git_repository *repo; diff --git a/tests/t18-status.c b/tests/t18-status.c index c30c541df..774dab6b1 100644 --- a/tests/t18-status.c +++ b/tests/t18-status.c @@ -174,6 +174,66 @@ BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file") git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); END_TEST +BEGIN_TEST(singlestatus2, "test retrieving status for a non existent file in an empty repository") + git_repository *repo; + unsigned int status_flags; + int error; + + must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + error = git_status_file(&status_flags, repo, "nonexistent"); + must_be_true(error == GIT_ENOTFOUND); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +BEGIN_TEST(singlestatus3, "test retrieving status for a new file in an empty repository") + git_repository *repo; + unsigned int status_flags; + char file_path[GIT_PATH_MAX]; + char filename[] = "new_file"; + int fd; + + must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); + + git_path_join(file_path, TEMP_REPO_FOLDER, filename); + fd = p_creat(file_path, 0644); + must_pass(fd); + must_pass(p_write(fd, "new_file\n", 9)); + must_pass(p_close(fd)); + + must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); + + must_pass(git_status_file(&status_flags, repo, filename)); + must_be_true(status_flags == GIT_STATUS_WT_NEW); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + +BEGIN_TEST(singlestatus4, "can't determine the status for a folder") + git_repository *repo; + unsigned int status_flags; + int error; + + 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, TEST_STD_REPO_FOLDER)); + + error = git_status_file(&status_flags, repo, "subdir"); + must_be_true(error == GIT_EINVALIDPATH); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); +END_TEST + BEGIN_SUITE(status) ADD_TEST(file0); @@ -181,4 +241,7 @@ BEGIN_SUITE(status) ADD_TEST(singlestatus0); ADD_TEST(singlestatus1); + ADD_TEST(singlestatus2); + ADD_TEST(singlestatus3); + ADD_TEST(singlestatus4); END_SUITE
\ No newline at end of file diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 75027dd6f..53361b7b1 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -37,6 +37,7 @@ #define TEST_INDEX_PATH (REPOSITORY_FOLDER "index") #define TEST_INDEX2_PATH (TEST_RESOURCES "/gitgit.index") #define TEST_INDEXBIG_PATH (TEST_RESOURCES "/big.index") +#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/" #define TEMP_FOLDER "" #define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/" |
