threads / patch / 25015

v2Add test-string-list.c

Subject: [Patch v2] Add test-string-list.c

## tl;dr

2 messages between Sep 6, 2010 and Sep 7, 2010. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

Thiago Farina· Sep 6, 2010, 23:43 UTC · lore

Add a simple test that demonstrates how to create and manipulate a list of strings using the string-list.h API.

To see the test, call it by: ./bin-wrappers/test-string-list.c

Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
 Makefile           |    1 +
 test-string-list.c |   27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)
 create mode 100644 test-string-list.c
Show changes to 2 files +28 −0

Makefile, test-string-list.c

diff --git a/Makefile b/Makefile
index 40fbcae..287bc2c 100644
--- a/Makefile
+++ b/Makefile
@@ -422,6 +422,7 @@ TEST_PROGRAMS_NEED_X += test-string-pool
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-treap
 TEST_PROGRAMS_NEED_X += test-index-version
+TEST_PROGRAMS_NEED_X += test-string-list
 
 TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
 
diff --git a/test-string-list.c b/test-string-list.c
new file mode 100644
index 0000000..267db4c
--- /dev/null
+++ b/test-string-list.c
@@ -0,0 +1,27 @@
+#include "git-compat-util.h"
+#include "string-list.h"
+
+int main(int argc, const char **argv)
+{
+	struct string_list list = STRING_LIST_INIT_NODUP;
+	int i;
+	int has_foo;
+
+	string_list_append(&list, "foo");
+	string_list_append(&list, "bar");
+
+	for (i = 0; i < list.nr; i++)
+		printf("%s\n", list.items[i].string);
+
+	print_string_list(&list, "");
+
+	has_foo = string_list_has_string(&list, "foo");
+	if (has_foo != 1)
+		return error("List doesn't have foo.");
+
+	string_list_clear(&list, 0);
+	if (list.nr > 0)
+		return error("List is not clear.");
+
+	return 0;
+}
-- 
1.7.2.3.313.gcd15
Junio C Hamano· Sep 7, 2010, 00:15 UTC · re: Thiago Farina · lore

Re: [Patch v2] Add test-string-list.c

We have many invocations of string_list_* functions in the code that are already run with our test suite, and breakage to string_list functions would very likely break them. This patch adds yet another and a lot simpler caller that is not used from anywhere.

Sorry, but I simply do not see the point.

As I already said in a previous message, your program, because it is so short and simple, may be a lot easier example for people who are learning git API than any of the real existing programs. It might be a good public service to give it a wider exposure by having it somewhere in my tree than burying it in your blog ;-), but then I think a better place to do so would be in Documentation/technical/api-*.txt and not in "test program" that is not used by anything.

Or are you planning to change the implementation of string_list so drastically real soon now that you need a specific test that only checks the API? If that is the case, I am Ok with treating it just like test-date which tries to test the approxidate API in isolation, but then you would need to connect test-string-list to a t/tNNNN-XXXX.sh script in the test suite.

But for that purpose, you are not exercising the API to any meaningful depth yet. It uses the unordered append interface to add only two elements, does a single look up, and clear. It may be a good start, but it isn't yet something I would want to be CC'ed for application.

Thanks.

← back to recent threads