Skip to content

Commit 608f013

Browse files
shejialuogitster
authored andcommitted
u-string-list: move "remove duplicates" test to "u-string-list.c"
We use "test-tool string-list remove_duplicates" to test the "string_list_remove_duplicates" function. As we have introduced the unit test, we'd better remove the logic from shell script to C program to improve test speed and readability. As all the tests in shell script are removed, let's just delete the "t0063-string-list.sh" and update the "meson.build" file to align with this change. Also we could simply remove "DISABLE_SIGN_COMPARE_WARNINGS" due to we have already deleted related code. Signed-off-by: shejialuo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85aabec commit 608f013

File tree

4 files changed

+62
-67
lines changed

4 files changed

+62
-67
lines changed

t/helper/test-string-list.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,9 @@
1-
#define DISABLE_SIGN_COMPARE_WARNINGS
2-
31
#include "test-tool.h"
42
#include "strbuf.h"
53
#include "string-list.h"
64

7-
/*
8-
* Parse an argument into a string list. arg should either be a
9-
* ':'-separated list of strings, or "-" to indicate an empty string
10-
* list (as opposed to "", which indicates a string list containing a
11-
* single empty string). list->strdup_strings must be set.
12-
*/
13-
static void parse_string_list(struct string_list *list, const char *arg)
14-
{
15-
if (!strcmp(arg, "-"))
16-
return;
17-
18-
(void)string_list_split(list, arg, ':', -1);
19-
}
20-
21-
static void write_list_compact(const struct string_list *list)
22-
{
23-
int i;
24-
if (!list->nr)
25-
printf("-\n");
26-
else {
27-
printf("%s", list->items[0].string);
28-
for (i = 1; i < list->nr; i++)
29-
printf(":%s", list->items[i].string);
30-
printf("\n");
31-
}
32-
}
33-
345
int cmd__string_list(int argc, const char **argv)
356
{
36-
if (argc == 3 && !strcmp(argv[1], "remove_duplicates")) {
37-
struct string_list list = STRING_LIST_INIT_DUP;
38-
39-
parse_string_list(&list, argv[2]);
40-
string_list_remove_duplicates(&list, 0);
41-
write_list_compact(&list);
42-
string_list_clear(&list, 0);
43-
return 0;
44-
}
45-
467
if (argc == 2 && !strcmp(argv[1], "sort")) {
478
struct string_list list = STRING_LIST_INIT_NODUP;
489
struct strbuf sb = STRBUF_INIT;

t/meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ integration_tests = [
124124
't0060-path-utils.sh',
125125
't0061-run-command.sh',
126126
't0062-revision-walking.sh',
127-
't0063-string-list.sh',
128127
't0066-dir-iterator.sh',
129128
't0067-parse_pathspec_file.sh',
130129
't0068-for-each-repo.sh',

t/t0063-string-list.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

t/unit-tests/u-string-list.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,65 @@ void test_string_list__filter(void)
174174
t_string_list_clear(&list, 0);
175175
t_string_list_clear(&expected_strings, 0);
176176
}
177+
178+
static void t_string_list_remove_duplicates(struct string_list *list,
179+
struct string_list *expected_strings)
180+
{
181+
string_list_remove_duplicates(list, 0);
182+
t_check_string_list(list, expected_strings);
183+
}
184+
185+
void test_string_list__remove_duplicates(void)
186+
{
187+
struct string_list expected_strings = STRING_LIST_INIT_DUP;
188+
struct string_list list = STRING_LIST_INIT_DUP;
189+
190+
t_string_list_remove_duplicates(&list, &expected_strings);
191+
192+
t_create_string_list_dup(&list, 0, "", NULL);
193+
t_create_string_list_dup(&expected_strings, 0, "", NULL);
194+
t_string_list_remove_duplicates(&list, &expected_strings);
195+
196+
t_create_string_list_dup(&expected_strings, 0, "a", NULL);
197+
198+
t_create_string_list_dup(&list, 0, "a", NULL);
199+
t_string_list_remove_duplicates(&list, &expected_strings);
200+
201+
t_create_string_list_dup(&list, 0, "a", "a", NULL);
202+
t_string_list_remove_duplicates(&list, &expected_strings);
203+
204+
t_create_string_list_dup(&list, 0, "a", "a", "a", NULL);
205+
t_string_list_remove_duplicates(&list, &expected_strings);
206+
207+
t_create_string_list_dup(&expected_strings, 0, "a", "b", NULL);
208+
209+
t_create_string_list_dup(&list, 0, "a", "a", "b", NULL);
210+
t_string_list_remove_duplicates(&list, &expected_strings);
211+
212+
t_create_string_list_dup(&list, 0, "a", "b", "b", NULL);
213+
t_string_list_remove_duplicates(&list, &expected_strings);
214+
215+
t_create_string_list_dup(&expected_strings, 0, "a", "b", "c", NULL);
216+
217+
t_create_string_list_dup(&list, 0, "a", "b", "c", NULL);
218+
t_string_list_remove_duplicates(&list, &expected_strings);
219+
220+
t_create_string_list_dup(&list, 0, "a", "a", "b", "c", NULL);
221+
t_string_list_remove_duplicates(&list, &expected_strings);
222+
223+
t_create_string_list_dup(&list, 0, "a", "b", "b", "c", NULL);
224+
t_string_list_remove_duplicates(&list, &expected_strings);
225+
226+
t_create_string_list_dup(&list, 0, "a", "b", "c", "c", NULL);
227+
t_string_list_remove_duplicates(&list, &expected_strings);
228+
229+
t_create_string_list_dup(&list, 0, "a", "a", "b", "b", "c", "c", NULL);
230+
t_string_list_remove_duplicates(&list, &expected_strings);
231+
232+
t_create_string_list_dup(&list, 0, "a", "a", "a", "b", "b", "b",
233+
"c", "c", "c", NULL);
234+
t_string_list_remove_duplicates(&list, &expected_strings);
235+
236+
t_string_list_clear(&list, 0);
237+
t_string_list_clear(&expected_strings, 0);
238+
}

0 commit comments

Comments
 (0)