-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathrun_test.sh
executable file
·132 lines (117 loc) · 3.46 KB
/
run_test.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
# This file execute tests for ribbit
TEMP_DIR=".tests"
if [ "$HOST_COMPILER" = "" ] && [ "$HOST_INTERPRETER" = "" ]; then
echo "Error, either HOST_COMPILER or HOST_INTERPRETER must be defined"
exit 1
fi
run_file () {
file=$1
out_file=$2
argv=$3
if [ "${HOST_INTERPRETER}" != "" ]; then
${HOST_INTERPRETER} $file $argv > $out_file;
else
${HOST_COMPILER} $file.exe $file;
./$file.exe $argv > $out_file;
fi;
}
get_attribute(){
test_file=$1
attribute=$2
echo `sed -n -e "/;;;$attribute:/p" $test_file | sed -e "s/^;;;$attribute://" | tr '\n' ',' | sed -e 's/,$//'`
}
test_path=$1
cleanup=`get_attribute $test_path "cleanup"`
argv=`get_attribute $test_path "argv"`
input=`get_attribute $test_path "input"`
mkdir -p $TEMP_DIR
prog=$TEMP_DIR/$(basename $1)
echo "-------------------- $test_path : \c"
test_ran="0"
success="1"
for tag in $(echo $TEST_TAGS | tr ' ' '\n'); do
if [ "$tag" = "core" ]; then
runs=`get_attribute $test_path "run"`
else
runs=`get_attribute $test_path "$tag-run"`
fi
for feature in "" $(echo $TEST_FEATURES | tr ',' '\n' | sed -e "s/ /,/g" ); do
for run in $(echo $runs | tr ',' '\n' | sed -e "s/ /,/g"); do
echo ".\c"
run=`echo $run | sed -e "s/,/ /g"`
feature=`echo $feature | sed -e "s/,/ /g"`
# Compile test
cmd="$RSC_COMPILER -t $HOST $run $feature -o $prog.$HOST $test_path"
`$cmd` > $prog.err 2>&1
if [ "$?" != "0" ]; then
if [ "$success" = "1" ]; then
success=0
echo "❌"
fi
echo ">>>>>> [run: '$run' features: '$feature' input: '$input' argv: '$argv']"
echo ">>>>>> Error during compilation (see $prog.err)"
echo ">>>>>> Compile with : '$cmd'"
echo ">>>>>> See error below."
cat $prog.err
echo ""
continue
fi
# Run test
echo $input | run_file $prog.$HOST $prog.out $argv > $prog.err 2>&1
if [ "$?" != 0 ]; then
if [ $success -eq 1 ]; then
success=0
echo "❌"
fi
echo ">>>>>> [run: '$run' features: '$feature' input: '$input' argv: '$argv']"
echo ">>>>>> Error during test execution (see $prog.err)"
echo ">>>>>> Compile with : '$cmd'"
echo ">>>>>> See error below."
tail -n 10 $prog.out
cat $prog.err
echo ""
continue
fi
# Check output
sed -e '1,/;;;expected:/d' -e 's/^;;;//' $test_path | diff - $prog.out > $prog.diff 2>&1;
if [ "$?" = "0" ]; then
test_ran=1
else
if [ "$success" = "1" ]; then
success=0
echo "❌"
fi
echo ">>>>>> [run: '$run' features: '$feature' input: '$input' argv: '$argv']"
echo ">>>>>> Results doesn't match expected value (see See $prog.diff)"
echo ">>>>>> Compile with : '$cmd'"
echo ">>>>>> See error below."
cat $prog.diff
echo ""
test_err=1
fi
# Cleanup
if [ "$cleanup" != "" ]; then
sh -c "$cleanup" > $prog.err 2>&1;
if [ "$?" != "0" ]; then
if [ "$success" = "1" ]; then
success=0
echo "❌"
fi
echo ">>> $test_path [options: $run]"
tail -n 10 $prog.err
echo "Error during cleaning up : see $prog.err for more details."
fi;
fi;
done
done
done
if [ $success -eq 1 ]; then
if [ $test_ran -eq 1 ]; then
echo "✅"
else
echo "skipped"
fi
exit 0;
else
exit 1;
fi