1 | #!/bin/sh
|
2 | #
|
3 | # Usage:
|
4 | # ./configure-test.sh <function name>
|
5 |
|
6 | # Note: set -e and -u are POSIX; maybe the configure script should run with them
|
7 | #set -o nounset
|
8 | #set -o pipefail
|
9 | #set -o errexit
|
10 |
|
11 | export _OIL_CONFIGURE_TEST=1 # so we don't run main
|
12 |
|
13 | . $PWD/configure # define the functions to be tested
|
14 |
|
15 | test_cc_statements() {
|
16 | cc_print_expr 'sizeof(int)'
|
17 |
|
18 | local actual
|
19 | actual=$(cat $TMP/print_expr.out)
|
20 | if ! test "$actual" = 4; then
|
21 | die "Expected 4, got $actual"
|
22 | fi
|
23 |
|
24 | if ! check_sizeof SIZEOF_INT 'int' 4; then
|
25 | die "FAILED"
|
26 | fi
|
27 | # failing test
|
28 | #check_sizeof SIZEOF_INT 'int' 8
|
29 |
|
30 | if ! cc_statement HAVE_INT 'int x = (int)0;'; then
|
31 | die "FAILED"
|
32 | fi
|
33 |
|
34 | if cc_statement HAVE_FOO 'foo x = (foo)0;'; then
|
35 | die "Expected to fail"
|
36 | fi
|
37 | }
|
38 |
|
39 | test_parse_flags() {
|
40 | parse_flags --prefix /usr --datarootdir /usr/local/share
|
41 |
|
42 | if test "$FLAG_prefix" != '/usr'; then
|
43 | die "FAILED - expected prefix /usr, got $FLAG_prefix"
|
44 | fi
|
45 | if test "$FLAG_datarootdir" != '/usr/local/share'; then
|
46 | die "FAILED - expected datarootdir /usr/local/share, got $FLAG_datarootdir"
|
47 | fi
|
48 |
|
49 | init_flags # Reset
|
50 |
|
51 | # Test fallback to --prefix
|
52 | parse_flags --prefix /usr
|
53 |
|
54 | if test "$FLAG_datarootdir" != '/usr/share'; then
|
55 | die "FAILED - expected datarootdir /usr/share, got $FLAG_datarootdir"
|
56 | fi
|
57 |
|
58 | init_flags # Reset
|
59 |
|
60 | parse_flags --cxx-for-configure foo
|
61 | if test "$FLAG_cxx_for_configure" != 'foo'; then
|
62 | die "FAILED - expected cxx foo, got $FLAG_cxx_for_configure"
|
63 | fi
|
64 |
|
65 | init_flags # Reset
|
66 | }
|
67 |
|
68 | test_echo_cpp() {
|
69 | local output
|
70 |
|
71 | # before calling detect_readline
|
72 | output="$(echo_cpp 2>&1)"
|
73 | if test "$?" = 0; then
|
74 | die 'Expected echo_cpp to fail, but succeeded'
|
75 | fi
|
76 | if ! test "$output" = "$0 ERROR: called echo_cpp before detecting readline."; then
|
77 | die "Unexpected echo_cpp output: $output"
|
78 | fi
|
79 |
|
80 | # pretend detected_deps was called
|
81 | detected_deps=1
|
82 |
|
83 | # no readline
|
84 | output="$(echo_cpp)"
|
85 | if ! test "$?" = 0; then
|
86 | die 'Expected echo_cpp to succeed, but failed'
|
87 | fi
|
88 | case "$output" in
|
89 | '/* #undef HAVE_READLINE */'*) ;;
|
90 | *) die "Unexpected echo_cpp output: $output" ;;
|
91 | esac
|
92 |
|
93 | # have readline
|
94 | have_readline=1
|
95 | output="$(echo_cpp)"
|
96 | if ! test "$?" = 0; then
|
97 | die 'Expected echo_cpp to succeed, but failed'
|
98 | fi
|
99 | case "$output" in
|
100 | '#define HAVE_READLINE 1'*) ;;
|
101 | *) die "Unexpected echo_cpp output: $output" ;;
|
102 | esac
|
103 |
|
104 | # clean-up
|
105 | detected_deps=''
|
106 | have_readline=''
|
107 | }
|
108 |
|
109 | test_echo_vars() {
|
110 | local output
|
111 |
|
112 | # before calling detect_readline
|
113 | output="$(echo_shell_vars 2>&1)"
|
114 | if test "$?" = 0; then
|
115 | die 'Expected echo_shell_vars to fail, but succeeded'
|
116 | fi
|
117 | if ! test "$output" = "$0 ERROR: called echo_shell_vars before detecting readline."; then
|
118 | die "Unexpected echo_shell_vars output: $output"
|
119 | fi
|
120 |
|
121 | # pretend detect_readline was called
|
122 | detected_deps=1
|
123 |
|
124 | # no readline
|
125 | output="$(echo_shell_vars)"
|
126 | if ! test "$?" = 0; then
|
127 | die 'Expected echo_shell_vars to succeed, but failed'
|
128 | fi
|
129 | if ! test "$output" = 'HAVE_READLINE=
|
130 | READLINE_DIR=
|
131 |
|
132 | PREFIX=/usr/local
|
133 | DATAROOTDIR=
|
134 |
|
135 | STRIP_FLAGS=--gc-sections'; then
|
136 | die "Unexpected echo_shell_vars output: $output"
|
137 | fi
|
138 |
|
139 | # have readline, no readline_dir
|
140 | have_readline=1
|
141 | output="$(echo_shell_vars)"
|
142 | if ! test "$?" = 0; then
|
143 | die 'Expected echo_shell_vars to succeed, but failed'
|
144 | fi
|
145 | if ! test "$output" = 'HAVE_READLINE=1
|
146 | READLINE_DIR=
|
147 |
|
148 | PREFIX=/usr/local
|
149 | DATAROOTDIR=
|
150 |
|
151 | STRIP_FLAGS=--gc-sections'; then
|
152 | die "Unexpected echo_shell_vars output: $output"
|
153 | fi
|
154 |
|
155 | # have readline, readline_dir present
|
156 | have_readline=1
|
157 | readline_dir=/path/to/readline
|
158 | output="$(echo_shell_vars)"
|
159 | if ! test "$?" = 0; then
|
160 | die 'Expected echo_shell_vars to succeed, but failed'
|
161 | fi
|
162 | if ! test "$output" = 'HAVE_READLINE=1
|
163 | READLINE_DIR=/path/to/readline
|
164 |
|
165 | PREFIX=/usr/local
|
166 | DATAROOTDIR=
|
167 |
|
168 | STRIP_FLAGS=--gc-sections'; then
|
169 | die "Unexpected echo_shell_vars output: $output"
|
170 | fi
|
171 |
|
172 | # clean-up
|
173 | detected_deps=''
|
174 | have_readline=''
|
175 | readline_dir=''
|
176 | have_systemtap_sdt=''
|
177 | }
|
178 |
|
179 | soil_run() {
|
180 | # Note: could use run-test-funcs
|
181 |
|
182 | for func in \
|
183 | test_cc_statements \
|
184 | test_parse_flags \
|
185 | test_echo_cpp \
|
186 | test_echo_vars; do
|
187 |
|
188 | echo " $func"
|
189 | $func
|
190 | echo ' OK'
|
191 |
|
192 | done
|
193 | }
|
194 |
|
195 | "$@"
|