-
Notifications
You must be signed in to change notification settings - Fork 774
/
common.sh
executable file
·130 lines (124 loc) · 2.92 KB
/
common.sh
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
#!/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
}
test_libpath(){
# usage: test_libpath ${PROGRAM} ${LIBPATH} ${LIBNAME}
# use optional 'BUILD_MODE=static' to pass if match is not found
UNAME=$(uname)
case ${UNAME} in
Darwin*)
USE_OTOOL=yes
EXPECTED_SUBSTR=$2
;;
MINGW* | MSYS*)
EXPECTED_SUBSTR=$(cygpath -u "$2/$3" | sed 's/\/lib\//\/bin\//')
;;
Linux*)
EXPECTED_SUBSTR=$2/$3
;;
*)
echo "test_libpath not set-up for UNAME=${UNAME}"
return 77 # skip
;;
esac
printf "Testing expected libpath output "
if [ "x${BUILD_MODE}" = xstatic ]; then
printf "not "
fi
printf "containing '${EXPECTED_SUBSTR}' ... "
if [ "x${USE_OTOOL}" = xyes ]; then
CMD_OUTPUT=$(otool -l ./$1 | grep -m1 "$2")
else
CMD_OUTPUT=$(ldd ./$1 | grep -m1 "$3")
fi
case "${CMD_OUTPUT}" in
*"not found"*)
echo "failed: ${CMD_OUTPUT}"
return 1 ;;
*${EXPECTED_SUBSTR}*) found=yes ;;
*) found=no ;;
esac
if [ "x${BUILD_MODE}" = xstatic ]; then
if [ "x${found}" = "xyes" ] ; then
echo "failed: ${CMD_OUTPUT}"
return 1
fi
elif [ "x${found}" = "xno" ] ; then
echo "failed:"
if [ "x${USE_OTOOL}" = xyes ]; then
echo "otool -l ./$1:"
otool -l ./$1
else
echo "ldd ./$1:"
ldd ./$1
fi
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
}