Add test script that does the actual testing
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 13 Oct 2023 13:07:21 +0000 (15:07 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 13 Oct 2023 13:07:21 +0000 (15:07 +0200)
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
src/main.c
test [new file with mode: 0755]

index e1292d55949fde08407704c200a500eb46b5ff9f..dd82e4c829884d03d5cdb2fe41e8ca3f8d36aafa 100644 (file)
--- 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)
 
index 94d8d50240ab8020daf764ff5bb3aef0802ae50b..68a38ecaaca814fc440879d0c0487083a823309b 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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 <fcntl.h>
@@ -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 (executable)
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)\n"
+               else
+                       printf "\033[31m"
+                       printf "$file: KO\n"
+                       printf "diff -y ./correct/$file ./results/$file\n"
+                       printf "$(diff -y ./correct/$file ./results/$file)\n"
+                       printf "$(<tmp)\n"
+               fi
+done
+
+for BS in ${testing_sizes[@]}
+do
+       printf "\033[0m\nTrying BUFFER_SIZE = $BS\n"
+       make --silent BUFFER_SIZE=$BS
+       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)\n"
+               else
+                       printf "\033[31m"
+                       printf "$file: KO\n"
+                       printf "diff -y ./correct/$file ./results/$file\n"
+                       printf "$(diff -y ./correct/$file ./results/$file)\n"
+                       printf "$(<tmp)\n"
+               fi
+       done
+done
+wait
+rm tmp