diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-05-19 13:04:32 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-06-06 09:38:44 +0200 |
commit | 92d3ea4e398e8fbe3bf59088dc1a9ce8642b23fe (patch) | |
tree | 455ed810f8384979e005b9546268b4f5fe939081 | |
parent | 8fe335382a27296ea7fb575cc0644a18b6e81c37 (diff) | |
download | libgit2-92d3ea4e398e8fbe3bf59088dc1a9ce8642b23fe.tar.gz |
tests: index::version: improve write test for index v4
The current write test does not trigger some edge-cases in the index
version 4 path compression code. Rewrite the test to start off the an
empty standard repository, creating index entries with interesting paths
itself. This allows for more fine-grained control over checked paths.
Furthermore, we now also verify that entry paths are actually
reconstructed correctly.
-rw-r--r-- | tests/index/version.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/tests/index/version.c b/tests/index/version.c index fc139f6b3..7ada302b5 100644 --- a/tests/index/version.c +++ b/tests/index/version.c @@ -34,31 +34,44 @@ void test_index_version__can_read_v4(void) void test_index_version__can_write_v4(void) { + const char *paths[] = { + "foo", + "foox", + "foobar", + "foobal", + "x", + "xz", + "xyzzyx" + }; + git_index_entry entry; git_index *index; - const git_index_entry *entry; + size_t i; - g_repo = cl_git_sandbox_init("filemodes"); + g_repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_pass(git_repository_index(&index, g_repo)); - - cl_assert(index->on_disk); - cl_assert(git_index_version(index) == 2); - - cl_assert(git_index_entrycount(index) == 6); - cl_git_pass(git_index_set_version(index, 4)); + for (i = 0; i < ARRAY_SIZE(paths); i++) { + memset(&entry, 0, sizeof(entry)); + entry.path = paths[i]; + entry.mode = GIT_FILEMODE_BLOB; + cl_git_pass(git_index_add_frombuffer(index, &entry, paths[i], + strlen(paths[i]) + 1)); + } + cl_assert_equal_sz(git_index_entrycount(index), ARRAY_SIZE(paths)); + cl_git_pass(git_index_write(index)); git_index_free(index); cl_git_pass(git_repository_index(&index, g_repo)); cl_assert(git_index_version(index) == 4); - entry = git_index_get_bypath(index, "exec_off", 0); - cl_assert(entry); - entry = git_index_get_bypath(index, "exec_off2on_staged", 0); - cl_assert(entry); - entry = git_index_get_bypath(index, "exec_on", 0); - cl_assert(entry); + for (i = 0; i < ARRAY_SIZE(paths); i++) { + const git_index_entry *e; + + cl_assert(e = git_index_get_bypath(index, paths[i], 0)); + cl_assert_equal_s(paths[i], e->path); + } git_index_free(index); } |