From 4e996925727f2b43872fc70f5c59e64cdf638bde Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Fri, 13 Oct 2023 15:07:21 +0200 Subject: [PATCH] Add test script that does the actual testing Implement test script in bash that handles the testing logic. Also change Makefile and src/main.c a little to accomodate the changes. The test script handles the following functionality: - Handle creation of correct results to compare with - Recompile gnl functions for testing with different BUFFER_SIZE - Run the tester executable on tests in test_files/ - Print the results of the test in color including the output of valgrind and diff when necessary. --- Makefile | 2 +- src/main.c | 17 ++++++++++----- test | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100755 test diff --git a/Makefile b/Makefile index e1292d5..dd82e4c 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ OBJS = $(SRCS:%.c=$(OBJDIR)%.o) GNLOBJS = $(GNLSRCS:%.c=$(OBJDIR)%.o) -NAME = test_ex +NAME = tester all : $(NAME) diff --git a/src/main.c b/src/main.c index 94d8d50..68a38ec 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/12 14:52:24 by ljiriste #+# #+# */ -/* Updated: 2023/10/12 14:57:56 by ljiriste ### ########.fr */ +/* Updated: 2023/10/13 13:54:26 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ #endif #ifndef SEPARATOR -# define SEPARATOR "---------------------\n" +# define SEPARATOR "---------------------" #endif #include @@ -67,11 +67,18 @@ void test_gnl(int testfd, int resfd) while (line) { ft_putstr_fd(line, resfd); + if (last_char(line) == '\n') + { + ft_putstr_fd(SEPARATOR, resfd); + ft_putstr_fd("\n", resfd); + } + else + { + ft_putstr_fd("\n", resfd); + ft_putstr_fd(SEPARATOR, resfd); + } free(line); line = get_next_line(testfd); - if (line) - if (last_char(line) == '\n') - ft_putstr_fd(SEPARATOR, resfd); } return ; } diff --git a/test b/test new file mode 100755 index 0000000..ddc763c --- /dev/null +++ b/test @@ -0,0 +1,62 @@ +#!/bin/bash + +git pull + +mkdir -p correct +SEP="---------------------" +wait +for file in $(ls test_files/) +do + sed "s/$/\n$SEP/g" test_files/$file > correct/$file +done + + +mkdir -p results +testing_sizes=(1 2 3 4 10 16 42 100 200 500 1000 9999 10000000) + +printf "Compiling without externally providing BUFFER_SIZE\n" +make --silent +wait +for file in $(ls test_files/) +do + valgrind --leak-check=full ./tester $file 2> tmp + wait + if $(cmp -s ./correct/$file ./results/$file) + then + printf "\033[32m" + printf "$file: OK\n" + printf "$( tmp + wait + if $(cmp -s ./correct/$file ./results/$file) + then + printf "\033[32m" + printf "$file: OK\n" + printf "$(