From 41cb57e9cd1d88e52d27ca61ad3400a749eeacb3 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 10 Sep 2015 16:35:06 -0700 Subject: [PATCH 1/4] 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(); +} -- 2.41.0 From b88808f708fd7dcf87c7ed48af62e1b58dff2988 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 10 Sep 2015 16:36:07 -0700 Subject: [PATCH 2/4] Test escaped space in a library name --- tests/lib1/quotes.pc | 2 +- tests/run.sh.in | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/lib1/quotes.pc b/tests/lib1/quotes.pc index bb1282f..b834816 100644 --- a/tests/lib1/quotes.pc +++ b/tests/lib1/quotes.pc @@ -6,5 +6,5 @@ includedir=${prefix}/include Name: quotes Description: A testing pkg-config file Version: 1.2.3 -Libs: -L${libdir} -lfoo +Libs: -L${libdir} -lfoo\ bar Cflags: -DQUOTED=\"bla\" diff --git a/tests/run.sh.in b/tests/run.sh.in index c971513..411f4c7 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -220,6 +220,8 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --list-all | grep -q 'multiline # test quoted #35 run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --cflags quotes" \ "-DQUOTED=\\\"bla\\\"" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs quotes" \ + '-lfoo\ bar' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs nolib; echo \$?" \ '0' -- 2.41.0 From d0bbc686bfa70e7f9eb84123902bddf1b3e22025 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Thu, 10 Sep 2015 16:49:52 -0700 Subject: [PATCH 3/4] Add tests for libraries quoted with double quotes, make them pass --- libpkgconf/argvsplit.c | 5 ++++- libpkgconf/tests/argvsplit-test.c | 12 ++++++++++++ tests/lib1/framework-3.pc | 9 +++++++++ tests/lib1/quotes.pc | 2 +- tests/run.sh.in | 4 +++- 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/lib1/framework-3.pc diff --git a/libpkgconf/argvsplit.c b/libpkgconf/argvsplit.c index d3ef07b..55c1b5a 100644 --- a/libpkgconf/argvsplit.c +++ b/libpkgconf/argvsplit.c @@ -42,8 +42,10 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv) while (*src_iter) { - if (quote == *src_iter) + if (quote == *src_iter) { quote = 0; + *dst_iter++ = *src_iter; + } else if (quote) { if (*src_iter == '\\') @@ -81,6 +83,7 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv) case '"': case '\'': quote = *src_iter; + *dst_iter++ = *src_iter; break; case '\\': diff --git a/libpkgconf/tests/argvsplit-test.c b/libpkgconf/tests/argvsplit-test.c index 81ab12c..7a23c29 100644 --- a/libpkgconf/tests/argvsplit-test.c +++ b/libpkgconf/tests/argvsplit-test.c @@ -26,9 +26,21 @@ void test_escaped() pkgconf_argv_free(argv); } +void test_quoted() +{ + 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(); + test_quoted(); } diff --git a/tests/lib1/framework-3.pc b/tests/lib1/framework-3.pc new file mode 100644 index 0000000..c221fee --- /dev/null +++ b/tests/lib1/framework-3.pc @@ -0,0 +1,9 @@ +prefix=/test +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: framework-3 +Description: pkg-config with space in framework name +Version: 1.3 +Libs: -F${libdir} -framework "Spacey Framework" diff --git a/tests/lib1/quotes.pc b/tests/lib1/quotes.pc index b834816..319d108 100644 --- a/tests/lib1/quotes.pc +++ b/tests/lib1/quotes.pc @@ -6,5 +6,5 @@ includedir=${prefix}/include Name: quotes Description: A testing pkg-config file Version: 1.2.3 -Libs: -L${libdir} -lfoo\ bar +Libs: -L${libdir} -lfoo\ bar "-lfoobie bletch" Cflags: -DQUOTED=\"bla\" diff --git a/tests/run.sh.in b/tests/run.sh.in index 411f4c7..d84c808 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -221,7 +221,7 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --list-all | grep -q 'multiline run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --cflags quotes" \ "-DQUOTED=\\\"bla\\\"" run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs quotes" \ - '-lfoo\ bar' + '-lfoo\ bar "-lfoobie bletch"' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs nolib; echo \$?" \ '0' @@ -241,6 +241,8 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs framework-2" \ "-F/test/lib -framework framework-2 -framework framework-1" run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs framework-1 framework-2" \ "-F/test/lib -framework framework-1 -framework framework-2" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs framework-3" \ + '-F/test/lib -framework "Spacey Framework"' run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --exists --print-errors 'foo > 0.6.0 foo < 0.8.0'; echo \$?" \ '1' -- 2.41.0 From 001cd31c089842ca744d2883ac99225537d0adab Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Fri, 11 Sep 2015 09:01:44 -0700 Subject: [PATCH 4/4] Now passes 'make distcheck', too --- Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.am b/Makefile.am index bed3f3d..dc6049d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST = \ tests/lib1/prefix-foo2.pc \ tests/lib1/bar.pc \ tests/lib1/framework-2.pc \ + tests/lib1/framework-3.pc \ tests/lib1/private-libs-duplication.pc \ tests/lib1/baz.pc \ tests/lib1/incomplete.pc \ @@ -76,6 +77,8 @@ EXTRA_PROGRAMS = unit_tests unit_tests_SOURCES = libpkgconf/tests/argvsplit-test.c unit_tests_LDADD = libpkgconf.la +CLEANFILES = $(EXTRA_PROGRAMS) + check: pkgconf unit_tests ./unit_tests $(SHELL) tests/run.sh ./pkgconf -- 2.41.0