diff --git a/Makefile b/Makefile index 709288c..c7f3840 100644 --- a/Makefile +++ b/Makefile @@ -50,10 +50,11 @@ TARGET = $(STATICLIB) $(SOLIB) #include include rules.mk -test: +test: clean $(MAKE) -f chomp.mk $(MAKE) -f copyfile.mk $(MAKE) -f dir.mk + $(MAKE) -f fexist.mk $(MAKE) -f fsendfile.mk $(MAKE) -f makepath.mk $(MAKE) -f pidfilefn.mk diff --git a/fexist.c b/fexist.c index 88e6af7..9080907 100644 --- a/fexist.c +++ b/fexist.c @@ -44,8 +44,36 @@ int fexist(char *file) return 1; } +#ifdef UNITTEST +#include "lite.h" + +int main(void) +{ + int i = 0; + struct { char *file; int exist; } arr[] = { + { "/etc/passwd", 1 }, + { "/etc/kalle", 0 }, + { "/sbin/init", 1 }, + { "/dev/null", 1 }, + { NULL, 0 }, + }; + FILE *src, *dst; + + for (i = 0; i < NELEMS(arr); i++) { + if (fexist(arr[i].file) != arr[i].exist) + err(1, "Failed fexist(%s)", arr[i].file ?: "NULL"); + else + printf("File %-11s %-14s => OK!\n", arr[i].file ?: "NULL", + arr[i].exist ? "does exist" : "does not exist"); + } + + return 0; +} +#endif /* UNITTEST */ + /** * Local Variables: + * compile-command: "make V=1 -f fexist.mk" * version-control: t * indent-tabs-mode: t * c-file-style: "linux" diff --git a/fexist.mk b/fexist.mk new file mode 100644 index 0000000..2818a1c --- /dev/null +++ b/fexist.mk @@ -0,0 +1,4 @@ +OBJS = +TARGET = fexist.test clean + +include rules.mk