add testsuit

This commit is contained in:
Julian Daube 2017-10-25 18:35:45 +02:00
parent 2bd12a392a
commit ecb5e1bcf3
3 changed files with 112 additions and 4 deletions

View File

@ -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 OUTPUT:= texdepends
.PHONY: test debug clean .PHONY: test debug clean
all: debug all: debug
test: debug test: ctests debug
./$(OUTPUT) test.tex ./$(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) debug: $(OUTPUT)
clean: clean:
$(RM) $(OBJ) $(OUTPUT) $(RM) $(OBJ) $(OUTPUT)
main.o: fs.o fs.c: fs_linux.o
main.c: fs.o strhash.o hashtable.o
$(OUTPUT): main.o $(OUTPUT): main.o
$(CXX) $(OBJ) -o $(OUTPUT) $(CXX) $(OBJ) -o $(OUTPUT)

72
tests.c Normal file
View File

@ -0,0 +1,72 @@
/*
* tests.c
*
* Created on: 20.10.2017
* Author: julian
*/
#include "tests.h"
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdarg.h>
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);
}

16
tests.h Normal file
View File

@ -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_ */