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

184 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=
126PREFIX=/usr/local
127DATAROOTDIR=
128STRIP_FLAGS=--gc-sections'; then
129 die "Unexpected echo_shell_vars output: $output"
130 fi
131
132 # have readline, no readline_dir
133 have_readline=1
134 output="$(echo_shell_vars)"
135 if ! test "$?" = 0; then
136 die 'Expected echo_shell_vars to succeed, but failed'
137 fi
138 if ! test "$output" = 'HAVE_READLINE=1
139READLINE_DIR=
140PREFIX=/usr/local
141DATAROOTDIR=
142STRIP_FLAGS=--gc-sections'; then
143 die "Unexpected echo_shell_vars output: $output"
144 fi
145
146 # have readline, readline_dir present
147 have_readline=1
148 readline_dir=/path/to/readline
149 output="$(echo_shell_vars)"
150 if ! test "$?" = 0; then
151 die 'Expected echo_shell_vars to succeed, but failed'
152 fi
153 if ! test "$output" = 'HAVE_READLINE=1
154READLINE_DIR=/path/to/readline
155PREFIX=/usr/local
156DATAROOTDIR=
157STRIP_FLAGS=--gc-sections'; then
158 die "Unexpected echo_shell_vars output: $output"
159 fi
160
161 # clean-up
162 detected_deps=''
163 have_readline=''
164 readline_dir=''
165 have_systemtap_sdt=''
166}
167
168soil_run() {
169 # Note: could use run-test-funcs
170
171 for func in \
172 test_cc_statements \
173 test_parse_flags \
174 test_echo_cpp \
175 test_echo_vars; do
176
177 echo " $func"
178 $func
179 echo ' OK'
180
181 done
182}
183
184"$@"