diff options
author | Russell Belfer <rb@github.com> | 2014-04-01 13:24:06 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-04-01 13:24:06 -0700 |
commit | 8061d519b33c95a8858752e7d70d40fe8bae90f9 (patch) | |
tree | 7e004e8e4cd1a6d337ec0d7614bb638389fdd7ab /tests | |
parent | 4ece3e225b566816598238902667552dee4c7deb (diff) | |
download | libgit2-8061d519b33c95a8858752e7d70d40fe8bae90f9.tar.gz |
Remove most submodule reloads from tests
With the new submodule cache validity checks, we generally don't
need to call git_submodule_reload_all to have up-to-date submodule
data. Some tests are still calling it where I want to actually
test that it can be called safely and doesn't break anything, but
mostly it is not needed.
This also expands some of the existing submodule tests to cover
some variants on the behavior that was already being tested.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/diff/submodules.c | 5 | ||||
-rw-r--r-- | tests/submodule/lookup.c | 66 | ||||
-rw-r--r-- | tests/submodule/nosubs.c | 18 |
3 files changed, 55 insertions, 34 deletions
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c index 2881f74be..02870ac86 100644 --- a/tests/diff/submodules.c +++ b/tests/diff/submodules.c @@ -131,8 +131,6 @@ void test_diff_submodules__dirty_submodule_2(void) g_repo = setup_fixture_submodules(); - cl_git_pass(git_submodule_reload_all(g_repo, 1)); - opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_SHOW_UNTRACKED_CONTENT | GIT_DIFF_RECURSE_UNTRACKED_DIRS | @@ -165,8 +163,6 @@ void test_diff_submodules__dirty_submodule_2(void) git_diff_free(diff); - cl_git_pass(git_submodule_reload_all(g_repo, 1)); - cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_dirty); git_diff_free(diff); @@ -299,7 +295,6 @@ void test_diff_submodules__invalid_cache(void) git_submodule_free(sm); - cl_git_pass(git_submodule_reload_all(g_repo, 1)); cl_git_pass(git_submodule_lookup(&sm, g_repo, smpath)); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c index 36bde4f6e..86ba25c3a 100644 --- a/tests/submodule/lookup.c +++ b/tests/submodule/lookup.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" #include "submodule_helpers.h" -#include "posix.h" #include "git2/sys/repository.h" +#include "fileops.h" static git_repository *g_repo = NULL; @@ -115,13 +115,7 @@ void test_submodule_lookup__lookup_even_with_unborn_head(void) &head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL, NULL)); git_reference_free(head); - assert_submodule_exists(g_repo, "sm_unchanged"); - assert_submodule_exists(g_repo, "sm_added_and_uncommited"); - assert_submodule_exists(g_repo, "sm_gitmodules_only"); - refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); - refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND); + test_submodule_lookup__simple_lookup(); /* baseline should still pass */ } void test_submodule_lookup__lookup_even_with_missing_index(void) @@ -133,44 +127,62 @@ void test_submodule_lookup__lookup_even_with_missing_index(void) git_repository_set_index(g_repo, idx); git_index_free(idx); - assert_submodule_exists(g_repo, "sm_unchanged"); - assert_submodule_exists(g_repo, "sm_added_and_uncommited"); - assert_submodule_exists(g_repo, "sm_gitmodules_only"); - refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); - refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND); + test_submodule_lookup__simple_lookup(); /* baseline should still pass */ } void test_submodule_lookup__just_added(void) { git_submodule *sm; + git_buf snap1 = GIT_BUF_INIT, snap2 = GIT_BUF_INIT; + + refute_submodule_exists(g_repo, "sm_just_added", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "sm_just_added_2", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND); + test_submodule_lookup__simple_lookup(); /* baseline */ - cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "sm_just_added", 1)); + cl_git_pass(git_futils_readbuffer(&snap1, "submod2/.gitmodules")); + + cl_git_pass(git_submodule_add_setup(&sm, g_repo, + "https://github.com/libgit2/libgit2.git", "sm_just_added", 1)); git_submodule_free(sm); assert_submodule_exists(g_repo, "sm_just_added"); - cl_git_pass(git_submodule_add_setup(&sm, g_repo, "https://github.com/libgit2/libgit2.git", "sm_just_added_2", 1)); + cl_git_pass(git_submodule_add_setup(&sm, g_repo, + "https://github.com/libgit2/libgit2.git", "sm_just_added_2", 1)); assert_submodule_exists(g_repo, "sm_just_added_2"); git_submodule_free(sm); - cl_git_append2file("submod2/.gitmodules", "\n[submodule \"mismatch_name\"]\n\tpath = mismatch_path\n\turl = https://example.com/example.git\n\n"); + cl_git_pass(git_futils_readbuffer(&snap2, "submod2/.gitmodules")); - cl_git_pass(git_submodule_reload_all(g_repo, 1)); + cl_git_append2file( + "submod2/.gitmodules", + "\n[submodule \"mismatch_name\"]\n" + "\tpath = mismatch_path\n" + "\turl = https://example.com/example.git\n\n"); assert_submodule_exists(g_repo, "mismatch_name"); assert_submodule_exists(g_repo, "mismatch_path"); + assert_submodule_exists(g_repo, "sm_just_added"); + assert_submodule_exists(g_repo, "sm_just_added_2"); + test_submodule_lookup__simple_lookup(); + + cl_git_rewritefile("submod2/.gitmodules", snap2.ptr); + git_buf_free(&snap2); + refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND); assert_submodule_exists(g_repo, "sm_just_added"); assert_submodule_exists(g_repo, "sm_just_added_2"); + test_submodule_lookup__simple_lookup(); - /* all the regular ones should still be working right, too */ + cl_git_rewritefile("submod2/.gitmodules", snap1.ptr); + git_buf_free(&snap1); - assert_submodule_exists(g_repo, "sm_unchanged"); - assert_submodule_exists(g_repo, "sm_added_and_uncommited"); - assert_submodule_exists(g_repo, "sm_gitmodules_only"); - refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); - refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "just_a_file", GIT_ENOTFOUND); - refute_submodule_exists(g_repo, "no_such_file", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "mismatch_name", GIT_ENOTFOUND); + refute_submodule_exists(g_repo, "mismatch_path", GIT_ENOTFOUND); + /* note error code change, because add_setup made a repo in the workdir */ + refute_submodule_exists(g_repo, "sm_just_added", GIT_EEXISTS); + refute_submodule_exists(g_repo, "sm_just_added_2", GIT_EEXISTS); + test_submodule_lookup__simple_lookup(); } diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c index cabb53ead..e343c1620 100644 --- a/tests/submodule/nosubs.c +++ b/tests/submodule/nosubs.c @@ -69,7 +69,10 @@ void test_submodule_nosubs__reload_add_reload(void) cl_git_pass(git_submodule_reload_all(repo, 0)); - cl_git_pass(git_submodule_add_setup(&sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); + /* try one add with a reload (to make sure no errors happen) */ + + cl_git_pass(git_submodule_add_setup(&sm, repo, + "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); cl_git_pass(git_submodule_reload_all(repo, 0)); @@ -79,6 +82,17 @@ void test_submodule_nosubs__reload_add_reload(void) cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); git_submodule_free(sm); + + /* try one add without a reload (to make sure cache inval works, too) */ + + cl_git_pass(git_submodule_add_setup(&sm, repo, + "https://github.com/libgit2/libgit2.git", "libgit2-again", 1)); + cl_assert_equal_s("libgit2-again", git_submodule_name(sm)); + git_submodule_free(sm); + + cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2-again")); + cl_assert_equal_s("libgit2-again", git_submodule_name(sm)); + git_submodule_free(sm); } void test_submodule_nosubs__bad_gitmodules(void) @@ -101,7 +115,7 @@ void test_submodule_nosubs__add_and_delete(void) git_submodule *sm; git_buf buf = GIT_BUF_INIT; - /* note the lack of calls to git_submodule_reload - this *should* work */ + /* note lack of calls to git_submodule_reload_all - this *should* work */ cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2")); cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2")); |