add testsuit
This commit is contained in:
parent
2bd12a392a
commit
ecb5e1bcf3
28
Makefile
28
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)
|
||||
|
72
tests.c
Normal file
72
tests.c
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user