nitiwiki: update results and report test error
[nit.git] / contrib / nitiwiki / tests / tests.sh
1 #!/bin/bash
2
3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 #
5 # Copyright 2014 Alexandre Terrasa <alexandre@moz-code.org>.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18
19 BIN=../bin
20 OUT=./out
21 RES=./res
22
23 # check args files
24 test_args()
25 {
26 local test="$1"
27 local args=`cat $test.args`
28 local outdir=$OUT/$test.files
29
30 echo $BIN/$args > $OUT/$test.bin
31 chmod +x $OUT/$test.bin
32 OUTDIR=$outdir $OUT/$test.bin > $OUT/$test.res 2> $OUT/$test.err
33
34 if [ -r $outdir ]; then
35 ls -aR $outdir >> $OUT/$test.res
36 fi
37
38 diff $OUT/$test.res $RES/$test.res > $OUT/$test.diff 2> /dev/null
39 }
40
41 # return
42 # 0 if the sav not exists
43 # 1 if the file does match
44 # 2 if the file does not match
45 check_result() {
46 local test="$1"
47
48 if [ ! -r "$RES/$test.res" ]; then
49 return 0
50 elif [ ! -s $OUT/$test.diff ]; then
51 return 1
52 else
53 return 2
54 fi
55 }
56
57 echo "Testing..."
58 echo ""
59
60 rm -rf $OUT 2>/dev/null
61 mkdir $OUT 2>/dev/null
62
63 all=0
64 ok=0
65 ko=0
66 sk=0
67
68 for file in `ls *.args`; do
69 ((all++))
70 test="${file%.*}"
71 echo -n "* $test: "
72
73 test_args $test
74 check_result $test
75
76 case "$?" in
77 0)
78 echo "skip ($test.res not found)"
79 ((sk++))
80 continue;;
81 1)
82 echo "success"
83 ((ok++))
84 ;;
85 2)
86 echo "error (diff $OUT/$test.res $RES/$test.res)"
87 ((ko++))
88 ;;
89 esac
90 done
91 echo ""
92 echo "==> success $ok/$all ($ko tests failed, $sk skipped)"
93
94 # return result
95 test "$ok" == "$all"