mirror of
https://gitlab.freedesktop.org/pkg-config/pkg-config.git
synced 2026-05-05 00:38:04 +02:00
check: Pass args to test function instead of setting in variable
The run_test shell function was running pkg-config with arguments stored in an environment variable. This has problems when trying to pass shell special characters with the proper escaping. Instead, pass the arguments to the test where they can maintain correct formatting through use of the special variable "$@".
This commit is contained in:
parent
e68baa7463
commit
397d414a6a
13 changed files with 56 additions and 113 deletions
|
|
@ -4,11 +4,8 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--cflags simple"
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --cflags simple
|
||||
|
||||
ARGS="--cflags fields-blank"
|
||||
RESULT=""
|
||||
run_test
|
||||
|
||||
run_test --cflags fields-blank
|
||||
|
|
|
|||
|
|
@ -7,22 +7,18 @@ set -e
|
|||
# all of these should fail, but when '=' or ' ' aren't used consistently
|
||||
# between the two options, broken popt sets the version to compare to be
|
||||
# "a=b"
|
||||
ARGS="--define-variable=a=b --atleast-pkgconfig-version=999.999"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --define-variable=a=b --atleast-pkgconfig-version=999.999
|
||||
|
||||
ARGS="--define-variable=a=b --atleast-pkgconfig-version 999.999"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --define-variable=a=b --atleast-pkgconfig-version 999.999
|
||||
|
||||
ARGS="--define-variable a=b --atleast-pkgconfig-version 999.999"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --define-variable a=b --atleast-pkgconfig-version 999.999
|
||||
|
||||
ARGS="--define-variable a=b --atleast-pkgconfig-version=999.999"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --define-variable a=b --atleast-pkgconfig-version=999.999
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--libs conflicts-test"
|
||||
RESULT="-L/public-dep/lib -lpublic-dep"
|
||||
|
||||
run_test
|
||||
run_test --libs conflicts-test
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,13 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
RESULT="-I/includedir/"
|
||||
case ${MACHTYPE} in
|
||||
*-msys)
|
||||
# Make sure path doesn't get mangled on MSYS
|
||||
ARGS="--define-variable=includedir=\\/includedir/ --cflags simple"
|
||||
run_test --define-variable=includedir=\\/includedir/ --cflags simple
|
||||
;;
|
||||
*)
|
||||
ARGS="--define-variable=includedir=/includedir/ --cflags simple"
|
||||
run_test --define-variable=includedir=/includedir/ --cflags simple
|
||||
;;
|
||||
esac
|
||||
RESULT="-I/includedir/"
|
||||
|
||||
run_test
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--cflags idirafter"
|
||||
RESULT="-idirafter -I/after -I/foo -I/bar"
|
||||
|
||||
run_test
|
||||
run_test --cflags idirafter
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--cflags includedir"
|
||||
RESULT="-I/usr/include/somedir"
|
||||
|
||||
run_test
|
||||
run_test --cflags includedir
|
||||
|
|
|
|||
|
|
@ -4,14 +4,12 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--libs simple"
|
||||
if [ "$list_indirect_deps" = "yes" ]; then
|
||||
RESULT="-lsimple -lm"
|
||||
else
|
||||
RESULT="-lsimple"
|
||||
fi
|
||||
run_test
|
||||
run_test --libs simple
|
||||
|
||||
ARGS="--libs fields-blank"
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --libs fields-blank
|
||||
|
|
|
|||
|
|
@ -4,7 +4,5 @@ set -e
|
|||
|
||||
. ${srcdir}/common
|
||||
|
||||
ARGS="--static --libs simple"
|
||||
RESULT="-lsimple -lm"
|
||||
|
||||
run_test
|
||||
run_test --static --libs simple
|
||||
|
|
|
|||
|
|
@ -7,25 +7,21 @@ set -e
|
|||
# non-existent package; call should fail and cause no output
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
ARGS="--exists pkg-non-existent"
|
||||
run_test
|
||||
run_test --exists pkg-non-existent
|
||||
|
||||
# existing package, but with missing Requires
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
ARGS="--exists missing-requires"
|
||||
run_test
|
||||
run_test --exists missing-requires
|
||||
|
||||
# tests below are on an existing package, but with missing Requires.private;
|
||||
# when pkg-config outputs error, the actual error text isn't checked
|
||||
# package exists, but should fail since deps can't be resolved
|
||||
ARGS="--exists missing-requires-private"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists missing-requires-private
|
||||
|
||||
# get Libs
|
||||
ARGS="--libs missing-requires-private"
|
||||
if [ "$list_indirect_deps" = "yes" ]; then
|
||||
EXPECT_RETURN=1
|
||||
RESULT='Package pkg-non-existent-private-dep was not found in the pkg-config search path.
|
||||
|
|
@ -36,54 +32,46 @@ else
|
|||
EXPECT_RETURN=0
|
||||
RESULT="-L/missing-requires-private/lib -lmissing-requires-private"
|
||||
fi
|
||||
run_test
|
||||
run_test --libs missing-requires-private
|
||||
|
||||
# Libs.private should fail (verbosely, but the output isn't verified)
|
||||
ARGS="--silence-errors --static --libs missing-requires-private"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --silence-errors --static --libs missing-requires-private
|
||||
|
||||
# Cflags.private should fail (verbosely, but the output isn't verified)
|
||||
ARGS="--silence-errors --static --cflags missing-requires-private"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --silence-errors --static --cflags missing-requires-private
|
||||
|
||||
# Cflags should fail (verbosely, but the output isn't verified)
|
||||
ARGS="--silence-errors --cflags missing-requires-private"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --silence-errors --cflags missing-requires-private
|
||||
|
||||
# get includedir var
|
||||
ARGS="--variable includedir missing-requires-private"
|
||||
EXPECT_RETURN=0
|
||||
RESULT="/usr/include/somedir"
|
||||
run_test
|
||||
run_test --variable includedir missing-requires-private
|
||||
|
||||
# tests below are on an existing package, but with missing Requires; when
|
||||
# pkg-config outputs error, the actual error text isn't checked
|
||||
# package exists
|
||||
ARGS="missing-requires"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test missing-requires
|
||||
|
||||
# Libs should fail
|
||||
ARGS="--silence-errors --libs missing-requires"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --silence-errors --libs missing-requires
|
||||
|
||||
# Cflags should fail
|
||||
ARGS="--silence-errors --cflags missing-requires"
|
||||
EXPECT_RETURN=1
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --silence-errors --cflags missing-requires
|
||||
|
||||
# get includedir var
|
||||
ARGS="--variable includedir missing-requires"
|
||||
EXPECT_RETURN=0
|
||||
RESULT="/usr/include/somedir"
|
||||
run_test
|
||||
run_test --variable includedir missing-requires
|
||||
|
|
|
|||
|
|
@ -5,27 +5,21 @@ set -e
|
|||
. ${srcdir}/common
|
||||
|
||||
# expect cflags from requires-test and public-dep
|
||||
ARGS="--cflags requires-test"
|
||||
RESULT="-I/requires-test/include -I/private-dep/include -I/public-dep/include"
|
||||
run_test
|
||||
run_test --cflags requires-test
|
||||
|
||||
# still expect those cflags for static linking case
|
||||
ARGS="--static --cflags requires-test"
|
||||
RESULT="-I/requires-test/include -I/private-dep/include -I/public-dep/include"
|
||||
run_test
|
||||
run_test --static --cflags requires-test
|
||||
|
||||
# expect libs for just requires-test and public-dep
|
||||
ARGS="--libs requires-test"
|
||||
if [ "$list_indirect_deps" = "yes" ]; then
|
||||
RESULT="-L/requires-test/lib -L/private-dep/lib -L/public-dep/lib -lrequires-test -lprivate-dep -lpublic-dep"
|
||||
else
|
||||
RESULT="-L/requires-test/lib -L/public-dep/lib -lrequires-test -lpublic-dep"
|
||||
fi
|
||||
run_test
|
||||
run_test --libs requires-test
|
||||
|
||||
# expect libs for requires-test, public-dep and private-dep in static case
|
||||
ARGS="--static --libs requires-test"
|
||||
RESULT="-L/requires-test/lib -L/private-dep/lib -L/public-dep/lib -lrequires-test -lprivate-dep -lpublic-dep"
|
||||
run_test
|
||||
|
||||
|
||||
run_test --static --libs requires-test
|
||||
|
|
|
|||
|
|
@ -9,94 +9,76 @@ v2=1.0.0
|
|||
v3=1.0.1
|
||||
|
||||
# exact version testing
|
||||
ARGS="--exists --print-errors simple = $v1"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors simple = $v1
|
||||
|
||||
ARGS="--exists --print-errors --exact-version=$v1 simple"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors --exact-version=$v1 simple
|
||||
|
||||
ARGS="--exists --print-errors simple = $v2"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors simple = $v2
|
||||
|
||||
ARGS="--exists --print-errors --exact-version=$v2 simple"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors --exact-version=$v2 simple
|
||||
|
||||
ARGS="--exists --print-errors simple = $v3"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors simple = $v3
|
||||
|
||||
ARGS="--exists --print-errors --exact-version=$v3 simple"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors --exact-version=$v3 simple
|
||||
|
||||
# atleast version testing
|
||||
ARGS="--exists --print-errors simple >= $v1"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors simple \>= $v1
|
||||
|
||||
ARGS="--exists --print-errors --atleast-version=$v1 simple"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors --atleast-version=$v1 simple
|
||||
|
||||
ARGS="--exists --print-errors simple >= $v2"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors simple \>= $v2
|
||||
|
||||
ARGS="--exists --print-errors --atleast-version=$v2 simple"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors --atleast-version=$v2 simple
|
||||
|
||||
ARGS="--exists --print-errors simple >= $v3"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors simple \>= $v3
|
||||
|
||||
ARGS="--exists --print-errors --atleast-version=$v3 simple"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors --atleast-version=$v3 simple
|
||||
|
||||
# max version testing
|
||||
ARGS="--exists --print-errors simple <= $v1"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors simple \<= $v1
|
||||
|
||||
ARGS="--exists --print-errors --max-version=$v1 simple"
|
||||
EXPECT_RETURN=1
|
||||
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
|
||||
run_test
|
||||
run_test --exists --print-errors --max-version=$v1 simple
|
||||
|
||||
ARGS="--exists --print-errors simple <= $v2"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors simple \<= $v2
|
||||
|
||||
ARGS="--exists --print-errors --max-version=$v2 simple"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors --max-version=$v2 simple
|
||||
|
||||
ARGS="--exists --print-errors simple <= $v3"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors simple \<= $v3
|
||||
|
||||
ARGS="--exists --print-errors --max-version=$v3 simple"
|
||||
EXPECT_RETURN=0
|
||||
RESULT=""
|
||||
run_test
|
||||
run_test --exists --print-errors --max-version=$v3 simple
|
||||
|
|
|
|||
|
|
@ -5,11 +5,9 @@ set -e
|
|||
. ${srcdir}/common
|
||||
|
||||
# expect cflags from whitespace
|
||||
ARGS="--cflags whitespace"
|
||||
RESULT='-Dlala=misc -I/usr/white\ space/include -I$(top_builddir) -Iinclude\ dir -Iother\ include\ dir'
|
||||
run_test
|
||||
run_test --cflags whitespace
|
||||
|
||||
# expect libs from whitespace
|
||||
ARGS="--libs whitespace"
|
||||
RESULT="-r:foo -L/usr/white\\ space/lib -lfoo\\ bar -lbar\\ baz"
|
||||
run_test
|
||||
run_test --libs whitespace
|
||||
|
|
|
|||
10
check/common
10
check/common
|
|
@ -15,17 +15,17 @@ export LC_ALL=C
|
|||
|
||||
run_test () {
|
||||
set +e
|
||||
${pkgconfig} $ARGS >/dev/null 2>&1
|
||||
${pkgconfig} "$@" >/dev/null 2>&1
|
||||
R=$?
|
||||
if [ "$R" -ne "${EXPECT_RETURN:-0}" ]; then
|
||||
${pkgconfig} --print-errors $ARGS
|
||||
echo "${pkgconfig} $ARGS exited with $R (expected ${EXPECT_RETURN:-0})" 1>&2
|
||||
${pkgconfig} --print-errors "$@"
|
||||
echo "${pkgconfig} $@ exited with $R (expected ${EXPECT_RETURN:-0})" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
R=$(${pkgconfig} $ARGS 2>&1 | sed -e 's,^[[:space:]]*,,' -e 's,[[:space:]]*$,,')
|
||||
R=$(${pkgconfig} "$@" 2>&1 | sed -e 's,^[[:space:]]*,,' -e 's,[[:space:]]*$,,')
|
||||
if [ "$R" != "$RESULT" ]; then
|
||||
echo "${pkgconfig} $ARGS :"
|
||||
echo "${pkgconfig} $@ :"
|
||||
echo "'$R' != '$RESULT'"
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue