mescc: Mes C Library: Fix qsort to support duplicate entries.
[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 51-strncmp
88 52-itoa
89 53-strcpy
90 54-argv
91 60-math
92 61-array
93 62-array
94 63-struct-cell
95 64-make-cell
96 65-read
97 70-printf
98 71-struct-array
99 72-typedef-struct-def
100 73-union
101 74-multi-line-string
102 75-struct-union
103 76-pointer-arithmetic
104 77-pointer-assign
105 78-union-struct
106 79-int-array
107 7a-struct-char-array
108 7b-struct-int-array
109 7c-dynarray
110 7d-cast-char
111 7e-struct-array-access
112 7f-struct-pointer-arithmetic
113 7g-struct-byte-word-field
114 7h-struct-assign
115 7i-struct-struct
116 7j-strtoull
117 7k-for-each-elem
118 7l-struct-any-size-array
119 7m-struct-char-array-assign
120 7n-struct-struct-array
121 7o-struct-pre-post
122 7p-struct-cast
123 7q-bit-field
124 7r-sign-extend
125 7s-struct-short
126 80-setjmp
127 81-qsort
128 81-qsort-dupes
129 82-define
130 83-heterogenoous-init
131 84-struct-field-list
132 85-sizeof
133 86-strncpy
134 87-sscanf
135 88-strrchr
136 90-strpbrk
137 91-fseek
138 92-stat
139 93-fread-fwrite
140 94-unsetenv
141 95-signal
142 96-strto
143 97-fopen
144 98-fopen
145 99-readdir
146 "
147
148 # 90: needs GNU, fails for mescc, passes for tcc
149 broken="$broken
150 7s-struct-short
151 "
152
153 # gcc not supported
154 CC=
155 set +e
156 expect=$(echo $broken | wc -w)
157 pass=0
158 fail=0
159 total=0
160 mkdir -p scaffold/tests
161 for t in $tests; do
162     if [ -z "${t/[012][0-9]-*/}" ]; then
163         LIBC=
164         MES_LIBS="-l none"
165     elif [ -z "${t/[34][0-9]-*/}" ]; then
166         LIBC=c-mini
167         MES_LIBS="-l c-mini"
168     elif [ -z "${t/[78][0-9a-z]-*/}" ]; then
169         LIBC=c+tcc
170         MES_LIBS="-l c+tcc"
171     elif [ -z "${t/9[0-9]-*/}" ]; then
172         LIBC=c+gnu
173         MES_LIBS="-l c+gnu"
174     else
175         LIBC=c
176         MES_LIBS=
177     fi
178     sh ${srcdest}build-aux/test.sh "scaffold/tests/$t" &> scaffold/tests/"$t".log
179     r=$?
180     total=$((total+1))
181     if [ $r = 0 ]; then
182         echo $t: [OK]
183         pass=$((pass+1))
184     else
185         echo $t: [FAIL]
186         fail=$((fail+1))
187     fi
188 done
189
190 [ $expect != 0 ] && echo "expect: $expect"
191 [ $fail != 0 ] && echo "failed: $fail"
192 [ $fail -lt $expect ] && echo "solved: $(($expect - $fail))"
193 echo "passed: $pass"
194 echo "total:  $total"
195 if [ $fail != 0 -a $fail -gt $expect ]; then
196     echo FAILED: $fail/$total
197     exit 1
198 elif [ $fail != 0 ]; then
199     echo PASS: $pass/$total
200 else
201     echo PASS: $total
202 fi