From a4ceb68409bf0dc4ebed944c8e2bbe047c001762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 3 May 2012 09:22:08 +0200 Subject: [PATCH 1/4] File lookup: fix uninitialized 'iter'. --- pkg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg.c b/pkg.c index 3015523..e70343d 100644 --- a/pkg.c +++ b/pkg.c @@ -63,7 +63,7 @@ pkg_find(const char *name, unsigned int flags) { char locbuf[PKG_CONFIG_PATH_SZ]; char **path; - size_t count, iter; + size_t count, iter = 0; const char *env_path; FILE *f; -- 2.41.0 From 97b8c093651f7798a222cf62838dd242150200fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 3 May 2012 08:50:57 +0200 Subject: [PATCH 2/4] Add minimal tests. --- Makefile | 3 +++ tests/lib1/foo.pc | 10 +++++++++ tests/run.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 tests/lib1/foo.pc create mode 100644 tests/run.sh diff --git a/Makefile b/Makefile index e1d4905..857fbda 100644 --- a/Makefile +++ b/Makefile @@ -9,4 +9,7 @@ install-extra: mkdir -p $(DESTDIR)/$(datarootdir)/aclocal install -c -m644 pkg.m4 $(DESTDIR)/$(datarootdir)/aclocal/pkg.m4 +check: $(PROG) + $(SHELL) tests/run.sh ./$(PROG) + include .deps diff --git a/tests/lib1/foo.pc b/tests/lib1/foo.pc new file mode 100644 index 0000000..5974fbe --- /dev/null +++ b/tests/lib1/foo.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: foo +Description: A testing pkg-config file +Version: 1.2.3 +Libs: -L${libdir} -lfoo +Cflags: -fPIC -I${includedir}/foo diff --git a/tests/run.sh b/tests/run.sh new file mode 100644 index 0000000..15f5c53 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Tests for pkg-config compliance. +# * Copyright (c) 2012 Michał Górny . + +done=0 +failed=0 + +run_test() { + local res t_ret 2>/dev/null || true + + echo "$ ${1}" + eval res="\$(${1})" + echo "${res}" + + t_ret=0 + while [ ${#} -gt 1 ]; do + shift + + case "${res}" in + *${1}*) + ;; + *) + echo "! expected ${1}" + t_ret=1 + ;; + esac + done + + if [ ${t_ret} -eq 0 ]; then + echo "+ [OK]" + else + failed=$(( failed + 1 )) + fi + done=$(( done + 1 )) + + echo +} + +selfdir=$(cd "$(dirname "${0}")"; pwd) + +# 1) overall 'is it working?' test +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs foo" \ + '-lfoo' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags --libs foo" \ + '-lfoo' '-I/usr/include/foo' '-fPIC' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo > 1.2'; echo \$?" \ + '0' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo > 1.2.3'; echo \$?" \ + '1' + +if [ ${failed} -gt 0 ]; then + echo "${failed} of ${done} tests failed. See output for details." >&2 + exit 1 +else + echo "${done} tests done. All succeeded." >&2 + exit 0 +fi -- 2.41.0 From 482b65f1ceaee5be70b205e3867d577ad11700f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 3 May 2012 09:04:48 +0200 Subject: [PATCH 3/4] Tests for PKG_CONFIG_PATH ordering. --- tests/lib2/foo.pc | 10 ++++++++++ tests/run.sh | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/lib2/foo.pc diff --git a/tests/lib2/foo.pc b/tests/lib2/foo.pc new file mode 100644 index 0000000..6491a43 --- /dev/null +++ b/tests/lib2/foo.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: foo +Description: A testing pkg-config file +Version: 1.2.3 +Libs: -L${libdir} -lbar +Cflags: -fPIC -I${includedir}/bar diff --git a/tests/run.sh b/tests/run.sh index 15f5c53..1501b81 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -48,6 +48,12 @@ run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo > 1.2'; echo \$?" \ run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo > 1.2.3'; echo \$?" \ '1' +# 2) tests for PKG_CONFIG_PATH order +run_test "PKG_CONFIG_PATH=${selfdir}/lib1:${selfdir}/lib2 ${1} --libs foo" \ + '-lfoo' +run_test "PKG_CONFIG_PATH=${selfdir}/lib2:${selfdir}/lib1 ${1} --libs foo" \ + '-lbar' + if [ ${failed} -gt 0 ]; then echo "${failed} of ${done} tests failed. See output for details." >&2 exit 1 -- 2.41.0 From 23e31fd702d744addf3c496a8bb6bc2de92a5946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Thu, 3 May 2012 09:15:32 +0200 Subject: [PATCH 4/4] Add tests for 'Requires' and '.private'. --- tests/lib1/bar.pc | 10 ++++++++++ tests/lib1/baz.pc | 11 +++++++++++ tests/run.sh | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/lib1/bar.pc create mode 100644 tests/lib1/baz.pc diff --git a/tests/lib1/bar.pc b/tests/lib1/bar.pc new file mode 100644 index 0000000..688d2af --- /dev/null +++ b/tests/lib1/bar.pc @@ -0,0 +1,10 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: bar +Description: Another pkg-config test +Version: 1.3 +Libs: -L${libdir} -lbar +Requires: foo diff --git a/tests/lib1/baz.pc b/tests/lib1/baz.pc new file mode 100644 index 0000000..1f0c16a --- /dev/null +++ b/tests/lib1/baz.pc @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: bar +Description: Another pkg-config test (with private Requires, ha!) +Version: 1.3 +Libs: -L${libdir} -lbaz +Libs.private: -L${libdir} -lzee +Requires.private: foo diff --git a/tests/run.sh b/tests/run.sh index 1501b81..1d24a54 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -54,6 +54,14 @@ run_test "PKG_CONFIG_PATH=${selfdir}/lib1:${selfdir}/lib2 ${1} --libs foo" \ run_test "PKG_CONFIG_PATH=${selfdir}/lib2:${selfdir}/lib1 ${1} --libs foo" \ '-lbar' +# 3) tests for 'Requires' and 'Requires.private' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs bar" \ + '-lfoo' '-lbar' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs --cflags baz" \ + '-lbaz' '-fPIC' '-I/usr/include/foo' +run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --static --libs baz" \ + '-lfoo -lbaz -lzee' + if [ ${failed} -gt 0 ]; then echo "${failed} of ${done} tests failed. See output for details." >&2 exit 1 -- 2.41.0