I'm running into a weird syntax error when I try to compile tests using the check unit testing framework with the -std=c99
flag.
So, I'm trying to compile the example.c
:
#include <check.h>
START_TEST(example) {
fail();
} END_TEST
int main(int argc, char** argv){ return 0; }
using autotools, with Makefile.am
:
check_PROGRAMS = example
example_SOURCES = example.c
example_CFLAGS = @CHECK_CFLAGS@ -Wall -pedantic -std=c99
example_LDADD = @CHECK_LIBS@
and configure.ac
:
AC_PREREQ([2.61])
AC_INIT([example], [1.0.0], [noreply@here.com])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_CONFIG_SRCDIR([example.c])
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_RANLIB
PKG_CHECK_MODULES([CHECK], [check >= 0.9.5])
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_STAT
AC_CHECK_FUNCS([memset])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
However I get this weird error:
% make check
make example
gcc -DPACKAGE_NAME=\"example\" -DPACKAGE_TARNAME=\"example\" -DPACKAGE_VERSION=\"1.0.0\" -DPACKAGE_STRING=\"example\ 1.0.0\" -DPACKAGE_BUGREPORT=\"noreply@here.com\" -DPACKAGE=\"example\" -DVERSION=\"1.0.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_FORK=1 -DHAVE_VFORK=1 -DHAVE_WORKING_VFORK=1 -DHAVE_WORKING_FORK=1 -DHAVE_STDLIB_H=1 -DHAVE_MALLOC=1 -DHAVE_STDLIB_H=1 -DHAVE_REALLOC=1 -DHAVE_MEMSET=1 -I. -I/opt/local/include -std=c99 -g -O2 -MT example-example.o -MD -MP -MF .deps/example-example.Tpo -c -o example-example.o `test -f 'example.c' || echo './'`example.c
example.c: In function 'example':
example.c:3: error: parse error before ',' token
make[1]: *** [example-example.o] Error 1
make: *** [check-am] Error 2
So it's finding a syntax error in fail()
(which I suppose check implements as a macro). If I remove the -std=c99
flag, the syntax error goes away, and it works fine.
Is there a way I can fix this? I definitely want -std=c99
so that my use (and check.h
's use) of variadic macros is ok'd by the compiler.
The basic tutorial on that site always shows the Done.fail
called between START_TEST
and END_TEST
macros. They most likely set some things up for these macros.
Now all you need to get that to compile is give fail()
an argument.
It's defined like this:
#define fail(...) _fail_unless(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
Which will have a stray ,
if no argument is given.