diff options
| author | Mike Taves <mwtoews@gmail.com> | 2021-12-09 00:45:03 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-09 00:45:03 +1300 |
| commit | 7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552 (patch) | |
| tree | d71d0771cc9f95d5a8ea96bd975bbd4164188813 /test/postinstall/common.sh | |
| parent | 1b18defb63c7d2420d18e4375348663874247838 (diff) | |
| download | PROJ-7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552.tar.gz PROJ-7a9b6566ac02d8c408f4f3758bfa5fcc3e90b552.zip | |
Refactor post-install suite to test shared and static projlib (#2972)
Diffstat (limited to 'test/postinstall/common.sh')
| -rwxr-xr-x | test/postinstall/common.sh | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/test/postinstall/common.sh b/test/postinstall/common.sh new file mode 100755 index 00000000..3bb5c080 --- /dev/null +++ b/test/postinstall/common.sh @@ -0,0 +1,135 @@ +#!/bin/sh + +# Common shell functions for post-install tests + +main_setup(){ + # usage: main_setup $1 $2 + export prefix=$1 + if [ -z "${prefix}" ]; then + echo "First positional argument to the the installed prefix is required" + exit 1 + fi + case $2 in + "" | shared) export BUILD_MODE=shared ;; + static) export BUILD_MODE=static ;; + *) + echo "Second argument must be either shared (default) or static" + exit 1 ;; + esac + + if [ ${BUILD_MODE} = shared ]; then + case $(uname) in + MINGW* | MSYS*) + prefix=$(cygpath -u ${prefix}) + export LD_LIBRARY_PATH=${prefix}/bin + ;; + Darwin*) + export DYLD_LIBRARY_PATH=${prefix}/lib + export LDFLAGS="${LDFLAGS} -Wl,-rpath,${prefix}/lib" + ;; + *) + export LD_LIBRARY_PATH=${prefix}/lib + ;; + esac + fi +} + +test_ldd(){ + # usage: test_ldd ${PROGRAM} ${LIBNAME} + # use optional 'BUILD_MODE=static' to to pass if LIBNAME is not found + if [ ! $(which ldd) ]; then + UNAME=$(uname) + case ${UNAME} in + Darwin*) alias ldd="otool -L" ;; + *) + echo "no ldd equivalent found for UNAME=${UNAME}" + return 77 ;; # skip + esac + fi + if [ -n "${LD_LIBRARY_PATH}" ]; then + EXPECTED_LDD_SUBSTR="${LD_LIBRARY_PATH}/$2" + elif [ -n "${DYLD_LIBRARY_PATH}" ]; then + EXPECTED_LDD_SUBSTR="${DYLD_LIBRARY_PATH}/$2" + else + EXPECTED_LDD_SUBSTR=$2 + fi + printf "Testing expected ldd output " + if [ "x${BUILD_MODE}" = xstatic ]; then + printf "not " + fi + printf "containing '${EXPECTED_LDD_SUBSTR}' ... " + LDD_OUTPUT=$(ldd ./$1 | grep "$3") + case "${LDD_OUTPUT}" in + *"not found"*) + echo "failed: ${LDD_OUTPUT}" + return 1 ;; + *${EXPECTED_LDD_SUBSTR}*) found=yes ;; + *) found=no ;; + esac + if [ "x${BUILD_MODE}" = xstatic ]; then + if [ "x${found}" = "xyes" ] ; then + echo "failed: ${LDD_OUTPUT}" + return 1 + fi + elif [ "x${found}" = "xno" ] ; then + echo "failed:" + ldd ./$1 + return 1 + fi + echo "passed" + return 0 +} + +test_transform(){ + # usage: test_transform ${PROGRAM_TRANSFORM} + printf "Testing transform ... " + EXPECTED="easting: 691875.63, northing: 6098907.83, latitude: 55.00, longitude: 12.00" + case "$1" in + "${EXPECTED}") + echo "passed" + return 0 ;; + *) + echo "failed, expected ${EXPECTED}, found $1" + return 1 ;; + esac +} + +test_searchpath(){ + # usage: test_searchpath ${PROGRAM_SEARCHPATH} ${EXPECTED_SEARCHPATH} + printf "Testing program searchpath '$1' ... " + PROGRAM_SEARCHPATH=$1 + UNAME=$(uname) + case ${UNAME} in + MINGW* | MSYS*) + PROGRAM_SEARCHPATH=$(echo "${PROGRAM_SEARCHPATH}" | tr '\\' '/') + esac + if [ -z $2 ]; then + echo "failed (empty expected)" + return 1 + fi + case ${PROGRAM_SEARCHPATH} in + *"$2"*) + echo "passed" + return 0 ;; + *) + echo "failed, expected '$2'" + return 1 ;; + esac +} + +test_version(){ + # usage: test_version ${PROGRAM_VERSION} ${EXPECTED_VERSION} + printf "Testing program version $1 ... " + if [ -z $2 ]; then + echo "failed (empty expected)" + return 1 + fi + case $1 in + $2*) + echo "passed" + return 0 ;; + *) + echo "failed, expected $2" + return 1 ;; + esac +} |
