Add unit test for fisdir()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-06-06 17:42:31 +02:00
parent c22a6e64d9
commit 267465f3d2
5 changed files with 26 additions and 34 deletions
-30
View File
@@ -21,7 +21,6 @@
* THE SOFTWARE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -42,37 +41,8 @@ int fisdir(const char *file)
return 0;
}
#ifdef UNITTEST
#include "lite.h"
int main(void)
{
int i = 0;
struct { char *file; int exist; } arr[] = {
{ "/etc/passwd", 0 },
{ "/etc/", 1 },
{ "/sbin/init", 0 },
{ "/dev/null", 0 },
{ "/dev/", 1 },
{ NULL, 0 },
};
FILE *src, *dst;
for (i = 0; i < NELEMS(arr); i++) {
if (fisdir(arr[i].file) != arr[i].exist)
err(1, "Failed fisdir(%s)", arr[i].file ?: "NULL");
else
printf("fisdir() %-11s %-18s => OK!\n", arr[i].file ?: "NULL",
arr[i].exist ? "is a directory" : "is NOT a directory");
}
return 0;
}
#endif /* UNITTEST */
/**
* Local Variables:
* compile-command: "make V=1 -f fisdir.mk"
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
-4
View File
@@ -1,4 +0,0 @@
OBJS =
TARGET = fisdir.test clean
include rules.mk
+1
View File
@@ -1,5 +1,6 @@
*.log
*.trs
fisdir
fsendfile
lfile
makepath
+1
View File
@@ -2,6 +2,7 @@ EXTRA_DIST = check.h
CLEANFILES = *~ *.trs *.log
TESTS =
TESTS += fisdir
TESTS += fsendfile
TESTS += lfile
TESTS += makepath
+24
View File
@@ -0,0 +1,24 @@
#include "check.h"
int main(void)
{
size_t i = 0;
struct { char *file; int exist; } arr[] = {
{ "/etc/passwd", 0 },
{ "/etc/", 1 },
{ "/sbin/init", 0 },
{ "/dev/null", 0 },
{ "/dev/", 1 },
{ NULL, 0 },
};
for (i = 0; i < NELEMS(arr); i++) {
if (fisdir(arr[i].file) != arr[i].exist)
err(1, "Failed fisdir(%s)", arr[i].file ?: "NULL");
else
printf("fisdir() %-11s %-18s => OK!\n", arr[i].file ?: "NULL",
arr[i].exist ? "is a directory" : "is NOT a directory");
}
return 0;
}