Skip to content

Commit

Permalink
More portability improvements for GCC 2
Browse files Browse the repository at this point in the history
  • Loading branch information
aiobofh committed Dec 12, 2017
1 parent b86e1b2 commit 8fb9596
Show file tree
Hide file tree
Showing 18 changed files with 502 additions and 132 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ cutest_work
*.junit_report.xml
*.memcheck
*~
empty
cproto-4.7m.tgz
cproto-4.7m
22 changes: 12 additions & 10 deletions examples/regression_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#include <stdio.h>

#define CUTEST_MY_OWN_EQ_COMPARATORS(EXP, REF) \
int*: cutest_assert_eq_int_ptr, \
int**: cutest_assert_eq_int_ptr_ptr, \
struct my_struct*: cutest_assert_eq_cumbersome_struct_ptr, \
int(*)(int,int): cutest_assert_eq_int_func_ptr,

#include "cutest.h"

#define m cutest_mock

struct my_struct;

/*
* These comparators are only here to reduce warnings on older compilers,
* since they usually do not like pointer-to-int conversions, so these
Expand Down Expand Up @@ -41,16 +53,6 @@ int cutest_assert_eq_cumbersome_struct_ptr(struct my_struct* a, struct my_struct
return 1;
}

#define CUTEST_MY_OWN_EQ_COMPARATORS(EXP, REF) \
int*: cutest_assert_eq_int_ptr, \
int**: cutest_assert_eq_int_ptr_ptr, \
struct my_struct*: cutest_assert_eq_cumbersome_struct_ptr, \
int(*)(int,int): cutest_assert_eq_int_func_ptr,

#include "cutest.h"

#define m cutest_mock

test(return_int_shall_return_1234) {
assert_eq(1234, return_int());
}
Expand Down
2 changes: 2 additions & 0 deletions examples/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static int compare_my_own_type_t(my_own_type_t a, my_own_type_t b, char* output)
#define CUTEST_MY_OWN_EQ_COMPARATORS(EXP, REF) \
my_own_type_t: compare_my_own_type_t,

#define CUTEST_LENIENT_ASSERTS 1

#include "cutest.h"

/*
Expand Down
38 changes: 23 additions & 15 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
LOCALCFLAGS=-pedantic -Wall -std=c99 -O2
include cutest.mk

ifneq ($(findstring clang,$(CC)),clang)
LOCALCFLAGS+=-flto
ifneq ("$(COV)","")
include coverage.mk
endif

all:
$(MAKE) -s -r --no-print-directory cutest_run && \
$(MAKE) -s -r --no-print-directory cutest_mock && \
$(MAKE) -s -r --no-print-directory cutest_prox && \
$(MAKE) -s -r --no-print-directory cutest_work
HAS_LTO:=$(shell $(CC) -o empty empty.c -flto 2>&1 >/dev/null && echo "yes")
ifeq ("$(HAS_LTO)","yes")
LTO:=-flto
else
LTO:=
HAS_LTO:=no
endif

include cutest.mk
include coverage.mk
LOCALCFLAGS=-pedantic -Wall -O2 $(STD) $(LTO)

info:
$(Q)echo "C-standard: $(STD)"
$(Q)echo "LTO : $(LTO)"
$(Q)echo "CLFAGS : $(LOCALCFLAGS)"

%.o: %.c
$(CC) -c $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@
$(Q)$(CC) -c $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@

cutest_run: cutest_run.o helpers.o testcase.o
$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@
$(Q)$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@

cutest_mock: cutest_mock.o helpers.o mockable.o arg.o
$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@
$(Q)$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@

cutest_prox: cutest_prox.o helpers.o
$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@
$(Q)$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@

cutest_work: cutest_work.o helpers.o
$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@
$(Q)$(CC) $^ $(LOCALCFLAGS) $(EXTRA_CFLAGS) -o $@

clean::
$(Q)$(RM) *~ *.o cutest_run cutset_mock cutest_prox cutest_work

clean_all: clean clean_cutest clean_cproto

#
# Dependencies described for test cases
#
Expand Down
47 changes: 22 additions & 25 deletions src/cproto.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

CPROTO_VER=4.7m

CPROTO_PATH=$(CUTEST_PATH)/cproto-$(CPROTO_VER)
CPROTO_PATH=$(abspath $(CUTEST_PATH)/cproto-$(CPROTO_VER))

CPROTO=$(CPROTO_PATH)/cproto
INSTALLED_CPROTO:=$(shell which cproto)
ifneq ("$(INSTALLED_CPROTO)","")
CPROTO=$(INSTALLED_CPROTO)
endif
#INSTALLED_CPROTO:=$(shell which cproto)
#ifneq ("$(INSTALLED_CPROTO)","")
# CPROTO=$(INSTALLED_CPROTO)
#endif

BISON=$(error bison - GNU Project parser generator not found. Can not build cproto-4.7m. You will have to install cproto onto your system manually. For more infomation go to http://invisible-island.net/cproto/cproto.html)
ifneq ("$(wildcard /usr/bin/bison)","")
Expand Down Expand Up @@ -82,44 +82,41 @@ else
endif

RMDIR=$(RM) -r
CPROTO_FLAGS=-D"CPP_DOES_ONLY_C_FILES=1" -D"CPP=\"gcc -E\"" -D"OPT_LINTLIBRARY=1" -D"MAX_INC_DEPTH=999999"
CPROTO_FLAGS=-D"CPP_DOES_ONLY_C_FILES=1" -D"CPP=\"gcc -E\"" -D"OPT_LINTLIBRARY=1" -D"MAX_INC_DEPTH=999999" -I$(CPROTO_PATH)

$(CUTEST_PATH)/cproto-4.7m.tgz:
$(CPROTO_PATH).tgz:
$(info Using $(WGET) to download cproto-4.7m from authors site)
$(Q)$(WGET) -q ftp://ftp.invisible-island.net/cproto/cproto-4.7m.tgz

$(CPROTO_PATH): $(CUTEST_PATH)/cproto-4.7m.tgz
$(Q)$(TAR) xzf $<

$(CPROTO_PATH)/lex.l: $(CPROTO_PATH)
$(CPROTO_PATH)/lex.l: $(CPROTO_PATH).tgz
$(Q)cd $(CUTEST_PATH) && $(TAR) xzf cproto-4.7m.tgz

$(CPROTO_PATH)/cproto.c: $(CPROTO_PATH)
$(CPROTO_PATH)/cproto.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/dump.c: $(CPROTO_PATH)
$(CPROTO_PATH)/dump.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/lintlibs.c: $(CPROTO_PATH)
$(CPROTO_PATH)/lintlibs.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/semantics.c: $(CPROTO_PATH)
$(CPROTO_PATH)/semantics.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/strkey.c: $(CPROTO_PATH)
$(CPROTO_PATH)/strkey.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/symbol.c: $(CPROTO_PATH)
$(CPROTO_PATH)/symbol.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/trace.c: $(CPROTO_PATH)
$(CPROTO_PATH)/trace.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/yyerror.c: $(CPROTO_PATH)
$(CPROTO_PATH)/yyerror.c: $(CPROTO_PATH)/lex.l

$(CPROTO_PATH)/lex.yy.c: $(CPROTO_PATH)/lex.l $(FLEX)
$(info Using $(FLEX) to build parts of cproto-4.7m)
$(Q)cd cproto-4.7m && $(FLEX) $<
$(CPROTO_PATH)/lex.yy.c: $(CPROTO_PATH)/lex.l
$(info Using $(FLEX) to build parts of cproto-4.7m in $(CPROTO_PATH) $(CUTEST_PATH))
$(Q)cd $(CPROTO_PATH) && $(FLEX) $<

$(CPROTO_PATH)/grammar.tab.c: $(CPROTO_PATH)/grammar.y $(CPROTO_PATH)/lex.yy.c $(BISON)
$(CPROTO_PATH)/grammar.tab.c: $(CPROTO_PATH)/grammar.y $(CPROTO_PATH)/lex.yy.c
$(info Using $(BISON) to build parts of cproto-4.7m)
$(Q)cd cproto-4.7m && $(BISON) $(notdir $<)
$(Q)cd $(CPROTO_PATH) && $(BISON) $(notdir $<)

$(CPROTO_PATH)/cproto: $(CPROTO_PATH)/cproto.c $(CPROTO_PATH)/dump.c $(CPROTO_PATH)/lintlibs.c $(CPROTO_PATH)/semantic.c $(CPROTO_PATH)/strkey.c $(CPROTO_PATH)/symbol.c $(CPROTO_PATH)/trace.c $(CPROTO_PATH)/yyerror.c $(CPROTO_PATH)/grammar.tab.c
$(Q)$(CC) -o $@ $^ -Icproto-4.7m/ $(CPROTO_FLAGS)

clean_cproto:
$(Q)$(RMDIR) $(CPROTO_PATH)
$(Q)$(RM) cproto-4.7m.tgz
19 changes: 18 additions & 1 deletion src/cutest.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,24 @@
#include "cutest_simple.h"
#endif

#ifdef VARIADIC

#define assert_eq_select(X, A1, A2, A3, MACRO, ...) MACRO

#define assert_eq_chooser(...) \
assert_eq_select(,##__VA_ARGS__, \
assert_eq_3, \
assert_eq_2, \
assert_eq_1,)

#define assert_eq(...) assert_eq_chooser(__VA_ARGS__)(__VA_ARGS__)

#else

#define assert_eq(EXP, REF) asset_eq_2(EXP, REF)

#endif

#include "stdlib.h"

/*
Expand Down Expand Up @@ -429,7 +447,6 @@ void cutest_execute_test(cutest_junit_report_t* junit_report,
int do_mock, const char *prog_name);
int cutest_shutdown(const char* filename,
cutest_junit_report_t* junit_report, size_t test_cnt);

/*
* These functions are generated
*/
Expand Down
Loading

0 comments on commit 8fb9596

Please sign in to comment.