texdepends/tests.c

73 lines
956 B
C
Raw Normal View History

2017-10-25 18:35:45 +02:00
/*
* 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);
}