summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--fzytest.c11
2 files changed, 12 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 7b3cead..4854fca 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CFLAGS+=-Wall -Wextra -g -std=c99 -O3 -pedantic
PREFIX?=/usr/local
MANDIR?=$(PREFIX)/share/man
BINDIR?=$(PREFIX)/bin
-VALGRIND?=
+DEBUGGER?=
INSTALL=install
INSTALL_PROGRAM=$(INSTALL)
@@ -17,7 +17,7 @@ fzytest: fzytest.o match.o choices.o
$(CC) $(CFLAGS) $(CCFLAGS) -o $@ $^
test: fzytest
- -$(VALGRIND) ./fzytest
+ -$(DEBUGGER) ./fzytest
fzy: fzy.o match.o tty.o choices.o
$(CC) $(CFLAGS) $(CCFLAGS) -o $@ $^
diff --git a/fzytest.c b/fzytest.c
index 2c28fb5..ec81170 100644
--- a/fzytest.c
+++ b/fzytest.c
@@ -1,12 +1,13 @@
#include <stdio.h>
#include <string.h>
+#include <signal.h>
#include "match.h"
#include "choices.h"
int testsrun = 0, testsfailed = 0, assertionsrun = 0;
-#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);testsfailed++;return;}
+#define assert(x) if(++assertionsrun && !(x)){fprintf(stderr, "test \"%s\" failed\n assert(%s) was false\n at %s:%i\n\n", __func__, #x, __FILE__ ,__LINE__);raise(SIGTRAP);testsfailed++;return;}
#define assert_streq(a, b) assert(!strcmp(a, b))
@@ -216,10 +217,18 @@ void summary(){
printf("%i tests, %i assertions, %i failures\n", testsrun, assertionsrun, testsfailed);
}
+static void ignore_signal(int signum){
+ (void) signum;
+}
+
int main(int argc, char *argv[]){
(void) argc;
(void) argv;
+ /* We raise sigtrap on all assertion failures.
+ * If we have no debugger running, we should ignore it */
+ signal(SIGTRAP, ignore_signal);
+
runtest(test_match);
runtest(test_scoring);
runtest(test_positions_1);