aboutsummaryrefslogtreecommitdiff
path: root/tests/runtests.sh
blob: cac11847f80d7d93d88f31fbfd501a3e9153fda7 (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
#!/bin/sh

## TODO:
##  find zexy (either in ../src or ../)
##  if it is not there, assume it is split into externals

if [ "x${PD}" = "x" ]
then
 PD=pd
fi

if which ${PD} > /dev/null
then
 :
else
 echo "Pd is needed to run tests" 1>&2
 echo "you can specify the full binary in the PD variable" 1>&2
 exit 77
fi

echo running tests in ${TESTDIR:=.}


SUFFIX=$(date +%y%m%d-%H%M%S)
RUNTESTS_FINAL_LOG=runtest-${SUFFIX}.log


RUNTESTS_TXT=runtests.txt
if which tempfile > /dev/null
then
  RUNTESTS_LOG=$(tempfile)
else
  RUNTESTS_LOG=tmp$$.log
fi

LIBFLAGS="-path ../src/.libs/:../src/:../ -lib zexy -path ../abs/:${TESTDIR}:."

list_tests() {
#  find . -mindepth 2  -name "*.pd" | sed 's|\.pd$|;|' 
 ls -1 ${TESTDIR}/*/*.pd | sed 's|\.pd$|;|'
}

debug() {
 :
if [ "x${DEBUG}" = "xyes" ]; then echo $@; fi
}


evaluate_tests() {
 local logfile
 local testfile
 local numtests

 testfile=$1
 logfile=$2

 debug "now evaluating results in ${logfile} (${testfile}"

 numtests=$(grep -c . ${testfile})
 numpass=$(egrep -c "regression-test: (.*/fail.*: failed|.*: OK)$" ${logfile})
 numfail=0
 failtests=""
 for t in $(egrep "regression-test: .*: (failed|OK)$" ${logfile} | egrep -v "regression-test: (.*/fail.*: failed|.*: OK)$" | awk '{print $2}')
 do
  failtests="${failtests} ${t%:}"
  let numfail=numfail+1
 done
 debug "number of tests = ${numtests}"
 echo "regression-test: ======================================" >>  ${logfile}
 echo "regression-test: ${numtests} regression-tests total" >>  ${logfile}
 echo "regression-test: ${numpass} regression-tests passed" >>  ${logfile}
 echo "regression-test: ${numfail} regression-tests failed" >>  ${logfile}
 echo "regression-test: ======================================" >>  ${logfile}
 if [ "x${failtests}" != "x" ]; then
  echo "regression-test: failed tests: ${failtests}" >> ${logfile}
 fi
 debug "show results"
 cat ${logfile} | egrep "^regression-test: " | sed -e 's/^regression-test: //'
}


run_nogui() {
 debug "running test without gui"
 ${PD} ${LIBFLAGS} -nogui runtests_nogui.pd > ${RUNTESTS_LOG} 2>&1 
 SUCCESS=$?
 debug "testing done"
 evaluate_tests ${RUNTESTS_TXT} ${RUNTESTS_LOG}
 debug "testing finished"
}

run_withgui() {
 debug "running test with gui"
 ${PD} ${LIBFLAGS} -stderr runtests.pd 2>&1 | tee ${RUNTESTS_LOG}
 SUCCESS=$?
 echo "testing completed, no evaluation will be done; see ${RUNTESTS_LOG} for results"
}

list_tests > ${RUNTESTS_TXT}

USEGUI=""
DEBUG=""

while [ "x$#" != "x0" ]
do
 if test "x$1" = "x-gui"; then
  USEGUI="yes"
 fi
 if test "x$1" = "x-debug"; then
  DEBUG="yes"
 fi
 if test "x$1" = "x-d"; then
  DEBUG="yes"
 fi
 if test "x$1" = "x-nolog"; then
  RUNTESTS_FINAL_LOG=
 fi
 shift
done

SUCCESS=0
if [ "x${USEGUI}" = "xyes" ]; then
 run_withgui
else
 run_nogui
fi

if [ "x${RUNTESTS_NOLOG}" != "x" ]; then
  RUNTESTS_FINAL_LOG=
fi
if [ "x${RUNTESTS_FINAL_LOG}" = "x" ]; then
 :
else
 cat ${RUNTESTS_LOG} >> ${RUNTESTS_FINAL_LOG}
fi

if [ "x${RUNTESTS_FINAL_LOG}" = "x${RUNTESTS_LOG}" ]; then
 :
else
 rm -f ${RUNTESTS_LOG}
fi

exit ${SUCCESS}