add test target and basic test 'harness'

test harness is a grand word for just a basic C main file that uses
plain <assert.h> macro to run tests
This commit is contained in:
Arnaud Bailly 2019-07-23 09:38:28 +02:00
parent 7f53d0d54d
commit 2b11b7cc32
No known key found for this signature in database
GPG Key ID: 389CC2BC5448321E
2 changed files with 28 additions and 12 deletions

View File

@ -25,37 +25,41 @@ else
LIBFLAGS :=-shared LIBFLAGS :=-shared
endif endif
OBJS = idris_net.o LIBNAME=idris_net
HDRS = idris_net.h OBJS = $(LIBNAME).o
HDRS = $(LIBNAME).h
CFLAGS := $(CFLAGS) CFLAGS := $(CFLAGS)
ifneq ($(OS), windows) ifneq ($(OS), windows)
CFLAGS += -fPIC CFLAGS += -fPIC
endif endif
DYLIBTARGET = idrnet$(SHLIB_SUFFIX) DYLIBTARGET = lib$(LIBNAME)$(SHLIB_SUFFIX)
LIBTARGET = idrnet.a LIBTARGET = $(LIBNAME).a
TARGET=${HOME}/.idris2 TARGET=${HOME}/.idris2
build: $(LIBTARGET) $(DYLIBTARGET) build: $(DYLIBTARGET)
@if ! [ -d build ]; then echo "creating 'build' directory"; mkdir build ; else echo "directory 'build' exists"; fi
$(LIBTARGET) : $(OBJS) @if [ -z "${IDRIS2}" ]; then echo 'variable $$IDRIS2 is not set, aborting'; exit 1; fi
$(AR) rc $(LIBTARGET) $(OBJS) ${IDRIS2} --build network.ipkg
$(RANLIB) $(LIBTARGET)
$(DYLIBTARGET) : $(OBJS) $(DYLIBTARGET) : $(OBJS)
$(CC) -o $(DYLIBTARGET) $(LIBFLAGS) -shared $(OBJS) $(CC) -o $(DYLIBTARGET) $(LIBFLAGS) -shared $(OBJS)
install: build install:
install $(LIBTARGET) $(HDRS) $(TARGET) install $(DYLIBTARGET) $(HDRS) $(TARGET)
${IDRIS2} --install network.ipkg ${IDRIS2} --install network.ipkg
clean : clean :
rm -rf $(OBJS) $(LIBTARGET) $(DYLIBTARGET) build rm -rf $(OBJS) $(LIBTARGET) $(DYLIBTARGET) build
test: $(DYLIBTARGET)
$(CC) -o network-tests -L. -I. -l$(LIBNAME) test.c
./network-tests
$(OBJS): $(HDRS) $(OBJS): $(HDRS)
all: $(DYLIBTARGET) $(LIBTARGET) all: $(DYLIBTARGET) $(LIBTARGET)
${IDRIS2} --build network1.ipkg ${IDRIS2} --build network.ipkg
.PHONY: build install clean .PHONY: build install clean

12
libs/network/test.c Normal file
View File

@ -0,0 +1,12 @@
#include <assert.h>
#include <stdio.h>
#include "idris_net.h"
int main(int argc, char**argv) {
int eagain = idrnet_geteagain();
assert(eagain == 35);
printf("network library tests SUCCESS\n");
return 0;
}