mescc: Add dir to include path.
[mes.git] / build-aux / check-mescc.sh
1 #! /bin/sh
2
3 # GNU Mes --- Maxwell Equations of Software
4 # Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 #
6 # This file is part of GNU Mes.
7 #
8 # GNU Mes is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or (at
11 # your option) any later version.
12 #
13 # GNU Mes is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Mes.  If not, see <http://www.gnu.org/licenses/>.
20
21 set -e
22 . ${srcdest}build-aux/config.sh
23 . ${srcdest}build-aux/trace.sh
24
25 MES=${MES-src/mes}
26 [ -z "$MESCC" ] && MESCC=scripts/mescc
27 GUILE=${GUILE-guile}
28 MES_PREFIX=${MES_PREFIX-mes}
29
30 HEX2=${HEX2-hex2}
31 M1=${M1-M1}
32 BLOOD_ELF=${BLOOD_ELF-blood-elf}
33 MES_SEED=${MES_SEED-../mes-seed}
34 MESCC=${MESCC-$(command -v mescc)}
35 [ -z "$MESCC" ] && MESCC=scripts/mescc
36 MES=${MES-$(command -v mes)}
37 [ -z "$MES" ] && MES=src/mes
38
39 if ! command -v $GUILE > /dev/null; then
40     GUILE=true
41 fi
42
43 tests="
44 t
45 00-exit-0
46 01-return-0
47 02-return-1
48 03-call
49 04-call-0
50 05-call-1
51 06-call-!1
52 07-include
53 08-assign
54 10-if-0
55 11-if-1
56 12-if-==
57 13-if-!=
58 14-if-goto
59 15-if-!f
60 16-if-t
61 20-while
62 21-char[]
63 22-while-char[]
64 23-pointer
65 30-strlen
66 31-eputs
67 32-compare
68 33-and-or
69 34-pre-post
70 35-compare-char
71 36-compare-arithmetic
72 37-compare-assign
73 38-compare-call
74 40-if-else
75 41-?
76 42-goto-label
77 43-for-do-while
78 44-switch
79 45-void-call
80 46-function-static
81 47-function-expression
82 48-function-destruct
83 49-global-static
84 4a-char-array
85 50-assert
86 51-strcmp
87 52-itoa
88 53-strcpy
89 54-argv
90 60-math
91 61-array
92 62-array
93 63-struct-cell
94 64-make-cell
95 65-read
96 70-printf
97 71-struct-array
98 72-typedef-struct-def
99 73-union
100 74-multi-line-string
101 75-struct-union
102 76-pointer-arithmetic
103 77-pointer-assign
104 78-union-struct
105 79-int-array
106 7a-struct-char-array
107 7b-struct-int-array
108 7c-dynarray
109 7d-cast-char
110 7e-struct-array-access
111 7f-struct-pointer-arithmetic
112 7g-struct-byte-word-field
113 7h-struct-assign
114 7i-struct-struct
115 7j-strtoull
116 7k-for-each-elem
117 7l-struct-any-size-array
118 7m-struct-char-array-assign
119 7n-struct-struct-array
120 7o-struct-pre-post
121 7p-struct-cast
122 7q-bit-field
123 7r-sign-extend
124 7s-struct-short
125 80-setjmp
126 81-qsort
127 82-define
128 83-heterogenoous-init
129 84-struct-field-list
130 85-sizeof
131 86-strncpy
132 87-sscanf
133 88-strrchr
134 90-strpbrk
135 91-fseek
136 92-stat
137 93-fread-fwrite
138 94-unsetenv
139 95-signal
140 96-strto
141 97-fopen
142 98-fopen
143 "
144
145 # 90: needs GNU, fails for mescc, passes for tcc
146 broken="$broken
147 7s-struct-short
148 "
149
150 # gcc not supported
151 CC=
152 set +e
153 expect=$(echo $broken | wc -w)
154 pass=0
155 fail=0
156 total=0
157 mkdir -p scaffold/tests
158 for t in $tests; do
159     if [ -z "${t/[012][0-9]-*/}" ]; then
160         LIBC=
161         MES_LIBS="-l none"
162     elif [ -z "${t/[34][0-9]-*/}" ]; then
163         LIBC=c-mini
164         MES_LIBS="-l c-mini"
165     elif [ -z "${t/[78][0-9a-z]-*/}" ]; then
166         LIBC=c+tcc
167         MES_LIBS="-l c+tcc"
168     elif [ -z "${t/9[0-9]-*/}" ]; then
169         LIBC=c+gnu
170         MES_LIBS="-l c+gnu"
171     else
172         LIBC=c
173         MES_LIBS=
174     fi
175     sh ${srcdest}build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
176     r=$?
177     total=$((total+1))
178     if [ $r = 0 ]; then
179         echo $t: [OK]
180         pass=$((pass+1))
181     else
182         echo $t: [FAIL]
183         fail=$((fail+1))
184     fi
185 done
186
187 [ $expect != 0 ] && echo "expect: $expect"
188 [ $fail != 0 ] && echo "failed: $fail"
189 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
190 echo "passed: $pass"
191 echo "total:  $total"
192 if [ $fail != 0 -a $fail -gt $expect ]; then
193     echo FAILED: $fail/$total
194     exit 1
195 elif [ $fail != 0 ]; then
196     echo PASS: $pass/$total
197 else
198     echo PASS: $total
199 fi