From 5dc1f88247fac0008c902dddd33adfa51380ec09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Sat, 27 Oct 2018 12:14:57 +0200 Subject: [PATCH] improved testing and added general Makefile --- Makefile | 16 ++++++++++++++++ interpreter/test/test_interpreter.c | 5 +++++ test/test_stack.c | 7 ++++++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89e3480 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CC=gcc +objects= stack.o method_dispatcher/method_dispatcher.o interpreter/core_methods.o interpreter/interpreter.o + +all: $(objects) test + +CFLAG= -c -O -o + +%.o: %.c + $(CC) $(CFLAG) $@ $< + +.PHONY: test + +test: + cd test && make + cd method_dispatcher/test && make + cd interpreter/test && make diff --git a/interpreter/test/test_interpreter.c b/interpreter/test/test_interpreter.c index 5793f0c..62db833 100644 --- a/interpreter/test/test_interpreter.c +++ b/interpreter/test/test_interpreter.c @@ -1,5 +1,6 @@ #include #include +#include #include "../interpreter.h" #include "../core_methods.h" #include "../../method_dispatcher/method_dispatcher.h" @@ -39,9 +40,13 @@ int main(void) machine_state_t_exec_cycle(state); machine_state_t_exec_cycle(state); printf("data_reg[0]: %x\n", state->data_reg[0]); + assert(state->data_reg[0] == 0xfefe); printf("data_reg[1]: %x\n", state->data_reg[1]); + assert(state->data_reg[1] == 5); printf("data_reg[2]: %x\n", state->data_reg[2]); + assert(state->data_reg[2] == 3); printf("program_counter: %d\n", state->program_counter); + assert(state->program_counter == 8); dispatch_tree_autoinserter_t_del(inserter); machine_state_t_del(state); free(program); diff --git a/test/test_stack.c b/test/test_stack.c index 05fecc1..328c35c 100644 --- a/test/test_stack.c +++ b/test/test_stack.c @@ -1,5 +1,6 @@ #include #include "../stack.h" +#include int main(void) { @@ -13,10 +14,14 @@ int main(void) { bci_stack_t_push(&stack, (uint16_t) i); } + --i; while(!status) { status = bci_stack_t_pop(&stack, &res); - printf("%d\n", res); + if(!status) + { + assert(res == i--); + } }