Tag
Hash :
749a604c
Author :
Date :
2012-09-02T17:34:44
tests: add test for freedesktop.org bug 54271
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
#!/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
local cmdline 2>/dev/null || true
cmdline="${1}"
eval res="\$(${1})" 2>/dev/null
t_ret=0
while [ ${#} -gt 1 ]; do
shift
case "${res}" in
*"${1}"*)
;;
*)
echo
echo "***********************"
echo "!!! Test $done failed."
echo "!!! $ ${cmdline}"
echo "!!! ${res}"
echo "!!! expected '${1}' in output"
echo "***********************"
t_ret=1
;;
esac
done
if [ ${t_ret} -eq 0 ]; then
echo -n "."
else
failed=$(( failed + 1 ))
fi
done=$(( done + 1 ))
}
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} --cflags --libs 'foo > 1.2'" \
'-lfoo' '-I/usr/include/foo' '-fPIC'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags --libs 'foo > 1.2 bar >= 1.3'" \
'-lfoo' '-I/usr/include/foo' '-fPIC'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags --libs 'foo' '>' '1.2'" \
'-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'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo' '>' '1.2'; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --uninstalled 'foo'; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --uninstalled 'omg'; echo \$?" \
'0'
run_test "${1} --modversion ${selfdir}/lib1/foo.pc" \
'1.2.3'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'foo >= '; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'tilde <= 1.0.0'; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'tilde = 1.0.0~rc1'; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists 'tilde >= 1.0.0'; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists '' 'foo'; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs intermediary-1 intermediary-2" \
'-lintermediary-1 -lintermediary-2 -lfoo -lbar -lbaz'
# 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'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --static --libs argv-parse-2" \
'-pthread '
# 4) tests for parser bugs
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs dos-lineendings" \
'-L/usr/lib/dos-lineendings -ldos-lineendings'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs argv-parse" \
'-llib-2 -lpthread'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exists -foo; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs argv-parse-3" \
'-llib-1'
# 5) tests for other regressions
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --variable=includedir foo" \
'/usr/include'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs-only-L cflags-libs-only" \
'-L/usr/local/lib'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs-only-L --libs-only-l cflags-libs-only" \
'-lfoo'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags-only-I --cflags-only-other cflags-libs-only" \
'-I/usr/local/include'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs incomplete; echo $?" \
'0'
# 6) tests for builtins
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --modversion pkg-config" \
'0.27'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --variable=prefix foo" \
'/usr'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --define-variable=prefix=/test --variable=prefix foo" \
'/test'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --variable=pcfiledir foo" \
"${selfdir}/lib1"
# 7) tests for env modifiers
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 PKG_CONFIG_SYSROOT_DIR=/test ${1} --cflags baz" \
'-I/test/usr/include/foo'
# 8) tests for 'Conflicts'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs conflicts; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --ignore-conflicts --libs conflicts; echo \$?" \
'-lconflicts' '0'
# 9) tests for --atleast-version (with and without trailing space)
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --atleast-version 1.0 foo; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --atleast-version 2.0 foo; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exact-version 1.0 foo; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exact-version 1.2.3 foo; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --max-version 1.0 foo; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --max-version 2.0 foo; echo \$?" \
'0'
# tests for issue #20
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --atleast-version 1.0 'foo '; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --atleast-version 2.0 'foo '; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exact-version 1.0 'foo '; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --exact-version 1.2.3 'foo '; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --max-version 1.0 'foo '; echo \$?" \
'1'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --max-version 2.0 'foo '; echo \$?" \
'0'
# test missing requires
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags missing-require; echo \$?" \
'1'
# test quoted #35
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags quotes" \
"-DQUOTED=\\\"bla\\\""
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs nolib; echo \$?" \
'0'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --libs nocflag; echo \$?" \
'0'
# test 36 - running against file in CWD with no path
# File moved to CWD to allow arbitrary path to pkgconf and keep pc file in CWD
run_test "cp ${selfdir}/lib1/foo.pc . && ${1} --libs foo.pc; rm -f foo.pc" \
'-lfoo'
# 10) tests for internal getopt implementation with options at the end
if [ "x@STRICT_MODE@" = "xno" ]; then
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} foo --libs" \
'-lfoo'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} foo --cflags --libs" \
'-lfoo' '-I/usr/include/foo' '-fPIC'
run_test "PKG_CONFIG_PATH=${selfdir}/lib1 ${1} --cflags foo --libs" \
'-lfoo' '-I/usr/include/foo' '-fPIC'
fi
echo
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