Skip to content

Commit 0e5a27c

Browse files
committed
tests: count config section helper already exists
1 parent f8fc987 commit 0e5a27c

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

tests/remote/create.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "clar_libgit2.h"
2+
#include "config/config_helpers.h"
23

34
static git_repository *_repo;
45
static git_config *_config;
@@ -13,25 +14,6 @@ static git_config *_config;
1314
cl_assert_equal_p(r, NULL); \
1415
} while (0);
1516

16-
static int cl_git_config_section_count__foreach(const git_config_entry *entry, void *payload)
17-
{
18-
size_t *count = payload;
19-
20-
GIT_UNUSED(entry);
21-
(*count)++;
22-
23-
return 0;
24-
}
25-
26-
static size_t cl_git_config_sections_count(git_config *cfg, const char *regex)
27-
{
28-
size_t count = 0;
29-
30-
cl_git_pass(git_config_foreach_match(cfg, regex, cl_git_config_section_count__foreach, &count));
31-
32-
return count;
33-
}
34-
3517
void test_remote_create__initialize(void)
3618
{
3719
cl_fixture_sandbox("testrepo.git");
@@ -70,7 +52,7 @@ void test_remote_create__named(void)
7052
git_config *cfg;
7153
const char *cfg_val;
7254

73-
size_t section_count = cl_git_config_sections_count(_config, "remote.");
55+
size_t section_count = count_config_entries_match(_repo, "remote\\.");
7456

7557
cl_git_pass(git_remote_create(&remote, _repo, "valid-name", TEST_URL));
7658

@@ -86,7 +68,7 @@ void test_remote_create__named(void)
8668
cl_git_pass(git_config_get_string(&cfg_val, cfg, "remote.valid-name.url"));
8769
cl_assert_equal_s(cfg_val, TEST_URL);
8870

89-
cl_assert_equal_i(section_count + 2, cl_git_config_sections_count(_config, "remote."));
71+
cl_assert_equal_i(section_count + 2, count_config_entries_match(_repo, "remote\\."));
9072

9173
git_config_free(cfg);
9274
git_remote_free(remote);
@@ -117,7 +99,7 @@ void test_remote_create__with_fetchspec(void)
11799
{
118100
git_remote *remote;
119101
git_strarray array;
120-
size_t section_count = cl_git_config_sections_count(_config, "remote.");
102+
size_t section_count = count_config_entries_match(_repo, "remote\\.");
121103

122104
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
123105
cl_assert_equal_s(git_remote_name(remote), "test-new");
@@ -127,7 +109,7 @@ void test_remote_create__with_fetchspec(void)
127109
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
128110
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
129111
cl_assert_equal_i(1, array.count);
130-
cl_assert_equal_i(section_count + 2, cl_git_config_sections_count(_config, "remote."));
112+
cl_assert_equal_i(section_count + 2, count_config_entries_match(_repo, "remote\\."));
131113

132114
git_strarray_free(&array);
133115
git_remote_free(remote);
@@ -137,12 +119,12 @@ void test_remote_create__with_empty_fetchspec(void)
137119
{
138120
git_remote *remote;
139121
git_strarray array;
140-
size_t section_count = cl_git_config_sections_count(_config, "remote.");
122+
size_t section_count = count_config_entries_match(_repo, "remote\\.");
141123

142124
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", NULL));
143125
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
144126
cl_assert_equal_i(0, array.count);
145-
cl_assert_equal_i(section_count + 1, cl_git_config_sections_count(_config, "remote."));
127+
cl_assert_equal_i(section_count + 1, count_config_entries_match(_repo, "remote\\."));
146128

147129
git_strarray_free(&array);
148130
git_remote_free(remote);
@@ -162,7 +144,7 @@ void test_remote_create__anonymous(void)
162144
{
163145
git_remote *remote;
164146
git_strarray array;
165-
size_t section_count = cl_git_config_sections_count(_config, "remote.");
147+
size_t section_count = count_config_entries_match(_repo, "remote\\.");
166148

167149
cl_git_pass(git_remote_create_anonymous(&remote, _repo, TEST_URL));
168150
cl_assert_equal_s(git_remote_name(remote), NULL);
@@ -171,7 +153,7 @@ void test_remote_create__anonymous(void)
171153

172154
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
173155
cl_assert_equal_i(0, array.count);
174-
cl_assert_equal_i(section_count, cl_git_config_sections_count(_config, "remote."));
156+
cl_assert_equal_i(section_count, count_config_entries_match(_repo, "remote\\."));
175157

176158
git_strarray_free(&array);
177159
git_remote_free(remote);
@@ -186,7 +168,8 @@ void test_remote_create__detached(void)
186168
{
187169
git_remote *remote;
188170
git_strarray array;
189-
size_t section_count = cl_git_config_sections_count(_config, "remote.");
171+
172+
size_t section_count = count_config_entries_match(_repo, "remote\\.");
190173

191174
cl_git_pass(git_remote_create_detached(&remote, TEST_URL));
192175
cl_assert_equal_s(git_remote_name(remote), NULL);
@@ -195,7 +178,7 @@ void test_remote_create__detached(void)
195178

196179
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
197180
cl_assert_equal_i(0, array.count);
198-
cl_assert_equal_i(section_count, cl_git_config_sections_count(_config, "remote."));
181+
cl_assert_equal_i(section_count, count_config_entries_match(_repo, "remote\\."));
199182

200183
git_strarray_free(&array);
201184
git_remote_free(remote);

0 commit comments

Comments
 (0)