Test must not expose non-determinism.
[wiggle/upstream.git] / dotest
blob1b3a44e0facfccb67842ff825337785571cf098d
1 #!/usr/bin/env bash
3 # Redirect for non-GNU time systems
4 if [ "xx$TIME_CMD" = "xx" ]
5 then
6 time_cmd=/usr/bin/time
7 else
8 time_cmd=$TIME_CMD
9 fi
11 dir=$PWD
13 while [ ! -f $dir/wiggle ]
15 if [ -z "$dir" ]; then
16 echo >&2 Cannot find wiggle program : $WIGGLE
17 exit 1
19 dir=${dir%/*}
20 done
21 export WIGGLE=$dir/wiggle
23 if [ -d tests ]
24 then cd tests
27 TIME="$time_cmd -o .time -f %U"
28 if $TIME true > /dev/null 2>&1
29 then :
30 else TIME=
32 vallog=/tmp/valg.log-$$
33 > $vallog
34 if [ " $1" = " valgrind" ]; then
35 TIME="valgrind --log-file=$vallog"
37 status=0
38 ok=0
39 fail=0
41 # Avoid non-determinism cause by CPU speed
42 export WIGGLE_LOOPCOUNT=5000
44 find . -name core | xargs rm -f
45 list=$(find . -type f \( -name script -o -name diff -o -name ldiff \
46 -o -name rediff -o -name merge -o -name wmerge -o -name lmerge \
47 -o -name replace -o -name Wmerge -o -name bmerge \)
49 for path in $list
51 dir=${path%/*}
52 base=${path##*/}
54 cd $dir
55 > .time
56 case $base in
57 script ) ./script ;;
58 diff ) if [ -f new ]
59 then $TIME $WIGGLE -dw orig new | diff -u diff - ; xit=$?
60 else $TIME $WIGGLE -dwp1 orig patch | diff -u diff - ; xit=$?
63 ldiff ) if [ -f new ]
64 then $TIME $WIGGLE -dl orig new | diff -u ldiff - ; xit=$?
65 else $TIME $WIGGLE -dlp1 orig patch | diff -u ldiff - ; xit=$?
68 reldiff ) $TIME $WIGGLE -dl patch | diff -u reldiff - ; xit=$?
70 rediff ) $TIME $WIGGLE -dw patch | diff -u rediff - ; xit=$?
72 merge ) if [ -f patch ]
73 then $TIME $WIGGLE -m orig patch | diff -u merge - ; xit=$?
74 elif [ -f new ]
75 then $TIME $WIGGLE -m orig new new2 | diff -u merge - ; xit=$?
76 else $TIME $WIGGLE -m orig | diff -u merge - ; xit=$?
79 replace ) cp orig orig.tmp
80 if [ -f patch ]
81 then $TIME $WIGGLE -mr orig.tmp patch
82 else $TIME $WIGGLE -mr orig.tmp new new2
84 diff -u merge orig.tmp ; xit=$?
85 rm orig.tmp orig.tmp.porig
87 lmerge ) if [ -f patch ]
88 then $TIME $WIGGLE -ml orig patch | diff -u lmerge - ; xit=$?
89 else $TIME $WIGGLE -ml orig new new2 | diff -u lmerge - ; xit=$?
92 wmerge ) if [ -f patch ]
93 then $TIME $WIGGLE -mw orig patch | diff -u wmerge - ; xit=$?
94 else $TIME $WIGGLE -mw orig new new2 | diff -u wmerge - ; xit=$?
97 Wmerge ) if [ -f patch ]
98 then $TIME $WIGGLE -mW orig patch | diff -u Wmerge - ; xit=$?
99 else $TIME $WIGGLE -mW orig new new2 | diff -u Wmerge - ; xit=$?
102 bmerge ) if [ -f patch ]
103 then $TIME $WIGGLE -mbw orig patch | diff -u bmerge - ; xit=$?
104 else $TIME $WIGGLE -mbw orig new new2 | diff -u bmerge - ; xit=$?
107 esac
108 if [ $xit = 0 ]; then msg=SUCCEEDED; else msg=FAILED; fi
109 if grep 'ERROR SUMMARY: [1-9]' $vallog > /dev/null 2>&1
110 then msg="$msg WITH VALGRIND ERRORS"; xit=1
112 echo $path $msg `grep -v 'Command exited' .time 2> /dev/null`
113 rm -f .time
114 exit $xit
116 if [ $? = 0 ]
117 then let ok++;
118 else status=1 ; let fail++
120 done
121 find . -name core -ls
122 echo $ok succeeded and $fail failed
123 exit $status