From ecb5e1bcf3b11b2f0b8a132a14107d15ac3e4040 Mon Sep 17 00:00:00 2001 From: Julian Daube Date: Wed, 25 Oct 2017 18:35:45 +0200 Subject: [PATCH] add testsuit --- Makefile | 28 ++++++++++++++++++---- tests.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests.h | 16 +++++++++++++ 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 tests.c create mode 100644 tests.h diff --git a/Makefile b/Makefile index b13bd06..99071da 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,39 @@ -OBJ:= main.o fs.o +OBJ:= main.o fs.o strhash.o hashtable.o +CC ?= clang + +# OS dependend targets +OBJ += fs_linux.o OUTPUT:= texdepends .PHONY: test debug clean all: debug -test: debug +test: ctests debug ./$(OUTPUT) test.tex -debug: CXXFLAGS:= -g -std=c++11 +ctests: test_path test_hashtable + $(foreach exe,$^,./$(exe);) + +.INTERMEDIATE: test_path tests.o test_path.o + +test_path: test_path.o fs.o fs_linux.o tests.o + $(CC) $^ -o test_path +test_path.c: fs.o tests.o + +test_hashtable: test_hashtable.o strhash.o tests.o hashtable.o + $(CC) $^ -o test_hashtable + +test_hashtable.c: hashtable.h + +debug: CXXFLAGS += -g -std=c++11 +debug: CFLAGS += -g debug: $(OUTPUT) clean: $(RM) $(OBJ) $(OUTPUT) -main.o: fs.o +fs.c: fs_linux.o +main.c: fs.o strhash.o hashtable.o $(OUTPUT): main.o $(CXX) $(OBJ) -o $(OUTPUT) diff --git a/tests.c b/tests.c new file mode 100644 index 0000000..48f1588 --- /dev/null +++ b/tests.c @@ -0,0 +1,72 @@ +/* + * tests.c + * + * Created on: 20.10.2017 + * Author: julian + */ + +#include "tests.h" +#include +#include + +#include +#include + +const char * teststack[20]; +int current = 0; + +void segfault(int i) { + fail("segfault"); + exit(2); +} + +void push(const char * name) { + if (current < 20) { + teststack[current] = name; + current++; + } +} + +void pop() { + if (current != 0) + current--; +} + +void test_name() { + int i = 0; + for (; i < current-1;i++) { + printf("%s@", teststack[i]); + } + + if (i < current) + printf("%s", teststack[i]); +} + +void init(const char * name) { + push(name); + test_name(); + puts(": START"); + + // install signal handlers + signal(SIGSEGV, segfault); +} + +void fail(const char * reason, ...) { + va_list list; + va_start(list, reason); + + test_name(); + fputs(": FAIL (", stdout); + vprintf(reason, list); + va_end(list); + + puts(")"); + exit(1); +} + +void pass() { + test_name(); + puts(": PASS"); + pop(); +// exit(0); +} diff --git a/tests.h b/tests.h new file mode 100644 index 0000000..a067895 --- /dev/null +++ b/tests.h @@ -0,0 +1,16 @@ +/* + * tests.h + * + * Created on: 20.10.2017 + * Author: julian + */ + +#ifndef TESTS_H_ +#define TESTS_H_ + +void init(); +void fail(const char * err, ...); +void pass(); + + +#endif /* TESTS_H_ */