3 # This file produces TAP compliant output
6 # This file can be run directly or with "prove" like this:
10 # Do not forget to set the compiler if needed like so:
11 # CC=my-clang-build prove -v checktests
18 CPPFLAGS
='-O -Wno-unused -include testprefix.h -IBlocksRuntime'
19 CCFLAGS
='-std=c99 -Wimplicit-function-declaration'
20 LIB
=libBlocksRuntime.a
31 while read -r LINE
; do
36 diag
'blocksruntime tests' ''
37 if ! ccver
="$("$CC" --version 2>&1)"; then
38 echo 'Bail out! '"\"$CC\" not installed (did you forget to set \$CC?)"
41 out
="$( ("$CC" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
42 case "$out" in *"-fblocks"*)
43 out
="$( ("$CC" -fblocks -S -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
44 case "$out" in *"-fblocks"*)
45 echo 'Bail out! '"\"$CC\" does not support the -fblocks option"
49 diag
"WARNING: -S required for -fblocks with $CC"
51 ccmach
="$("$CC" -dumpmachine 2>/dev/null)"
54 if cxxver
="$("$CXX" --version 2>&1)"; then
56 out
="$( ("$CXX" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
57 case "$out" in *"-fblocks"*)
58 out
="$( ("$CXX" -fblocks -S -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1)"
61 warnskipcxx
="\"$CXX\" does not support the -fblocks option; skipping C++ tests"
68 if [ "$CC" != "$CXX" ]; then
69 diag
"WARNING: -S required for -fblocks with $CXX"
72 if [ -n "$dopp" ]; then
73 cxxmach
="$("$CXX" -dumpmachine 2>/dev/null)"
74 cxxdver
="$("$CXX" -dumpversion 2>/dev/null)"
77 warnskipcxx
="\"$CXX\" not installed; skipping C++ tests"
79 if [ -n "$usedashs" ]; then
82 if [ -n "$warnskipcxx" ]; then
83 diag
"$warnskipcxx" ""
85 if [ ! -r "$LIB" ]; then
86 echo 'Bail out! '"No \"$LIB\" file found, try running \"$(dirname "$0")/buildlib\" first"
91 case "$ccver" in *[Cc
][Ll
][Aa
][Nn
][Gg
]*)
94 case "$cxxver" in *[Cc
][Ll
][Aa
][Nn
][Gg
]*)
97 if [ -n "$iscxx_clang" ]; then case "$cxxdver" in
103 case "$ccmach" in arm-
*)
104 case "$ccmach" in *abihf
)
108 case "$cxxmach" in arm-
*)
109 case "$cxxmach" in *abihf
)
113 diag
"CC${iscc_clang:+(clang)}: $CC --version"
114 echo "$ccver" | diagfilt
116 if [ -n "$dopp" -a z
"$CXX" != z
"$CC" ]; then
117 diag
"CXX${iscxx_clang:+(clang)}: $CXX --version"
118 echo "$cxxver" | diagfilt
129 for test in BlocksRuntime
/tests
/*.
[cC
]; do
130 testname
="${test#BlocksRuntime/tests/}"
138 testcount
=$
(($testcount + 1))
143 dispatch_async.c
) skip
=1;;
145 macro.c
) stub
='void foo(); int main(){foo(); printf("success");}';;
146 varargs-bad-assign.c | \
147 rettypepromotion.c | \
148 shorthandexpression.c | \
152 constassign.c
) xfail
=1;;
153 copy-block-literal-rdar6439600.c
) reason
='compiler bug'; showxfail
=1; xfail
=1;;
154 ${iscc_clang}cast.c
) reason
='gcc compiler bug'; showxfail
=1; xfail
=1;;
155 ${iscxx_clang}josh.C
) reason
='g++ compiler bug'; showxfail
=1; xfail
=1;;
157 if [ -n "$skiprefC" ]; then
158 reason
="\"$CXX\" version too old"
162 if [ -n "$iscc_armhf" ]; then
163 reason
='incorrect clang armhf block float vararg implementation'
171 USEFLAGS
="$CCFLAGS $CPPFLAGS"
175 *.cpp
) cpp
=1; ext
=.cpp
;;
176 *.
cp) cpp
=1; ext
=.
cp;;
177 *.c
++) cpp
=1; ext
=.c
++;;
179 if [ -n "$cpp" ]; then
182 USELIB
="$LIB -lstdc++"
184 if [ -n "$COMSPEC" -a -n "$skipdoze" ]; then
187 if [ -z "$skip" -a -n "$cpp" -a -z "$dopp" ]; then
188 echo "ok $testcount - $testname # skipped: C++ with blocks not available"
189 skipcpp
=$
(($skipcpp + 1))
190 skipcount
=$
(($skipcount + 1))
192 if [ -n "$skip" ]; then
193 if [ -n "$skipdoze" ]; then
194 echo "ok $testcount - $testname # skipped: not supported on this platform"
196 echo "ok $testcount - $testname # skipped: not supported"
198 skipcount
=$
(($skipcount + 1))
200 if [ -n "$stub" ]; then
202 if [ -z "$usedashs" ]; then
203 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
204 echo "$stub" | "$USECC" $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext) -fblocks \
205 $TESTDIR/$(basename $test $ext).o $USELIB -x c - && \
206 cd $TESTDIR && ./$(basename $test $ext)
208 "$USECC" -S $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).s -fblocks $test && \
209 "$USECC" -c $CFLAGS $extra -o $TESTDIR/$(basename $test $ext).o \
210 $TESTDIR/$(basename $test $ext).s && \
211 echo "$stub" | "$USECC" $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext) \
212 $TESTDIR/$(basename $test $ext).o $USELIB -x c - && \
213 cd $TESTDIR && ./$(basename $test $ext)
218 if [ -z "$usedashs" ]; then
219 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
220 "$USECC" $CFLAGS -o $TESTDIR/$(basename $test $ext) -fblocks $TESTDIR/$(basename $test $ext).o $USELIB && \
221 cd $TESTDIR && ./$(basename $test $ext)
223 "$USECC" -S $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).s -fblocks $test && \
224 "$USECC" -c $CFLAGS $extra -o $TESTDIR/$(basename $test $ext).o \
225 $TESTDIR/$(basename $test $ext).s && \
226 "$USECC" $CFLAGS -o $TESTDIR/$(basename $test $ext) $TESTDIR/$(basename $test $ext).o $USELIB && \
227 cd $TESTDIR && ./$(basename $test $ext)
232 if [ -n "$xfail" ]; then
233 xfailcount
=$
(($xfailcount + 1))
234 : ${reason:=expected to fail}
235 if [ $result = 0 ]; then
236 bonuscount
=$
(($bonuscount + 1))
237 passcount
=$
(($passcount + 1))
238 echo "ok $testcount - $testname # TODO: $reason"
240 echo "not ok $testcount - $testname # TODO: $reason"
241 if [ -n "$showxfail" ]; then
242 echo "$out" | diagfilt
246 if [ $result != 0 ]; then
248 failcount
=$
(($failcount + 1))
249 echo "not ok $testcount - $testname"
250 echo "$out" | diagfilt
252 echo "ok $testcount - $testname"
253 passcount
=$
(($passcount + 1))
259 diag
"" "test count: $testcount"
260 if [ $bonuscount != 0 ]; then
261 diag
" passed: $passcount (todo=$bonuscount)"
263 diag
" passed: $passcount"
265 if [ $xfailcount != 0 ]; then
266 if [ $bonuscount != 0 ]; then
267 diag
" xfail: $xfailcount (passed=$bonuscount)"
269 diag
" xfail: $xfailcount"
272 if [ $skipcount != 0 ]; then
273 if [ $skipcpp != 0 ]; then
274 diag
" skipped: $skipcount (C++=$skipcpp)"
276 diag
" skipped: $skipcount"
279 if [ $failcount != 0 ]; then
280 diag
" failed: $failcount"
282 if [ -n "$testsfailed" ]; then
283 diag
"test failures occurred"
285 diag
"all tests passed"
289 [ -z "$testsfailed" ] ||
exit 1