summaryrefslogtreecommitdiff
path: root/autoopts/test/defs.in
blob: d7669abad85b72e41325e9a84a0e78894c19dfa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#! /bin/echo this_file_should_be_sourced,_not_executed
#  -*- Mode: Shell-script -*-
#
# defs --- define the environment for autogen tests.
#
# Time-stamp:     "2012-05-13 16:02:07 bkorb"
# Author:         Bruce Korb <bkorb@gnu.org>
##
##  This file is part of AutoOpts, a companion to AutoGen.
##  AutoOpts is free software.
##  AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved
##
##  AutoOpts is available under any one of two licenses.  The license
##  in use must be one of these two and the choice is under the control
##  of the user of the license.
##
##   The GNU Lesser General Public License, version 3 or later
##      See the files "COPYING.lgplv3" and "COPYING.gplv3"
##
##   The Modified Berkeley Software Distribution License
##      See the file "COPYING.mbsd"
##
##  These files have the following md5sums:
##
##  43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3
##  06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3
##  66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
#  C O N F I G U R E D   V A L U E S
#
# Make sure srcdir is an absolute path.  Supply the variable
# if it does not exist.  We want to be able to run the tests
# stand-alone!!
#
cfg_vals()
{
  case `uname -s` in
  SunOS )
    if test "X$BASH_VERSION" = X
    then
      # On Solaris, make certain we do not use /bin/sh
      sh=`which bash`
      test "X$sh" = X && sh=/usr/xpg4/bin/sh
      BASH_VERSION=not-good-enough
      export BASH_VERSION
      exec $sh "$0" "$@"
    fi
    ;;
  esac

  script_name=$1
  set -a
  . ${top_builddir}/config/shdefs
  progname=`echo "$script_name" | ${SED} 's,^.*/,,'`
  testname=`echo "$progname" | ${SED} 's,\..*$,,'`
  test_name=`echo ${testname} | ${SED} 's/-/_/g'`
  PS4=">${testname}-\${FUNCNAME}> "
  test -z "$srcdir"       && exit 1
  srcdir=`cd $srcdir >/dev/null && pwd`
  ( exec 2>/dev/null; ulimit -c unlimited ) && \
    ulimit -c unlimited

  test -z "${CFLAGS}"     && CFLAGS='@CFLAGS@'
  CFLAGS="${CFLAGS} @DEFS@"
  test -z "${testsubdir}" && testsubdir=testdir
  test -z "${PAGER}"      && PAGER=more
  nl='
' ht='	'

  stdopts=${top_srcdir}/autoopts/test/stdopts.def
  test_main=yes
  use_flags=true
  sed_omit_license="/-\*- buffer-read-only:/,/^ \*\//d"
  TERM=''
  set +a

  (
    test_local() {
      local local_works=yes
    }
    test_local
  ) || eval 'local() { : ; }'
 
  vars=`set | ${SED} -n '/^\(LANG\|LC_[A-Z_]*\)=/s/=.*//p'` 2>/dev/null
  test "X$vars" = X || unset $vars
}

#  If only the "rm(1)" command could be relied upon....
#
purge()
{
  rm -rf ${*} 2>/dev/null
  bad=''
  for f
  do test -f ${f} -o -d ${f} && bad="${bad} ${f}"
  done
  test -z "$bad" && return 0

  set -- $bad
  test "x${RANDOM}" = "x${RANDOM}" && RANDOM=`expr 0${RANDOM} + 1 2>/dev/null`

  f=ZZPURGE-${1}-${RANDOM}-$$
  if test $# -gt 1
  then mkdir ${f}
       mv $* ${f}/.
  else mv $1 ${f}
  fi
}

init_tests()
{
  logfile=`pwd`/testdir/${testname}.log
  exec 8>&2 1>${logfile} 2>&1

  TMPDIR=`pwd`/testdir/${testname}-tmpd
  mkdir ${TMPDIR}

  f=`\cd ${LIBGUILE_PATH}/../bin && pwd`
  PATH=${f}:${PATH}
  echo PATH is ${PATH} >&2

  builddir=`pwd`
  testsubdir=testdir
  CFLAGS=`echo ${CFLAGS} | \
    ${SED} "s/-Werror[^ ${ht}]*//g;s/-Wextra//g"`

  lo_dir=${top_builddir}/autoopts
  test -d ${lo_dir}/.libs && lo_dir=${lo_dir}/.libs
  test "X${LD_LIBRARY_PATH}" = X || LD_LIBRARY_PATH=:${LD_LIBRARY_PATH}
  LD_LIBRARY_PATH=${lo_dir}:${LIBGUILE_PATH}${LD_LIBRARY_PATH}

  case ${AG_VERSION} in
  *pre* ) GUILE_WARN_DEPRECATED=detailed ;;
  *     ) GUILE_WARN_DEPRECATED=no ;;
  esac

  case "$LIB" in
  *-lgen* ) : ;;
  * )
    for f in /usr/lib*/libgen.so /lib*/libgen.so
    do
      test -f $f && {
        LIB="${LIB} -lgen"
        break
      }
    done
    ;;
  esac
  lo_lib=`find ${lo_dir} -type f -name libopts*.${OBJEXT}`
  LIB="${lo_lib} ${LIB}"

  AG_L=run_ag\ ao
  agl_opts="-L${top_builddir}/autoopts/tpl -L${top_srcdir}/autoopts/tpl"

  export TMPDIR PATH LD_LIBRARY_PATH \
         GUILE_WARN_DEPRECATED LIB AG_L agl_opts \
         CC LIBGUILE AG_VERSION
}

