summaryrefslogtreecommitdiff
path: root/tests/twisted/run-test.sh.in
blob: d0574fa9073fc9b51889d6456168e6ebcbb7cdcf (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
#!/bin/sh

# This script assumes that it is run in a temporary directory where it can
# create and delete subdirectories for files, logs, etc., but other users
# cannot write (for instance, /tmp is unsuitable, but
# the directory created by `mktemp -d /tmp/test.XXXXXXXXXX` is fine).
#
# During "make check" or "make installcheck" it runs in
# ${top_builddir}/tests/twisted.
#
# During installed testing, the test environment must run it in a
# suitable location.

set -e

CHECK_TWISTED_CURDIR="`pwd`"
export CHECK_TWISTED_CURDIR

if test "x$CHECK_TWISTED_UNINSTALLED" = x; then
  script_fullname=`readlink -e "@twistedtestsdir@/run-test.sh"`
  if [ `readlink -e "$0"` != "$script_fullname" ] ; then
    echo "Bail out! This script is meant to be installed at $script_fullname"
    exit 1
  fi

  G_TEST_SRCDIR="@twistedtestsdir@"
  export G_TEST_SRCDIR
  G_TEST_BUILDDIR="@twistedtestsdir@"
  export G_TEST_BUILDDIR

  PYTHONPATH="${G_TEST_SRCDIR}"
  export PYTHONPATH
else
  if ! test -d "$G_TEST_SRCDIR"; then
    echo "Bail out! G_TEST_SRCDIR must be set and absolute"
    exit 1
  fi
  if ! test -d "$G_TEST_BUILDDIR"; then
    echo "Bail out! G_TEST_BUILDDIR must be set and absolute"
    exit 1
  fi

  PYTHONPATH="${G_TEST_SRCDIR}:${G_TEST_BUILDDIR}"
  export PYTHONPATH
fi

config_file="${G_TEST_BUILDDIR}/tools/tmp-session-bus.conf"

SALUT_DEBUG=all
export SALUT_DEBUG
GIBBER_DEBUG=all
export GIBBER_DEBUG
WOCKY_DEBUG=all
export WOCKY_DEBUG

G_MESSAGES_DEBUG=all
export G_MESSAGES_DEBUG

XDG_CONFIG_DIRS="${G_TEST_SRCDIR}"
export XDG_CONFIG_DIRS

if [ -n "$1" ] ; then
  list="$1"
else
  list=$(cat "${G_TEST_BUILDDIR}"/twisted-tests.list)
fi

if [ -z "$SALUT_TEST_REAL_AVAHI" ]; then
  also_for_system="--also-for-system";
fi

n=0
for i in $list ; do
  n=$(( $n + 1 ))
done

echo "1..$n"

i=0
n_failed=0
for t in $list ; do
  i=$(( $i + 1 ))
  echo "# Testing $i/$n: $t ..."

  tmp="${CHECK_TWISTED_CURDIR}/tmp-`echo $t | tr ./ __`"
  rm -fr "$tmp"
  mkdir "$tmp"

  CHECK_TWISTED_LOG_DIR="${tmp}"
  export CHECK_TWISTED_LOG_DIR
  XDG_CONFIG_HOME="${tmp}/config"
  export XDG_CONFIG_HOME
  XDG_DATA_HOME="${tmp}/localshare"
  export XDG_DATA_HOME
  XDG_DATA_DIRS="${tmp}/share:${G_TEST_SRCDIR}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  export XDG_DATA_DIRS
  XDG_CACHE_HOME="${tmp}/cache"
  export XDG_CACHE_HOME
  XDG_CACHE_DIR="${tmp}/cache"
  export XDG_CACHE_DIR
  SALUT_LOGFILE="${tmp}/cm.log"
  export SALUT_LOGFILE

  CHECK_TWISTED_VERBOSE=1
  export CHECK_TWISTED_VERBOSE

  e=0
  sh "${G_TEST_SRCDIR}/tools/with-session-bus.sh" \
    ${CHECK_TWISTED_SLEEP} \
    --config-file="${config_file}" \
    ${also_for_system} \
    -- \
    @TEST_PYTHON@ -u "${G_TEST_SRCDIR}/$t" \
    > "$tmp"/test.log 2>&1 || e=$?
  case "$e" in
    (0)
      echo "ok $i - $t"
      if test -z "$CHECK_TWISTED_KEEP_TEMP"; then
        rm -fr "$tmp"
      fi
      ;;
    (77)
      echo "ok $i # SKIP $t"
      (
        cd $tmp && for x in *.log; do
          echo "# ===== log file: $x ====="
          sed 's/^/# /' "$x"
        done
        echo "# ===== end of log files for $t ====="
      )
      if test -z "$CHECK_TWISTED_KEEP_TEMP"; then
        rm -fr "$tmp"
      fi
      ;;
    (*)
      n_failed=$(( $n_failed + 1 ))
      echo "not ok $i - $t ($e)"
      (
        cd $tmp && for x in *.log; do
          echo "# ===== log file: $x ====="
          sed 's/^/# /' "$x"
        done
        echo "# ===== end of log files for $t ====="
      )
      ;;
  esac
done

if test $n_failed != 0; then
  echo "# Tests run: $n; tests failed: $n_failed"
  exit 1
else
  exit 0
fi