3 # (C) Copyright Vesa Karvonen 2004.
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE.)
10 TIMEFORMAT
='Time: %R seconds'
17 function check-and-add-preprocessor
{
18 if $1 >& /dev
/null
; then
19 availablePreprocessors
="[$2] $availablePreprocessors"
23 if ! test -f .preprocessor
; then
24 availablePreprocessors
=''
26 check-and-add-preprocessor
"cpp --help" cpp
27 check-and-add-preprocessor
"wave -v" wave
29 read -e -p "Choose preprocessor: $availablePreprocessors? "
30 if test "$(echo "$availablePreprocessors" | grep "\\[$REPLY\\]")" != "$availablePreprocessors" ; then
32 Sorry, \"$REPLY\" isn't one of the preprocessors:
34 $availablePreprocessors
36 If you wish to use another preprocessor, you need to customize this
37 script for the preprocessor, because there is no standard on the
38 command line options accepted by a preprocessor."
41 echo "$REPLY" > .preprocessor
42 echo "Wrote $REPLY to the .preprocessor file."
45 preprocessor
=$
(cat .preprocessor
)
47 function eval-in-cpp
{
52 $
(if test $debugFlag = 1 ; then echo '-DORDER_PP_DEBUG' ; fi) \
54 -I "../../chaos-pp/" \
55 -include "../inc/order/interpreter.h" \
56 -include "test-defs.h"
59 function eval-in-wave
{
61 $
(if test $debugFlag = 1 ; then echo '--define ORDER_PP_DEBUG' ; fi) \
63 --include "../../chaos-pp/" \
64 --forceinclude "order/interpreter.h" \
65 --forceinclude "test-defs.h"
82 echo "$tmp" |
sed "$@"
86 cat $dbFile |
wc -l |
sed 's# ##g'
90 head -n $
(($1+1)) |
tail -n1
93 function get-line-from
{
94 echo "$2" | get-line
$1
98 cat $dbFile | get-line
$1
102 echo "$1#$2#$3" >> $dbFile
106 function clean-test-db
{
107 local tmp
="$(cat $dbFile)"
108 echo "$tmp" |
sort |
uniq > $dbFile
111 function remove-test
{
112 local lines
=$
(test-cnt
)
113 local before
=$
(head -n $1 $dbFile)
114 local after
=$
(tail -n $
(($lines-1-$1)) $dbFile)
116 if test "$before" != "" ; then echo "$before" >> $dbFile ; fi
117 if test "$after" != "" ; then echo "$after" >> $dbFile ; fi
120 function replace-test
{
121 local lines
=$
(test-cnt
)
122 local before
=$
(head -n $1 $dbFile)
123 local after
=$
(tail -n $
(($lines-1-$1)) $dbFile)
125 if test "$before" != "" ; then echo "$before" >> $dbFile ; fi
126 add-test
"$2" "$3" "$4"
127 if test "$after" != "" ; then echo "$after" >> $dbFile ; fi
130 function preprocess-positive-tests
{
131 sed -e 's|^.*#.*#O.*$||g' \
133 -e 's|^\(.\+\)$|ORDER_PP(\1)|g' \
140 function differing-lines
{
143 grep -v -e "^\\($(echo -n "$2" | sed 's#\([^a-zA-Z0-9()?+|{, ]\)#\\\1#g' | nl -s '#' -v 0 | tr "\n" '$' | sed 's#\$#\\\|#g')\\)\$" | \
144 sed -e 's|#.*||g' -e 's|[ \t]||g' |
tr "\n" ' '
148 echo "Total of $(test-cnt) tests."
149 echo "Running positive tests..."
151 local allTerm
=$
(sed -e 's|#.*||g' $dbFile)
152 local allExpected
=$
(sed -e 's|^[^#]*#||g' -e 's|#.*$||g' $dbFile)
153 local allErrors
=$
(sed -e 's|.*#||g' $dbFile)
155 local posActual
=$
(preprocess-positive-tests
)
156 local posExpected
=$
(sed -e 's|^.*#.*#O.*$||g' -e 's|^[^#]*#||g' -e 's|#.*$||g' $dbFile)
158 echo "Comparing results..."
160 for i
in $
(differing-lines
"$posActual" "$posExpected") ; do
161 term
=$
(get-line-from
$i "$allTerm")
162 local result
=$
(get-line-from
$i "$posActual")
163 local expected
=$
(get-line-from
$i "$posExpected")
166 echo "Expected: $expected"
167 echo "Result: $result"
168 read -e -n 1 -p "[(U)se result | (R)emove test | Skip]? "
172 replace-test
$i "$term" "$result" "" ;;
181 echo "Running and comparing negative tests..."
183 local oldDebugFlag
=$debugFlag
186 for i
in $
(differing-lines
"$(sed -e 's|.*#.*#O.*|\$|g' -e 's|[^$]\+|#|g' $dbFile)" "$(sed -e 's|.\+|#|g' $dbFile)") ; do
187 term
=$
(get-line-from
$i "$allTerm")
188 local expectedResult
=$
(get-line-from
$i "$allExpected")
189 local expectedErrors
=$
(get-line-from
$i "$allErrors")
193 if test "$result#$errors" != "$expectedResult#$expectedErrors" ; then
195 echo "Expected result: $expectedResult"
196 echo "Actual result: $result"
197 echo "Expected error: $expectedErrors"
198 echo "Actual error: $errors"
199 read -e -n 1 -p "[(U)se result | (R)emove test | Skip]? "
203 replace-test
$i "$term" "$result" "$errors" ;;
213 debugFlag
=$oldDebugFlag
217 result
=$
(echo "ORDER_PP($term)" | spacify | eval-in
2>"$tmpFile" |
tail -n1)
218 resultChars
=$
(echo "$result" |
wc -m |
sed 's# ##g')
219 resultLines
=$
(echo "$result" |
wc -l |
sed 's# ##g')
220 messages
="$(cat "$tmpFile")"
221 if test -n "$messages" ; then
222 errors
=$
(echo "$messages" |
grep -o 'ORDER_PP_[a-zA-Z0-9_]\+' |
sort |
uniq |
tr $
'\n' ' ' |
sed 's# $##g')
228 function interactive-eval
{
230 if test "$REPLY" != "" ; then
238 if test -n "$messages" ; then
239 echo "Errors: $errors"
244 if test $
(($COLUMNS-9)) -lt $resultChars ; then
245 echo "The output contains $resultChars characters on $resultLines lines!"
246 read -e -n 1 -p "[(S)kip | (L)ess | Display]? "
249 echo "Result: $result" |
less ;;
253 echo "Result: $result" ;;
256 echo "Result: $result"
260 function interactive-trace
{
262 if test "$REPLY" != "" ; then
270 result
=$
(echo "(,,ORDER_PP_DEF($(echo "$term" | spacify)),8EXIT,)" | eval-in
)
273 while read -e -n 1 -p "[(#$steps) | Enter to step]? " ; do
274 if test "$REPLY" != "" ; then
280 result
=$
(echo "ORDER_PP_CM_DN_0 $result" | eval-in
)
283 if ! echo "$result" |
grep -q '^(' ; then
284 echo "[ Program stopped. ]"
290 function interactive-add-test
{
292 read -e -n 1 -p "Add [(N)o | Yes]? "
297 add-test
"$term" "$result" "$errors"
302 echo "Database: $dbFile"
303 if ! cp -r $dbFile $dbFile.bak
; then
304 echo "Backup failed. Terminating."
307 echo "Backed up database to: $dbFile.bak"
314 if test -z "$REPLY" ; then
315 if test "$#" -gt 0 ; then
316 REPLY
="$(echo "$1" | sed 's#^-*##g')"
319 read -e -n 1 -p "[(A)dd | (C)lean | (D)ebug | (M)ode: $debugFlag | (Q)uit | (S)how | (T)est | Eval]? "
324 interactive-add-test
;;
336 debugFlag
=$
((1-debugFlag)) ;;
341 REPLY
="$(echo "$REPLY" | sed 's#^.##g')"