-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
configure-test.sh
executable file
·187 lines (154 loc) · 4.01 KB
/
configure-test.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
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
#!/bin/sh
#
# Usage:
# ./configure-test.sh <function name>
# Note: set -e and -u are POSIX; maybe the configure script should run with them
#set -o nounset
#set -o pipefail
#set -o errexit
export _OIL_CONFIGURE_TEST=1 # so we don't run main
. $PWD/configure # define the functions to be tested
test_cc_statements() {
cc_print_expr 'sizeof(int)'
local actual
actual=$(cat $TMP/print_expr.out)
if ! test "$actual" = 4; then
die "Expected 4, got $actual"
fi
if ! check_sizeof SIZEOF_INT 'int' 4; then
die "FAILED"
fi
# failing test
#check_sizeof SIZEOF_INT 'int' 8
if ! cc_statement HAVE_INT 'int x = (int)0;'; then
die "FAILED"
fi
if cc_statement HAVE_FOO 'foo x = (foo)0;'; then
die "Expected to fail"
fi
}
test_parse_flags() {
parse_flags --prefix /usr --datarootdir /usr/local/share
if ! test "$FLAG_prefix" = '/usr'; then
die "FAILED - prefix is $FLAG_prefix not /usr"
fi
if ! test "$FLAG_datarootdir" = '/usr/local/share'; then
die "FAILED - datarootdir is $FLAG_datarootdir not /usr/local/share"
fi
FLAG_prefix='/usr/local'
FLAG_datarootdir=''
parse_flags --prefix /usr
if ! test "$FLAG_datarootdir" = '/usr/share'; then
die "FAILED - datarootdir is $FLAG_datarootdir not /usr/share"
fi
FLAG_prefix='/usr/local'
FLAG_datarootdir=''
}
test_echo_cpp() {
local output
# before calling detect_readline
output="$(echo_cpp 2>&1)"
if test "$?" = 0; then
die 'Expected echo_cpp to fail, but succeeded'
fi
if ! test "$output" = "$0 ERROR: called echo_cpp before detecting readline."; then
die "Unexpected echo_cpp output: $output"
fi
# pretend detected_deps was called
detected_deps=1
# no readline
output="$(echo_cpp)"
if ! test "$?" = 0; then
die 'Expected echo_cpp to succeed, but failed'
fi
case "$output" in
'/* #undef HAVE_READLINE */'*) ;;
*) die "Unexpected echo_cpp output: $output" ;;
esac
# have readline
have_readline=1
output="$(echo_cpp)"
if ! test "$?" = 0; then
die 'Expected echo_cpp to succeed, but failed'
fi
case "$output" in
'#define HAVE_READLINE 1'*) ;;
*) die "Unexpected echo_cpp output: $output" ;;
esac
# clean-up
detected_deps=''
have_readline=''
}
test_echo_vars() {
local output
# before calling detect_readline
output="$(echo_shell_vars 2>&1)"
if test "$?" = 0; then
die 'Expected echo_shell_vars to fail, but succeeded'
fi
if ! test "$output" = "$0 ERROR: called echo_shell_vars before detecting readline."; then
die "Unexpected echo_shell_vars output: $output"
fi
# pretend detect_readline was called
detected_deps=1
# no readline
output="$(echo_shell_vars)"
if ! test "$?" = 0; then
die 'Expected echo_shell_vars to succeed, but failed'
fi
if ! test "$output" = 'HAVE_READLINE=
READLINE_DIR=
HAVE_SYSTEMTAP_SDT=
PREFIX=/usr/local
DATAROOTDIR=
STRIP_FLAGS=--gc-sections'; then
die "Unexpected echo_shell_vars output: $output"
fi
# have readline, no readline_dir
have_readline=1
output="$(echo_shell_vars)"
if ! test "$?" = 0; then
die 'Expected echo_shell_vars to succeed, but failed'
fi
if ! test "$output" = 'HAVE_READLINE=1
READLINE_DIR=
HAVE_SYSTEMTAP_SDT=
PREFIX=/usr/local
DATAROOTDIR=
STRIP_FLAGS=--gc-sections'; then
die "Unexpected echo_shell_vars output: $output"
fi
# have readline, readline_dir present
have_readline=1
readline_dir=/path/to/readline
output="$(echo_shell_vars)"
if ! test "$?" = 0; then
die 'Expected echo_shell_vars to succeed, but failed'
fi
if ! test "$output" = 'HAVE_READLINE=1
READLINE_DIR=/path/to/readline
HAVE_SYSTEMTAP_SDT=
PREFIX=/usr/local
DATAROOTDIR=
STRIP_FLAGS=--gc-sections'; then
die "Unexpected echo_shell_vars output: $output"
fi
# clean-up
detected_deps=''
have_readline=''
readline_dir=''
have_systemtap_sdt=''
}
soil_run() {
# Note: could use run-test-funcs
for func in \
test_cc_statements \
test_parse_flags \
test_echo_cpp \
test_echo_vars; do
echo " $func"
$func
echo ' OK'
done
}
"$@"