From 92d81280a9d6687184582da9e9fb96ff44486954 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jun 2016 17:44:54 +0200 Subject: [PATCH] Add unit test for fexist() Signed-off-by: Joachim Nilsson --- fexist.c | 28 ---------------------------- fexist.mk | 4 ---- tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/fexist.c | 23 +++++++++++++++++++++++ 5 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 fexist.mk create mode 100644 tests/fexist.c diff --git a/fexist.c b/fexist.c index 9f665ad..c74e89d 100644 --- a/fexist.c +++ b/fexist.c @@ -44,36 +44,8 @@ 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" * indent-tabs-mode: t * c-file-style: "linux" * End: diff --git a/fexist.mk b/fexist.mk deleted file mode 100644 index 2818a1c..0000000 --- a/fexist.mk +++ /dev/null @@ -1,4 +0,0 @@ -OBJS = -TARGET = fexist.test clean - -include rules.mk diff --git a/tests/.gitignore b/tests/.gitignore index 1ab0c84..7b27f36 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,5 +1,6 @@ *.log *.trs +fexist fisdir fsendfile lfile diff --git a/tests/Makefile.am b/tests/Makefile.am index 6e39b31..9829d01 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = check.h CLEANFILES = *~ *.trs *.log TESTS = +TESTS += fexist TESTS += fisdir TESTS += fsendfile TESTS += lfile diff --git a/tests/fexist.c b/tests/fexist.c new file mode 100644 index 0000000..a18b71f --- /dev/null +++ b/tests/fexist.c @@ -0,0 +1,23 @@ +#include "check.h" + +int main(void) +{ + size_t i = 0; + struct { char *file; int exist; } arr[] = { + { "/etc/passwd", 1 }, + { "/etc/kalle", 0 }, + { "/sbin/init", 1 }, + { "/dev/null", 1 }, + { NULL, 0 }, + }; + + 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; +}