-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.sh
executable file
·171 lines (154 loc) · 3.58 KB
/
tester.sh
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
MYSHELL="$PWD/mysh"
REFER="/bin/tcsh -f"
TRAPSIG=0
CAT=`which cat`
GREP=`which grep`
SED=`which sed`
RM=`which rm`
TR=`which tr`
HEAD=`which head`
TAIL=`which tail`
WC=`which wc`
CHMOD=`which chmod`
EXPR=`which expr`
MKDIR=`which mkdir`
CP=`which cp`
for i in `env | grep BASH_FUNC_ | cut -d= -f1`; do
f=`echo $i | sed s/BASH_FUNC_//g | sed s/%%//g`
unset -f $f
done
disp_test()
{
id=$1
$CAT tests | $GREP -A1000 "\[$id\]" | $GREP -B1000 "^\[$id-END\]" | $GREP -v "^\[.*\]"
}
run_script()
{
SC="$1"
echo "$SC" > /tmp/.tmp.$$
. /tmp/.tmp.$$
$RM -f /tmp/.tmp.$$
}
prepare_test()
{
local testfn="/tmp/.tester.$$"
local runnerfn="/tmp/.runner.$$"
local refoutfn="/tmp/.refer.$$"
local shoutfn="/tmp/.shell.$$"
WRAPPER="$runnerfn"
echo "#!/bin/bash" > $runnerfn
echo "$SETUP" >> $runnerfn
echo "/bin/bash -c '"$testfn" | "$MYSHELL" ; echo Shell exit with code \$?' > "$shoutfn" 2>&1" >> $runnerfn
echo "$CLEAN" >> $runnerfn
echo "$SETUP" >> $runnerfn
echo "$TCSHUPDATE" >> $runnerfn
echo "/bin/bash -c '"$testfn" | "$REFER" ; echo Shell exit with code \$?' > "$refoutfn" 2>&1" >> $runnerfn
echo "$CLEAN" >> $runnerfn
echo "#!/bin/bash" > $testfn
echo "$TESTS" | $TR "²" "\n" >> $testfn
chmod 755 $testfn
chmod 755 $runnerfn
}
load_test()
{
id=$1
debug=$2
SETUP=`disp_test "$id" | $GREP "SETUP=" | $SED s/'SETUP='// | $SED s/'"'//g`
CLEAN=`disp_test "$id" | $GREP "CLEAN=" | $SED s/'CLEAN='// | $SED s/'"'//g`
NAME=`disp_test "$id" | $GREP "NAME=" | $SED s/'NAME='// | $SED s/'"'//g`
TCSHUPDATE=`disp_test "$id" | $GREP "TCSHUPDATE=" | $SED s/'TCSHUPDATE='// | $SED s/'"'//g`
TESTS=`disp_test "$id" | $GREP -v "SETUP=" | $GREP -v "CLEAN=" | $GREP -v "NAME=" | $GREP -v "TCSHUPDATE=" | $GREP -v "TESTS=" | $TR "\n" "²" | $SED s/"²$"//`
prepare_test
$WRAPPER
nb=`$CAT /tmp/.refer.$$ | $GREP -v '^_=' | $GREP -v '^\[1\]' | $WC -l`
i=1
ok=1
while [ $i -le $nb ]
do
l=`$CAT /tmp/.refer.$$ | $GREP -v '^_=' | $GREP -v '^\[1\]' | $HEAD -$i | $TAIL -1`
a=`$CAT /tmp/.shell.$$ | $GREP -v '^_=' | $GREP -v '^\[1\]' | $GREP -- "$l$" | $WC -l`
if [ $a -eq 0 ]
then
ok=0
fi
i=`$EXPR $i + 1`
done
if [ $ok -eq 1 ]
then
if [ $debug -ge 1 ]
then
echo "Test $id ($NAME) : OK"
if [ $debug -eq 2 ]
then
echo "Output $MYSHELL :"
$CAT -e /tmp/.shell.$$
echo ""
echo "Output $REFER :"
$CAT -e /tmp/.refer.$$
echo ""
fi
else
echo "OK"
fi
else
if [ $debug -ge 1 ]
then
echo "Test $id ($NAME) : KO - Check output in /tmp/test.$$/$id/"
$MKDIR -p /tmp/test.$$/$id 2>/dev/null
$CP /tmp/.shell.$$ /tmp/test.$$/$id/mysh.out
$CP /tmp/.refer.$$ /tmp/test.$$/$id/tcsh.out
else
echo "KO"
fi
fi
}
if [ $TRAPSIG -eq 1 ]
then
for sig in `trap -l`
do
echo "$sig" | grep "^SIG" >/dev/null 2>&1
if [ $? -eq 0 ]
then
trap "echo Received signal $sig !" $sig
fi
done
fi
if [ ! -f tests ]
then
echo "No tests file. Please read README.ME" >&2
exit 1
fi
if [ ! -f $MYSHELL ]
then
echo "$MYSHELL not found" >&2
exit 1
fi
if [ $# -eq 2 ]
then
echo "Debug mode" >&2
echo "Shell : $MYSHELL" >&2
echo "Reference : $REFER" >&2
echo ""
fi
if [ $# -eq 0 ]
then
for lst in `cat tests | grep "^\[.*\]$" | grep -vi end | sed s/'\['// | sed s/'\]'//`
do
path_backup=$PATH
load_test $lst 1
export PATH=$path_backup
done
else
if [ $# -eq 1 ]
then
load_test $1 0
else
if [ "X$1" = "X-d" ]
then
load_test $2 2
else
load_test $1 2
fi
fi
fi