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.
GNLOBJS = $(GNLSRCS:%.c=$(OBJDIR)%.o)
-NAME = test_ex
+NAME = tester
all : $(NAME)
/* 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 */
/* */
/* ************************************************************************** */
#endif
#ifndef SEPARATOR
-# define SEPARATOR "---------------------\n"
+# define SEPARATOR "---------------------"
#endif
#include <fcntl.h>
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 ;
}
--- /dev/null
+#!/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