aboutsummaryrefslogtreecommitdiff
path: root/scripts/test.sh
blob: cdfe3bdb022e8dd4068e885c870637595b353827 (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
#!/bin/bash

source scripts/runtest.sh
source scripts/portability.sh

TOPDIR="$PWD"
export FILES="$PWD"/tests/files

trap 'kill $(jobs -p) 2>/dev/null; exit 1' INT

rm -rf generated/testdir
mkdir -p generated/testdir/testdir

if [ -z "$TEST_HOST" ]
then
  if [ $# -ne 0 ]
  then
    PREFIX=generated/testdir/ scripts/single.sh "$@" || exit 1
  else
    make install_flat PREFIX=generated/testdir || exit 1
  fi
fi

cd generated/testdir
PATH="$PWD:$PATH"
TESTDIR="$PWD"
export LC_COLLATE=C

[ -f "$TOPDIR/generated/config.h" ] &&
  export OPTIONFLAGS=:$(echo $($SED -nr 's/^#define CFG_(.*) 1/\1/p' "$TOPDIR/generated/config.h") | $SED 's/ /:/g')

do_test()
{
  cd "$TESTDIR" && rm -rf testdir && mkdir testdir && cd testdir || exit 1
  CMDNAME="${1##*/}"
  CMDNAME="${CMDNAME%.test}"
  if [ -z "$TEST_HOST" ]
  then
    C="$TESTDIR/$CMDNAME"
    [ ! -e "$C" ] && echo "$CMDNAME disabled" && return
  else
    C="$(which $CMDNAME 2>/dev/null)"
    [ -z "$C" ] && printf '%s\n' "$SHOWSKIP: no $CMDNAME" && return
  fi
  C="$(dirname $(realpath "$C"))/$CMDNAME"

  . "$1"
}

if [ $# -ne 0 ]
then
  for i in "$@"
  do
    do_test "$TOPDIR"/tests/$i.test
  done
else
  for i in "$TOPDIR"/tests/*.test
  do
    [ -z "$TEST_ALL" ] && [ ! -x "$i" ] && continue
    do_test "$i"
  done
fi

[ $FAILCOUNT -eq 0 ]