Utility script to build a FAT library for OS X
[blocksruntime.git] / checktests
blob1c9740a10ca3fcb973e0713d071cbd6de39da096
1 #!/bin/sh
2 : ${CC:=clang}
3 : ${CXX:=$CC}
4 : ${CFLAGS:=}
5 CPPFLAGS='-Wno-unused -include testprefix.h -IBlocksRuntime'
6 CCFLAGS='-std=c99'
7 LIB=libBlocksRuntime.a
8 TESTDIR=testbin
9 rm -rf $TESTDIR
10 mkdir $TESTDIR
11 if ! "$CC" --version >/dev/null 2>&1; then
12 echo "$CC" not installed
13 exit 1
14 else
15 if ("$CC" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') 2>&1 | grep -q -- -fblocks; then
16 echo "$CC" does not support the -fblocks option
17 exit 1
20 if "$CXX" --version >/dev/null 2>&1; then
21 dopp=1
22 if ("$CXX" -fblocks -c -o /dev/null -x c - < /dev/null 2>&1 || echo '-fblocks') | grep -q -- -fblocks; then
23 echo "$CXX" does not support the -fblocks option
24 exit 1
26 else
27 echo "$CXX" not installed -- skipping C++ tests
29 if [ ! -r "$LIB" ]; then
30 echo "No $LIB file found, try running $(dirname "$0")/buildlib first"
31 exit 1
33 failcount=0
34 testsfailed=
35 for test in BlocksRuntime/tests/*.[cC]; do
36 skip=
37 skipdoze=
38 extra=
39 stub=
40 println=
41 xfail=
42 pmsg='should PASS'
43 fmsg='should FAIL'
44 case $test in
45 */rdar6405500.c | \
46 */rdar6414583.c | \
47 */objectRRGC.c | \
48 */dispatch_async.c) skip=1;;
49 */fail.c) skipdoze=1;;
50 */macro.c) stub='void foo(); int main(){foo(); printf("success");}'; println=1;;
51 */cast.c | \
52 */voidarg.c) println=1;;
53 */varargs-bad-assign.c | \
54 */rettypepromotion.c | \
55 */shorthandexpression.c | \
56 */k-and-r.c | \
57 */sizeof.c | \
58 */orbars.c | \
59 */constassign.c) xfail=1;;
60 esac
61 ext=.c
62 cpp=
63 USECC="$CC"
64 USEFLAGS="$CCFLAGS $CPPFLAGS"
65 USELIB="$LIB"
66 case $test in
67 *.C) cpp=1; ext=.C;;
68 *.cpp) cpp=1; ext=.cpp;;
69 *.cp) cpp=1; ext=.cp;;
70 *.c++) cpp=1; ext=.c++;;
71 esac
72 if [ -n "$cpp" ]; then
73 USECC="$CXX"
74 USEFLAGS="$CPPFLAGS"
75 USELIB="$LIB -lstdc++"
77 if [ -n "$COMSPEC" -a -n "$skipdoze" ]; then
78 skip=1
80 if [ -z "$skip" -a -n "$cpp" -a -z "$dopp" ]; then
81 echo "skipping $test ("$CXX" not installed)"
82 else
83 if [ -n "$skip" ]; then
84 echo skipping $test
85 else
86 if [ -n "$xfail" ]; then
87 echo "--- $(basename $test) ($fmsg) ---"
88 else
89 echo "--- $(basename $test) ($pmsg) ---"
91 if [ -n "$stub" ]; then
92 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
93 echo "$stub" | "$USECC" $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext) -fblocks \
94 $TESTDIR/$(basename $test $ext).o $USELIB -x c - && \
95 $TESTDIR/$(basename $test $ext)
96 else
97 "$USECC" -c $CFLAGS $USEFLAGS $extra -o $TESTDIR/$(basename $test $ext).o -fblocks $test && \
98 "$USECC" $CFLAGS -o $TESTDIR/$(basename $test $ext) -fblocks $TESTDIR/$(basename $test $ext).o $USELIB && \
99 $TESTDIR/$(basename $test $ext)
101 result=$?
102 if [ -n "$println" ]; then
103 echo ''
105 if [ $result = 0 -a -n "$xfail" ]; then
106 echo ''
107 echo "*"
108 echo "**"
109 echo "*** ^FAILURE: expect FAIL test PASSED! ***"
110 echo "**"
111 echo "*"
112 echo ''
113 testsfailed=1
114 failcount=$(($failcount + 1))
116 if [ $result != 0 -a -z "$xfail" ]; then
117 echo ''
118 echo "*"
119 echo "**"
120 echo "*** ^FAILURE: expect PASS test FAILED! ***"
121 echo "**"
122 echo "*"
123 echo ''
124 testsfailed=1
125 failcount=$(($failcount + 1))
129 done
130 if [ -n "$testsfailed" ]; then
131 echo ''
132 echo "*"
133 echo "**"
134 echo "*** WARNING: Some failures($failcount) occurred, look for '*** ^FAILURE:' lines above"
135 echo "**"
136 echo "*"
137 echo ''
138 exit 1
140 echo "*** All tests passed ***"
141 exit 0