Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c086ccb

Browse files
committed
tests: submodule: do not rely on config iteration order
The test submodule::lookup::duplicated_path, which tries to verify that we detect submodules with duplicated paths, currently relies on the gitmodules file of "submod2_target". While this file has two gitmodules with the same path, one of these gitmodules has an empty name and thus does not pass `git_submodule_name_is_valid`. Because of this, the test is in fact dependent on the iteration order in which we process the submodules. In fact the "valid" submodule comes first, the "invalid" submodule will cause the desired error. In fact the "invalid" submodule comes first, it will be skipped due to its name being invalid, and we will not see the desired error. While this works on the master branch just right due to the refactoring of our config code, where iteration order is now deterministic, this breaks on all older maintenance branches. Fix the issue by simply using `cl_git_rewritefile` to rewrite the gitmodules file. This greatly simplifies the test and also makes the intentions of it much clearer.
1 parent 54990d7 commit c086ccb

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

tests/submodule/lookup.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void test_submodule_lookup__foreach(void)
132132
cl_assert_equal_i(8, data.count);
133133
}
134134

135-
static int sm_dummy_cb(git_submodule *sm, const char *name, void *payload)
135+
static int foreach_cb(git_submodule *sm, const char *name, void *payload)
136136
{
137137
GIT_UNUSED(sm);
138138
GIT_UNUSED(name);
@@ -142,20 +142,15 @@ static int sm_dummy_cb(git_submodule *sm, const char *name, void *payload)
142142

143143
void test_submodule_lookup__duplicated_path(void)
144144
{
145-
/*
146-
* Manually invoke cleanup methods to remove leftovers
147-
* from `setup_fixture_submod2`
148-
*/
149-
cl_git_sandbox_cleanup();
150-
cl_fixture_cleanup("submod2_target");
151-
152-
g_repo = setup_fixture_submodules();
153-
154-
/*
155-
* This should fail, as the submodules repo has an
156-
* invalid gitmodules file with duplicated paths.
157-
*/
158-
cl_git_fail(git_submodule_foreach(g_repo, sm_dummy_cb, NULL));
145+
cl_git_rewritefile("submod2/.gitmodules",
146+
"[submodule \"sm1\"]\n"
147+
" path = duplicated-path\n"
148+
" url = sm1\n"
149+
"[submodule \"sm2\"]\n"
150+
" path = duplicated-path\n"
151+
" url = sm2\n");
152+
153+
cl_git_fail(git_submodule_foreach(g_repo, sm_lookup_cb, NULL));
159154
}
160155

161156
void test_submodule_lookup__lookup_even_with_unborn_head(void)
@@ -456,14 +451,6 @@ void test_submodule_lookup__lookup_in_bare_repository_fails(void)
456451
cl_git_fail(git_submodule_lookup(&sm, g_repo, "nonexisting"));
457452
}
458453

459-
static int foreach_cb(git_submodule *sm, const char *name, void *payload)
460-
{
461-
GIT_UNUSED(sm);
462-
GIT_UNUSED(name);
463-
GIT_UNUSED(payload);
464-
return 0;
465-
}
466-
467454
void test_submodule_lookup__foreach_in_bare_repository_fails(void)
468455
{
469456
cl_git_sandbox_cleanup();

0 commit comments

Comments
 (0)