From 41cb57e9cd1d88e52d27ca61ad3400a749eeacb3 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 10 Sep 2015 16:35:06 -0700 Subject: [PATCH] Add unit test for argvsplit --- Makefile.am | 7 ++++++- libpkgconf/tests/argvsplit-test.c | 34 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 libpkgconf/tests/argvsplit-test.c diff --git a/Makefile.am b/Makefile.am index 35c1ad7..bed3f3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -72,5 +72,10 @@ noinst_HEADERS = getopt_long.h dist_doc_DATA = README.md AUTHORS -check: pkgconf +EXTRA_PROGRAMS = unit_tests +unit_tests_SOURCES = libpkgconf/tests/argvsplit-test.c +unit_tests_LDADD = libpkgconf.la + +check: pkgconf unit_tests + ./unit_tests $(SHELL) tests/run.sh ./pkgconf diff --git a/libpkgconf/tests/argvsplit-test.c b/libpkgconf/tests/argvsplit-test.c new file mode 100644 index 0000000..81ab12c --- /dev/null +++ b/libpkgconf/tests/argvsplit-test.c @@ -0,0 +1,34 @@ +#include +#include + +#include "../libpkgconf.h" + +void test_simple() +{ + int argc; + char **argv; + + pkgconf_argv_split("A B", &argc, &argv); + assert(argc == 2); + assert(!strcmp(argv[0], "A")); + assert(!strcmp(argv[1], "B")); + pkgconf_argv_free(argv); +} + +void test_escaped() +{ + int argc; + char **argv; + + pkgconf_argv_split("A\\ B", &argc, &argv); + assert(argc == 1); + assert(!strcmp(argv[0], "A\\ B")); + pkgconf_argv_free(argv); +} + +int main(int argc, char **argv) +{ + (void) argc; (void) argv; + test_simple(); + test_escaped(); +}