Add autotest for mkpath() and makepath()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2015-08-22 23:01:15 +02:00
parent b59249714b
commit 57c49bfe0c
4 changed files with 26 additions and 21 deletions
+1 -14
View File
@@ -27,17 +27,9 @@ NAME = libite
PKG = $(NAME)-$(VERSION)
ARCHIVE = $(PKG).tar.xz
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
STRIP ?= $(CROSS)strip
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
CFLAGS += -fPIC
CFLAGS += -Os
CPPFLAGS += -D_GNU_SOURCE
CPPFLAGS += -W -Wall
ARFLAGS = crus
DISTFILES = README LICENSE
HEADERS = lite.h
@@ -54,12 +46,6 @@ SYMLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a
TARGET = $(STATICLIB) $(SOLIB)
# Default install paths
prefix ?= /usr/local
libdir ?= $(prefix)/lib
datadir ?= $(prefix)/share/doc/$(LIBNAME)
incdir ?= $(prefix)/include
# This magic trick looks like a comment, but works on BSD PMake
#include <rules.mk>
include rules.mk
@@ -69,6 +55,7 @@ test:
$(MAKE) -f copyfile.mk
$(MAKE) -f dir.mk
$(MAKE) -f fsendfile.mk
$(MAKE) -f makepath.mk
$(MAKE) -f pidfilefn.mk
$(MAKE) -f rsync.mk
+6 -5
View File
@@ -55,7 +55,7 @@ int makepath(char *dir)
/********************************* UNIT TESTS ************************************/
#ifdef UNITTEST
#include <stdio.h>
#include "lite.h"
int checkpath(char *dir)
{
@@ -63,7 +63,8 @@ int checkpath(char *dir)
struct stat sb;
snprintf(tmp, sizeof(tmp), "ls -ld %s", dir);
system(tmp);
if (system(tmp))
perror("system");
if (!stat(dir, &sb) && S_ISDIR(sb.st_mode))
return 0;
@@ -98,11 +99,11 @@ int main(void)
NULL
};
fprintf(stderr, "Testing makepath() ...\n");
printf("Testing makepath() ...\n");
for (i = 0; list[i] && !ret; i++)
ret = test_makepath(list[i]);
fprintf(stderr, "\nCleaning up ...\n");
printf("\nCleaning up ...\n");
for (i = 0; list[i]; i++)
rmdir(list[i]);
@@ -112,7 +113,7 @@ int main(void)
/**
* Local Variables:
* compile-command: "gcc -g -o unittest -D_GNU_SOURCE -DUNITTEST makepath.c && ./unittest"
* compile-command: "make V=1 -f makepath.mk"
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
+4
View File
@@ -0,0 +1,4 @@
OBJS =
TARGET = makepath.test clean
include rules.mk
+15 -2
View File
@@ -3,6 +3,15 @@
# Figure out root of library, unless used as submodule
ROOTDIR ?= $(shell pwd)
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
STRIP ?= $(CROSS)strip
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
CPPFLAGS += -D_GNU_SOURCE
ARFLAGS = crus
# Default to silent build, use V=1 to get verbose mode.
ifeq ($V,1)
Q =
@@ -16,7 +25,11 @@ REDIRECT = >/dev/null
MAKEFLAGS = --no-print-directory --silent
endif
export ROOTDIR Q PRINT MAKEFLAGS
# Default install paths
prefix ?= /usr/local
libdir ?= $(prefix)/lib
datadir ?= $(prefix)/share/doc/$(LIBNAME)
incdir ?= $(prefix)/include
# Pretty printing and GCC -M for auto dep files
%.o: %.c
@@ -29,7 +42,7 @@ export ROOTDIR Q PRINT MAKEFLAGS
%.test: %.c
$(PRINT) " TEST $(subst $(ROOTDIR)/,,$(shell pwd)/)$(@:.test=)\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -DUNITTEST $< $(OBJS)
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -g -o $@ -DUNITTEST $< $(OBJS)
$(Q)@./$@ $(REDIRECT)