diff --git a/quiz/Makefile b/quiz/Makefile index ac63567cd..a208e82d7 100644 --- a/quiz/Makefile +++ b/quiz/Makefile @@ -1,5 +1,4 @@ SFLAGS += -Iquiz/include -objs += $(addprefix quiz/src/, runner.o symbols.o) symbols_file = $(addprefix quiz/src/, symbols.c) products += $(symbols_file) @@ -8,8 +7,9 @@ $(symbols_file): $(tests) @echo "AWK $@" @awk -f quiz/src/symbols.awk $(tests) > $@ +runner_objs += $(addprefix quiz/src/, runner.o symbols.o) test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests))) -test.elf: $(objs) $(test_objs) +test.elf: $(objs) $(runner_objs) $(test_objs) @echo "LD $@" @$(LD) $(LDFLAGS) $(objs) $(test_objs) -o $@ diff --git a/quiz/include/quiz.h b/quiz/include/quiz.h index 975723ca3..52aae759f 100644 --- a/quiz/include/quiz.h +++ b/quiz/include/quiz.h @@ -1,10 +1,22 @@ #ifndef QUIZ_H #define QUIZ_H +#include + #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 +#ifdef __cplusplus +extern "C" { +#endif + +void quiz_assert_true(bool condition); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/quiz/src/assertions.c b/quiz/src/assertions.c new file mode 100644 index 000000000..1ea3fab91 --- /dev/null +++ b/quiz/src/assertions.c @@ -0,0 +1,7 @@ +#include +#include + +void quiz_assert_true(bool condition) { + if (!condition) { + } +} diff --git a/quiz/src/runner.c b/quiz/src/runner.c index 9ffa98ba0..895a0c545 100644 --- a/quiz/src/runner.c +++ b/quiz/src/runner.c @@ -1,11 +1,29 @@ #include "symbols.h" #include +#include + +void print(char * message) { + static int line_y = 0; + int line_height = KDStringSize("M").height; + KDDrawString(message, (KDPoint){.x = 0, .y = line_y}); + line_y += line_height; + if (line_y > ION_FRAMEBUFFER_HEIGHT) { + line_y = 0; + ion_getchar(); + // Clear screen maybe? + } +} void hello() { int i = 0; while (quiz_cases[i] != NULL) { QuizCase c = quiz_cases[i]; c(); + print(quiz_case_names[i]); i++; } + print("ALL TESTS FINISHED"); + while (1) { + ion_sleep(); + } } diff --git a/quiz/src/symbols.awk b/quiz/src/symbols.awk index 042e7329f..b678a0de6 100644 --- a/quiz/src/symbols.awk +++ b/quiz/src/symbols.awk @@ -6,19 +6,28 @@ BEGIN { #FIXME: Is there a way to capture subexpression in awk? The following gsub is # kind of ugly -/QUIZ_CASE\(([a-z0-9_]+)\)/ { gsub(/(QUIZ_CASE\()|(\))/, "", $1); tests = tests ",quiz_case_" $1 } +/QUIZ_CASE\(([a-z0-9_]+)\)/ { gsub(/(QUIZ_CASE\()|(\))/, "", $1); tests = tests "quiz_case_" $1 "," } END { - a = tests; - b = tests; - gsub(/,/, "();\nvoid ", a); - sub(/\(\);\n/, "", a); - print a "();"; - print ""; + declarations = tests; + gsub(/quiz_case/, "void quiz_case", declarations); + gsub(/,/, "();\n", declarations); + print declarations; + + symbols = tests; print "QuizCase quiz_cases[] = {"; - sub(/,/, "", b); - gsub(/,/, ",\n", b); - print b; - print ",NULL" + gsub(/quiz_case/, " quiz_case", symbols); + gsub(/,/, ",\n", symbols); + symbols = symbols " NULL" + print symbols; + print "};" + print "" + + names = tests; + print "char * quiz_case_names[] = {"; + gsub(/quiz_case_/, " \"", names); + gsub(/,/, "\",\n", names); + names = names " NULL" + print names; print "};" } diff --git a/quiz/src/symbols.h b/quiz/src/symbols.h index 1dc58bdf8..56f7986f4 100644 --- a/quiz/src/symbols.h +++ b/quiz/src/symbols.h @@ -1,3 +1,4 @@ typedef void (*QuizCase)(void); extern QuizCase quiz_cases[]; +extern char * quiz_case_names[];