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