{"thread":{"id":"25015","subject":"[Patch v2] Add test-string-list.c","startedAt":"2010-09-06T23:43:23Z","lastAt":"2010-09-07T00:15:06Z","messageCount":2,"participants":["Thiago Farina","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"150153","messageId":"1283816603-12156-1-git-send-email-tfransosi@gmail.com","threadId":"25015","inReplyTo":null,"subject":"[Patch v2] Add test-string-list.c","fromName":"Thiago Farina","fromEmail":"tfransosi@gmail.com","sentAt":"2010-09-06T23:43:23Z","receivedAt":"2010-09-06T23:43:23Z","isPatch":true,"sender":{"key":"tfransosi@gmail.com","avatar":"https://avatars.githubusercontent.com/u/970071?v=4"},"body":"Add a simple test that demonstrates how to create and manipulate\na list of strings using the string-list.h API.\n\nTo see the test, call it by:\n./bin-wrappers/test-string-list.c\n\nSigned-off-by: Thiago Farina <tfransosi@gmail.com>\n---\n Makefile           |    1 +\n test-string-list.c |   27 +++++++++++++++++++++++++++\n 2 files changed, 28 insertions(+), 0 deletions(-)\n create mode 100644 test-string-list.c\n\ndiff --git a/Makefile b/Makefile\nindex 40fbcae..287bc2c 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -422,6 +422,7 @@ TEST_PROGRAMS_NEED_X += test-string-pool\n TEST_PROGRAMS_NEED_X += test-svn-fe\n TEST_PROGRAMS_NEED_X += test-treap\n TEST_PROGRAMS_NEED_X += test-index-version\n+TEST_PROGRAMS_NEED_X += test-string-list\n \n TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))\n \ndiff --git a/test-string-list.c b/test-string-list.c\nnew file mode 100644\nindex 0000000..267db4c\n--- /dev/null\n+++ b/test-string-list.c\n@@ -0,0 +1,27 @@\n+#include \"git-compat-util.h\"\n+#include \"string-list.h\"\n+\n+int main(int argc, const char **argv)\n+{\n+\tstruct string_list list = STRING_LIST_INIT_NODUP;\n+\tint i;\n+\tint has_foo;\n+\n+\tstring_list_append(&list, \"foo\");\n+\tstring_list_append(&list, \"bar\");\n+\n+\tfor (i = 0; i < list.nr; i++)\n+\t\tprintf(\"%s\\n\", list.items[i].string);\n+\n+\tprint_string_list(&list, \"\");\n+\n+\thas_foo = string_list_has_string(&list, \"foo\");\n+\tif (has_foo != 1)\n+\t\treturn error(\"List doesn't have foo.\");\n+\n+\tstring_list_clear(&list, 0);\n+\tif (list.nr > 0)\n+\t\treturn error(\"List is not clear.\");\n+\n+\treturn 0;\n+}\n-- \n1.7.2.3.313.gcd15\n"},{"id":"150161","messageId":"7viq2is92t.fsf@alter.siamese.dyndns.org","threadId":"25015","inReplyTo":"1283816603-12156-1-git-send-email-tfransosi@gmail.com","subject":"Re: [Patch v2] Add test-string-list.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-09-07T00:15:06Z","receivedAt":"2010-09-07T00:15:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We have many invocations of string_list_* functions in the code that are\nalready run with our test suite, and breakage to string_list functions\nwould very likely break them.  This patch adds yet another and a lot\nsimpler caller that is not used from anywhere.\n\nSorry, but I simply do not see the point.\n\nAs I already said in a previous message, your program, because it is so\nshort and simple, may be a lot easier example for people who are learning\ngit API than any of the real existing programs.  It might be a good public\nservice to give it a wider exposure by having it somewhere in my tree than\nburying it in your blog ;-), but then I think a better place to do so\nwould be in Documentation/technical/api-*.txt and not in \"test program\"\nthat is not used by anything.\n\nOr are you planning to change the implementation of string_list so\ndrastically real soon now that you need a specific test that only checks\nthe API?  If that is the case, I am Ok with treating it just like test-date\nwhich tries to test the approxidate API in isolation, but then you would\nneed to connect test-string-list to a t/tNNNN-XXXX.sh script in the test\nsuite.\n\nBut for that purpose, you are not exercising the API to any meaningful\ndepth yet.  It uses the unordered append interface to add only two\nelements, does a single look up, and clear.  It may be a good start, but\nit isn't yet something I would want to be CC'ed for application.\n\nThanks.\n"}]}