be_silent()
{
  setx=:
  VERBOSE=false
  purge testdir

  # Sometimes, MSDos FS cannot even rename the directory!!
  #
  if test -d testdir
  then purge testdir/* testdir/.??*
  else msg=echo
       mkdir testdir || exit 1
  fi

  run_ag()
  {
    local opts=''
    shift

    case " $* " in
    *' -L'* ) : ;;
    * ) opts="${agl_opts}" ;;
    esac

    ${AGexe} ${opts} "$@"
  }

  init_tests
}

be_verbose()
{
  set -x
  setx='set -x'
  msg=:
  VERBOSE=true
  test -d testdir || mkdir testdir || exit 1

  run_ag()
  {
    local tfile=${testname}-aglog-${1}-$$.log
    shift
    local opts=''
    local tr="--trace=every --trace-out=>>${tfile}"

    case " $* " in
    *' -L'* ) : ;;
    * ) opts="${agl_opts}" ;;
    esac

    MALLOC_CHECK_=2 \
      ${AGexe} ${opts} ${tr} "$@"
  }

  init_tests
}

cfg_inc()
{
  cd testdir || {
    echo "Cannot make or change into testdir" >&8
    exit 1
  }
  testsubdir=`pwd`

  dirs=`
  for f in ${top_builddir} ${top_srcdir}
  do
    for d in . autoopts agen5
    do
      cd $f/$d
      pwd >&9
      cd -
    done 9>&1 1>/dev/null
  done | sort -u | ${SED} 's/^/-I/'`

  INC=`echo ${dirs} ${CPPFLAGS}`

  : "=== Running $progname for ${testname} using ${SHELL} ==="
  chmod +w * > /dev/null 2>&1 || :
  ${VERBOSE} && SHELLX="${SHELL} -x" || SHELLX="${SHELL}"
}

clean_help() {
  test -z "$sedcmd" && s= || s="${sedcmd}${nl}"
  s="${s}/^Packaged by/d${nl}"
  s="${s}/^Report .* bugs to/d${nl}"
  s="${s}/[Pp]lease send bug reports/d${nl}"
  s="${s}/^[ ${ht}]*\$/d"

  ${SED} "${s}"
}

compile()
{
  ${setx}
  test "X${Csrc}"  = "X" && Csrc="${testname}"
  test "X${Cexe}"  = "X" && Cexe="${Csrc}"
  test "X${Dnam}"  = "X" && Dnam="${testname}"

  d=`echo TEST_TEST_${Dnam}_OPTS | /usr/bin/tr '[a-z]-' '[A-Z]_'`
  cc_cmd="${CC} ${CFLAGS} -D$d ${INC} -o ${Cexe} ${Csrc}.c ${LIB}"
  eval ${cc_cmd} || \
    failure cannot compile ${Csrc}.c
  if test $# -gt 0
  then
    ./${Cexe} ${*} ${dosed} || \
      failure cannot obtain help output for ${Csrc}
  fi | clean_help > ${Csrc}.help    
  Csrc='' Cexe='' Dnam=''
}

cleanup()
{
  trap '' 15
  ${setx}
  ${VERBOSE} || {
    cd ${builddir}
    purge testdir
    test -d testdir && mv testdir ZZJUNK-$$
  }
  ${msg} ${testname} done
}

# A standard failure function
#
failure()
{
  trap '' 15
  ${setx}
  cd ${testsubdir}
  if test -d ../FAILURES
  then ( \cd ../FAILURES ; purge -rf ${testname}* .*${testname}* )
  else mkdir ../FAILURES ; fi

  exec > /dev/tty 2>&8
  cat ${logfile} >&2

  {
    mv -f ${testname}* .*${testname}* ../FAILURES || :
  } 2>/dev/null
  for f in core*
  do test -f ${f} && mv -f ${f} ../FAILURES/${testname}-${f} ; done

  echo FAILURE: "$*" >&8
  exit 1
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

cfg_vals $0

case "${VERBOSE}" in
'' | [Nn]* | 0 | [Ff]* )
    be_silent ;;

[Yy]* | [0-9] | [Tt]* )
    be_verbose ;;

* )
    case "$-" in
    *x* ) be_verbose ;;
     *  ) be_silent ;;
    esac
esac

cfg_inc

trap "failure 'test ${testname} killed on timeout'" 15
( ( exec > /dev/null 2>&1 </dev/null
    test -z "${kill_delay}" && kill_delay=3
    kill_delay=`expr $kill_delay '*' $AG_TIMEOUT`
    sleep ${kill_delay}
    ps -p $$ || exit
    kill -15 $$
    sleep 1
    ps -p $$ || exit
    mv -f `dirname $logfile` ${builddir}/FAILED-${testname}
    kill -9 $$
) &
)

## Local Variables:
## mode: shell-script
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

# defs.in ends here