From 107dd016d0eb630f316ee1d7d3be5f019d15b530 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Thu, 3 Sep 2015 23:51:47 +0200 Subject: [PATCH] [Quiz] Support C++ cases --- kandinsky/test/set_pixel.c | 2 +- poincare/test/integer.cpp | 2 +- quiz/Makefile | 5 ++++- quiz/include/quiz.h | 6 +++++- quiz/src/symbols.awk | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/kandinsky/test/set_pixel.c b/kandinsky/test/set_pixel.c index b89af1939..d20028fd4 100644 --- a/kandinsky/test/set_pixel.c +++ b/kandinsky/test/set_pixel.c @@ -1,6 +1,6 @@ #include #include -TEST(setpixel) { +QUIZ_CASE(setpixel) { 2+2; } diff --git a/poincare/test/integer.cpp b/poincare/test/integer.cpp index 3cc19ae23..9987eaf98 100644 --- a/poincare/test/integer.cpp +++ b/poincare/test/integer.cpp @@ -1,6 +1,6 @@ #include #include -TEST(integer) { +QUIZ_CASE(integer) { 1+1; } diff --git a/quiz/Makefile b/quiz/Makefile index 4bc8073c8..ac63567cd 100644 --- a/quiz/Makefile +++ b/quiz/Makefile @@ -1,4 +1,5 @@ SFLAGS += -Iquiz/include +objs += $(addprefix quiz/src/, runner.o symbols.o) symbols_file = $(addprefix quiz/src/, symbols.c) products += $(symbols_file) @@ -9,4 +10,6 @@ $(symbols_file): $(tests) test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests))) -test.elf: quiz/src/symbols.o quiz/src/runner.o $(test_objs) +test.elf: $(objs) $(test_objs) + @echo "LD $@" + @$(LD) $(LDFLAGS) $(objs) $(test_objs) -o $@ diff --git a/quiz/include/quiz.h b/quiz/include/quiz.h index 50fc833db..975723ca3 100644 --- a/quiz/include/quiz.h +++ b/quiz/include/quiz.h @@ -1,6 +1,10 @@ #ifndef QUIZ_H #define QUIZ_H -#define TEST(foo) void test_##foo() +#ifdef __cplusplus +#define QUIZ_CASE(name) extern "C" { void quiz_case_##name();}; void quiz_case_##name() +#else +#define QUIZ_CASE(name) void quiz_case_##name() +#endif #endif diff --git a/quiz/src/symbols.awk b/quiz/src/symbols.awk index 66be35cd0..042e7329f 100644 --- a/quiz/src/symbols.awk +++ b/quiz/src/symbols.awk @@ -6,7 +6,7 @@ BEGIN { #FIXME: Is there a way to capture subexpression in awk? The following gsub is # kind of ugly -/TEST\(([a-z0-9_]+)\)/ { gsub(/(TEST\()|(\))/, "", $1); tests = tests "," $1 } +/QUIZ_CASE\(([a-z0-9_]+)\)/ { gsub(/(QUIZ_CASE\()|(\))/, "", $1); tests = tests ",quiz_case_" $1 } END { a = tests;