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

190 lines, 119 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 - prefix is $FLAG_prefix not /usr"
44 fi
45
46 if ! test "$FLAG_datarootdir" = '/usr/local/share'; then
47 die "FAILED - datarootdir is $FLAG_datarootdir not /usr/local/share"
48 fi
49
50 FLAG_prefix='/usr/local'
51 FLAG_datarootdir=''
52
53 parse_flags --prefix /usr
54
55 if ! test "$FLAG_datarootdir" = '/usr/share'; then
56 die "FAILED - datarootdir is $FLAG_datarootdir not /usr/share"
57 fi
58
59 FLAG_prefix='/usr/local'
60 FLAG_datarootdir=''
61}
62
63test_echo_cpp() {
64 local output
65
66 # before calling detect_readline
67 output="$(echo_cpp 2>&1)"
68 if test "$?" = 0; then
69 die 'Expected echo_cpp to fail, but succeeded'
70 fi
71 if ! test "$output" = "$0 ERROR: called echo_cpp before detecting readline."; then
72 die "Unexpected echo_cpp output: $output"
73 fi
74
75 # pretend detected_deps was called
76 detected_deps=1
77
78 # no readline
79 output="$(echo_cpp)"
80 if ! test "$?" = 0; then
81 die 'Expected echo_cpp to succeed, but failed'
82 fi
83 case "$output" in
84 '/* #undef HAVE_READLINE */'*) ;;
85 *) die "Unexpected echo_cpp output: $output" ;;
86 esac
87
88 # have readline
89 have_readline=1
90 output="$(echo_cpp)"
91 if ! test "$?" = 0; then
92 die 'Expected echo_cpp to succeed, but failed'
93 fi
94 case "$output" in
95 '#define HAVE_READLINE 1'*) ;;
96 *) die "Unexpected echo_cpp output: $output" ;;
97 esac
98
99 # clean-up
100 detected_deps=''
101 have_readline=''
102}
103
104test_echo_vars() {
105 local output
106
107 # before calling detect_readline
108 output="$(echo_shell_vars 2>&1)"
109 if test "$?" = 0; then
110 die 'Expected echo_shell_vars to fail, but succeeded'
111 fi
112 if ! test "$output" = "$0 ERROR: called echo_shell_vars before detecting readline."; then
113 die "Unexpected echo_shell_vars output: $output"
114 fi
115
116 # pretend detect_readline was called
117 detected_deps=1
118
119 # no readline
120 output="$(echo_shell_vars)"
121 if ! test "$?" = 0; then
122 die 'Expected echo_shell_vars to succeed, but failed'
123 fi
124 if ! test "$output" = 'HAVE_READLINE=
125READLINE_DIR=
126
127PREFIX=/usr/local
128DATAROOTDIR=
129
130STRIP_FLAGS=--gc-sections'; then
131 die "Unexpected echo_shell_vars output: $output"
132 fi
133
134 # have readline, no readline_dir
135 have_readline=1
136 output="$(echo_shell_vars)"
137 if ! test "$?" = 0; then
138 die 'Expected echo_shell_vars to succeed, but failed'
139 fi
140 if ! test "$output" = 'HAVE_READLINE=1
141READLINE_DIR=
142
143PREFIX=/usr/local
144DATAROOTDIR=
145
146STRIP_FLAGS=--gc-sections'; then
147 die "Unexpected echo_shell_vars output: $output"
148 fi
149
150 # have readline, readline_dir present
151 have_readline=1
152 readline_dir=/path/to/readline
153 output="$(echo_shell_vars)"
154 if ! test "$?" = 0; then
155 die 'Expected echo_shell_vars to succeed, but failed'
156 fi
157 if ! test "$output" = 'HAVE_READLINE=1
158READLINE_DIR=/path/to/readline
159
160PREFIX=/usr/local
161DATAROOTDIR=
162
163STRIP_FLAGS=--gc-sections'; then
164 die "Unexpected echo_shell_vars output: $output"
165 fi
166
167 # clean-up
168 detected_deps=''
169 have_readline=''
170 readline_dir=''
171 have_systemtap_sdt=''
172}
173
174soil_run() {
175 # Note: could use run-test-funcs
176
177 for func in \
178 test_cc_statements \
179 test_parse_flags \
180 test_echo_cpp \
181 test_echo_vars; do
182
183 echo " $func"
184 $func
185 echo ' OK'
186
187 done
188}
189
190"$@"