Erreur de syntaxe lors de l'utilisation framework de test unité de contrôle avec C99
-
27-10-2019 - |
Question
Je suis en cours d'exécution dans une erreur de syntaxe bizarre lorsque je tente de compiler des tests en utilisant le framework de test unité de contrôle avec le drapeau de -std=c99
.
Alors, je suis en train de compiler le example.c
:
#include <check.h>
START_TEST(example) {
fail();
} END_TEST
int main(int argc, char** argv){ return 0; }
en utilisant les autotools, avec Makefile.am
:
check_PROGRAMS = example
example_SOURCES = example.c
example_CFLAGS = @CHECK_CFLAGS@ -Wall -pedantic -std=c99
example_LDADD = @CHECK_LIBS@
et 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
Cependant je reçois cette erreur bizarre:
% 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
Il est de trouver une erreur de syntaxe dans fail()
(que je suppose que comme une vérification des instruments macro). Si je retire le drapeau -std=c99
, l'erreur de syntaxe disparaît, et il fonctionne très bien.
Est-il possible que je peux résoudre ce problème? Je veux vraiment -std=c99
pour que mon utilisation (et l'utilisation check.h
) des macros variadique est ok'd par le compilateur.
La solution
Le tutoriel de base sur ce site montre toujours Terminé. fail
appelé entre les macros START_TEST
et END_TEST
. Ils vont très probablement mis des choses pour ces macros.
Maintenant, tout ce dont vous avez besoin pour obtenir que de compiler est de donner fail()
un argument.
Il est défini comme ceci:
#define fail(...) _fail_unless(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)
Ce qui aura un ,
parasite si aucun argument est donné.