OILS / configure-test.sh View on Github | oils.pub

194 lines, 104 significant
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
11export _OIL_CONFIGURE_TEST=1 # so we don't run main
12
13. $PWD/configure # define the functions to be tested
14
15test_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
39test_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
68test_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 # clean-up
84 detected_deps=''
85}
86
87test_echo_vars() {
88 local output
89
90 # before calling detect_readline
91 output="$(echo_shell_vars 2>&1)"
92 if test "$?" = 0; then
93 die 'Expected echo_shell_vars to fail, but succeeded'
94 fi
95 if ! test "$output" = "$0 ERROR: called echo_shell_vars before detecting readline."; then
96 die "Unexpected echo_shell_vars output: $output"
97 fi
98
99 # pretend detect_readline was called
100 detected_deps=1
101
102 # no readline
103 output="$(echo_shell_vars)"
104 if ! test "$?" = 0; then
105 die 'Expected echo_shell_vars to succeed, but failed'
106 fi
107 if ! test "$output" = 'HAVE_READLINE=
108READLINE_DIR=
109HAVE_READLINE_CALLBACK_SIGCLEANUP=
110HAVE_READLINE_CATCH=
111HAVE_READLINE_COMPLETION_DISPLAY_MATCHES_HOOK=
112HAVE_READLINE_COMPLETION_SUPPRESS_APPEND=
113HAVE_READLINE_FREE_HISTORY_ENTRY=
114HAVE_READLINE_LIST_FUNMAP_NAMES=
115HAVE_READLINE_RESIZE_TERMINAL=
116
117PREFIX=/usr/local
118DATAROOTDIR=
119
120STRIP_FLAGS=--gc-sections'; then
121 die "Unexpected echo_shell_vars output: $output"
122 fi
123
124 # have readline, no readline_dir
125 have_readline=1
126 output="$(echo_shell_vars)"
127 if ! test "$?" = 0; then
128 die 'Expected echo_shell_vars to succeed, but failed'
129 fi
130 if ! test "$output" = 'HAVE_READLINE=1
131READLINE_DIR=
132HAVE_READLINE_CALLBACK_SIGCLEANUP=
133HAVE_READLINE_CATCH=
134HAVE_READLINE_COMPLETION_DISPLAY_MATCHES_HOOK=
135HAVE_READLINE_COMPLETION_SUPPRESS_APPEND=
136HAVE_READLINE_FREE_HISTORY_ENTRY=
137HAVE_READLINE_LIST_FUNMAP_NAMES=
138HAVE_READLINE_RESIZE_TERMINAL=
139
140PREFIX=/usr/local
141DATAROOTDIR=
142
143STRIP_FLAGS=--gc-sections'; then
144 die "Unexpected echo_shell_vars output: $output"
145 fi
146
147 # have readline, readline_dir present
148 have_readline=1
149 readline_dir=/path/to/readline
150 output="$(echo_shell_vars)"
151 if ! test "$?" = 0; then
152 die 'Expected echo_shell_vars to succeed, but failed'
153 fi
154 if ! test "$output" = 'HAVE_READLINE=1
155READLINE_DIR=/path/to/readline
156HAVE_READLINE_CALLBACK_SIGCLEANUP=
157HAVE_READLINE_CATCH=
158HAVE_READLINE_COMPLETION_DISPLAY_MATCHES_HOOK=
159HAVE_READLINE_COMPLETION_SUPPRESS_APPEND=
160HAVE_READLINE_FREE_HISTORY_ENTRY=
161HAVE_READLINE_LIST_FUNMAP_NAMES=
162HAVE_READLINE_RESIZE_TERMINAL=
163
164PREFIX=/usr/local
165DATAROOTDIR=
166
167STRIP_FLAGS=--gc-sections'; then
168 die "Unexpected echo_shell_vars output: $output"
169 fi
170
171 # clean-up
172 detected_deps=''
173 have_readline=''
174 readline_dir=''
175 have_systemtap_sdt=''
176}
177
178soil_run() {
179 # Note: could use run-test-funcs
180
181 for func in \
182 test_cc_statements \
183 test_parse_flags \
184 test_echo_cpp \
185 test_echo_vars; do
186
187 echo " $func"
188 $func
189 echo ' OK'
190
191 done
192}
193
194"$@"