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