From bd69aad13afd0a4592faa01a52648712e5f6bf9f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 22 Aug 2015 22:22:14 +0200 Subject: [PATCH] Add autotest for copyfile et al. Signed-off-by: Joachim Nilsson --- Makefile | 1 + copyfile.c | 27 ++++++++++++++++----------- copyfile.mk | 4 ++++ 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 copyfile.mk diff --git a/Makefile b/Makefile index 0e66e6d..98d1a20 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ include rules.mk test: $(MAKE) -f chomp.mk + $(MAKE) -f copyfile.mk $(MAKE) -f rsync.mk $(OBJS): Makefile diff --git a/copyfile.c b/copyfile.c index 7a4396f..f41f0c3 100644 --- a/copyfile.c +++ b/copyfile.c @@ -261,6 +261,8 @@ int fcopyfile(FILE *src, FILE *dst) } #ifdef UNITTEST +#include + int main(void) { int i = 0; @@ -272,14 +274,15 @@ int main(void) }; FILE *src, *dst; - fprintf(stderr, "\n=>Start testing copy_filep()\n"); + printf("=>Start testing fcopyfile()\n"); while (files[i]) { - fprintf(stderr, "fcopyfile(%s, %s)\t", files[i], - files[i + 1]); + printf("fcopyfile(%s, %s)\t", files[i], files[i + 1]); src = fopen(files[i], "r"); dst = fopen(files[i + 1], "w"); - if (fcopyfile(src, dst)) - perror("Failed"); + if (fcopyfile(src, dst)) { + if (!fisdir(files[i + 1])) + err(1, "Failed fcopyfile(%s, %s)", files[i], files[i + 1]); + } if (src) fclose(src); @@ -287,21 +290,23 @@ int main(void) fclose(dst); if (fexist(files[i + 2])) - fprintf(stderr, "OK => %s\n", files[i + 2]); + printf("OK => %s", files[i + 2]); + printf("\n"); erase(files[i + 2]); i += 3; } - printf("\n\n=>Start testing copyfile()\n"); + printf("\n=>Start testing copyfile()\n"); i = 0; while (files[i]) { - fprintf(stderr, "copyfile(%s, %s)\t", files[i], files[i + 1]); + printf("copyfile(%s, %s)\t", files[i], files[i + 1]); if (!copyfile(files[i], files[i + 1], 0, 0)) - perror("Failed"); + err(1, "Failed copyfile(%s, %s)", files[i], files[i + 1]); if (fexist(files[i + 2])) - fprintf(stderr, "OK => %s\n", files[i + 2]); + printf("OK => %s", files[i + 2]); + printf("\n"); erase(files[i + 2]); i += 3; @@ -313,7 +318,7 @@ int main(void) /** * Local Variables: - * compile-command: "gcc -g -o coppy -DUNITTEST copyfile.c fisdir.c fexist.c fmode.c && ./coppy" + * compile-command: "make V=1 -f copyfile.mk" * version-control: t * indent-tabs-mode: t * c-file-style: "linux" diff --git a/copyfile.mk b/copyfile.mk new file mode 100644 index 0000000..b08c2ae --- /dev/null +++ b/copyfile.mk @@ -0,0 +1,4 @@ +OBJS = fisdir.o fexist.o fmode.o +TARGET = $(OBJS) copyfile.test clean + +include rules.mk