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 | # clean-up
|
84 | detected_deps=''
|
85 | }
|
86 |
|
87 | test_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=
|
108 | READLINE_DIR=
|
109 |
|
110 | PREFIX=/usr/local
|
111 | DATAROOTDIR=
|
112 |
|
113 | STRIP_FLAGS=--gc-sections'; then
|
114 | die "Unexpected echo_shell_vars output: $output"
|
115 | fi
|
116 |
|
117 | # have readline, no readline_dir
|
118 | have_readline=1
|
119 | output="$(echo_shell_vars)"
|
120 | if ! test "$?" = 0; then
|
121 | die 'Expected echo_shell_vars to succeed, but failed'
|
122 | fi
|
123 | if ! test "$output" = 'HAVE_READLINE=1
|
124 | READLINE_DIR=
|
125 |
|
126 | PREFIX=/usr/local
|
127 | DATAROOTDIR=
|
128 |
|
129 | STRIP_FLAGS=--gc-sections'; then
|
130 | die "Unexpected echo_shell_vars output: $output"
|
131 | fi
|
132 |
|
133 | # have readline, readline_dir present
|
134 | have_readline=1
|
135 | readline_dir=/path/to/readline
|
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
|
141 | READLINE_DIR=/path/to/readline
|
142 |
|
143 | PREFIX=/usr/local
|
144 | DATAROOTDIR=
|
145 |
|
146 | STRIP_FLAGS=--gc-sections'; then
|
147 | die "Unexpected echo_shell_vars output: $output"
|
148 | fi
|
149 |
|
150 | # clean-up
|
151 | detected_deps=''
|
152 | have_readline=''
|
153 | readline_dir=''
|
154 | have_systemtap_sdt=''
|
155 | }
|
156 |
|
157 | soil_run() {
|
158 | # Note: could use run-test-funcs
|
159 |
|
160 | for func in \
|
161 | test_cc_statements \
|
162 | test_parse_flags \
|
163 | test_echo_cpp \
|
164 | test_echo_vars; do
|
165 |
|
166 | echo " $func"
|
167 | $func
|
168 | echo ' OK'
|
169 |
|
170 | done
|
171 | }
|
172 |
|
173 | "$@"
|