Skip to content

Commit 641cbf0

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 4421ed8 commit 641cbf0

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
@@ -169,3 +169,65 @@ void test_string_list__filter(void)
169169

170170
t_string_list_clear(&list, 0);
171171
}
172+
173+
static void t_string_list_remove_duplicates(struct string_list *list, ...)
174+
{
175+
struct string_list expected_strings = STRING_LIST_INIT_DUP;
176+
va_list ap;
177+
178+
va_start(ap, list);
179+
t_vcreate_string_list_dup(&expected_strings, 0, ap);
180+
va_end(ap);
181+
182+
string_list_remove_duplicates(list, 0);
183+
t_string_list_equal(list, &expected_strings);
184+
185+
string_list_clear(&expected_strings, 0);
186+
}
187+
188+
void test_string_list__remove_duplicates(void)
189+
{
190+
struct string_list list = STRING_LIST_INIT_DUP;
191+
192+
t_create_string_list_dup(&list, 0, NULL);
193+
t_string_list_remove_duplicates(&list, NULL);
194+
195+
t_create_string_list_dup(&list, 0, "", NULL);
196+
t_string_list_remove_duplicates(&list, "", NULL);
197+
198+
t_create_string_list_dup(&list, 0, "a", NULL);
199+
t_string_list_remove_duplicates(&list, "a", NULL);
200+
201+
t_create_string_list_dup(&list, 0, "a", "a", NULL);
202+
t_string_list_remove_duplicates(&list, "a", NULL);
203+
204+
t_create_string_list_dup(&list, 0, "a", "a", "a", NULL);
205+
t_string_list_remove_duplicates(&list, "a", NULL);
206+
207+
t_create_string_list_dup(&list, 0, "a", "a", "b", NULL);
208+
t_string_list_remove_duplicates(&list, "a", "b", NULL);
209+
210+
t_create_string_list_dup(&list, 0, "a", "b", "b", NULL);
211+
t_string_list_remove_duplicates(&list, "a", "b", NULL);
212+
213+
t_create_string_list_dup(&list, 0, "a", "b", "c", NULL);
214+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
215+
216+
t_create_string_list_dup(&list, 0, "a", "a", "b", "c", NULL);
217+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
218+
219+
t_create_string_list_dup(&list, 0, "a", "b", "b", "c", NULL);
220+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
221+
222+
t_create_string_list_dup(&list, 0, "a", "b", "c", "c", NULL);
223+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
224+
225+
t_create_string_list_dup(&list, 0, "a", "a", "b", "b", "c", "c", NULL);
226+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
227+
228+
t_create_string_list_dup(&list, 0, "a", "a", "a", "b", "b", "b",
229+
"c", "c", "c", NULL);
230+
t_string_list_remove_duplicates(&list, "a", "b", "c", NULL);
231+
232+
t_string_list_clear(&list, 0);
233+
}

0 commit comments

Comments
 (0)