Fix uninitialized variable + tests #4
3
Makefile
3
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
|
||||
|
|
2
pkg.c
2
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;
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,71 @@
|
|||
#!/bin/sh
|
||||
# Tests for pkg-config compliance.
|
||||
# * Copyright (c) 2012 Michał Górny <mgorny@gentoo.org>.
|
||||
|
||||
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'
|
||||
|
||||
# 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'
|
||||
|
||||
# 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
|
||||
else
|
||||
echo "${done} tests done. All succeeded." >&2
|
||||
exit 0
|
||||
fi
|
Loading…
Reference in New Issue