Add munit for unit testing.
Main method extracted to separate file to make it easier to test the _rest_ of the code. munit is added as a submodule by running `cd src; git submodule add https://github.com/nemequ/munit.git` . Unit testing has so far only been tested on ubuntu.
This commit is contained in:
75
src/test/Makefile
Normal file
75
src/test/Makefile
Normal file
@@ -0,0 +1,75 @@
|
||||
# Using µnit is very simple; just include the header and add the C
|
||||
# file to your sources. That said, here is a simple Makefile to build
|
||||
# the example.
|
||||
|
||||
CSTD:=99
|
||||
OPENMP:=n
|
||||
ASAN:=n
|
||||
UBSAN:=n
|
||||
EXTENSION:=
|
||||
TEST_ENV:=
|
||||
CFLAGS:=-Wall -Wno-char-subscripts -Wno-unused-but-set-variable
|
||||
AGGRESSIVE_WARNINGS=n
|
||||
LIBS:=-lcrypt
|
||||
|
||||
#ifeq ($(CC),pgcc)
|
||||
# CFLAGS+=-c$(CSTD)
|
||||
#else
|
||||
# CFLAGS+=-std=c$(CSTD)
|
||||
#endif
|
||||
|
||||
ifeq ($(OPENMP),y)
|
||||
ifeq ($(CC),pgcc)
|
||||
CFLAGS+=-mp
|
||||
else
|
||||
CFLAGS+=-fopenmp
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(SANITIZER),)
|
||||
CFLAGS+=-fsanitize=$(SANITIZER)
|
||||
endif
|
||||
|
||||
ifneq ($(CC),pgcc)
|
||||
ifeq ($(EXTRA_WARNINGS),y)
|
||||
CFLAGS+=-Wall -Wextra -Werror
|
||||
endif
|
||||
|
||||
ifeq ($(ASAN),y)
|
||||
CFLAGS+=-fsanitize=address
|
||||
endif
|
||||
|
||||
ifeq ($(UBSAN),y)
|
||||
CFLAGS+=-fsanitize=undefined
|
||||
endif
|
||||
endif
|
||||
|
||||
MUNIT_FILES := ../munit/munit.h ../munit/munit.c
|
||||
TEST_FILES := $(ls *.c)
|
||||
|
||||
# exclude main.c to avoid having multiple entrypoints.
|
||||
OBJ_FILES_FROM_MUD_CODE != ls ../*.c | grep -v main.c | sed 's/\.c$$/.o/g' | xargs
|
||||
OBJ_FILES_FORM_MUNIT:= ../munit/munit.o
|
||||
OBJ_FILES_FROM_TESTS!= ls *.c | sed 's/\$$.c/.o/g' | xargs
|
||||
|
||||
OBJ_FILES := $(OBJ_FILES_FROM_MUD_CODE) $(OBJ_FILES_FORM_MUNIT) $(OBJ_FILES_FROM_TESTS) $(LIBS)
|
||||
|
||||
testfile: $(OBJ_FILES)
|
||||
$(CC) $(CFLAGS) -o testfile $(OBJ_FILES)
|
||||
|
||||
test: testfile
|
||||
$(TEST_ENV) ./testfile
|
||||
|
||||
$%.o: %.c
|
||||
$(CC) $< $(CFLAGS) -c -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o testfile depend
|
||||
all: test
|
||||
|
||||
default: all
|
||||
|
||||
depend:
|
||||
$(CC) -MM *.c > depend
|
||||
|
||||
-include depend
|
||||
Reference in New Issue
Block a user