OBJDIR := obj/
INCLUDE := include/
+RESDIR := results/
+TESTDIR := test_files/
+CORDIR := correct/
+
SRCS := $(shell find $(SRCDIR) -name '*.c' -type f -printf "%f\n")
GNLSRCS := get_next_line.c get_next_line_utils.c
GNLBONUS := $(GNLSRCS:%.c=%_bonus.c)
GNLOBJS := $(GNLSRCS:%.c=$(OBJDIR)%.o)
GNLBONUSOBJS = $(GNLBONUS:%.c=$(OBJDIR)%.o)
-TESTDIR := test_files/
-CORDIR := correct/
-TESTFILES := $(shell find $(TESTDIR) -type f | sort)
+TESTFILES := $(shell find $(TESTDIR) -type f -not -path "*/.* | sort) $(TESTDIR).stdin
CORFILES := $(TESTFILES:$(TESTDIR)%=$(CORDIR)%)
NAME = tester
$(CC) $(CFLAGS) $^ -o $@
$(OBJS) : $(OBJDIR)%.o : $(SRCDIR)%.c | $(OBJDIR)
- $(CC) $(CFLAGS) -c $< -o $@ -I$(INCLUDE)
+ $(CC) $(CFLAGS) -c $< -o $@ -I$(INCLUDE) -DTEST_DIR=\"$(TESTDIR)\" -DRESULT_DIR=\"$(RESDIR)\"
$(GNLOBJS) $(GNLBONUSOBJS) : $(OBJDIR)%.o : $(GNLDIR)%.c | $(OBJDIR)
ifndef BUFFER_SIZE
fclean : clean
$(RM) $(NAME) $(BONUS)
+ $(RM) $(CORDIR)* $(RESDIR)*
re : fclean
$(MAKE)
/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/12 14:52:24 by ljiriste #+# #+# */
-/* Updated: 2023/10/26 15:53:28 by ljiriste ### ########.fr */
+/* Updated: 2023/10/27 11:30:50 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
return (fds);
while (i < count)
{
+ if (fname[i][0] == '-' && fname[i][1] == '\0')
+ {
+ fds[i++] = 0;
+ continue ;
+ }
tmp = ft_strdup(TEST_DIR);
path = ft_strjoin(tmp, fname[i]);
fds[i++] = open(path, O_RDONLY);
void close_all(int count, int *fds)
{
while (count > 0)
- close(fds[--count]);
+ {
+ if (fds[--count] == 0)
+ continue ;
+ close(fds[count]);
+ }
free(fds);
return ;
}
for arg in "$@"
do
- if [ $arg == 'a' ]
+ if [ "$arg" == 'a' ]
then
b=1
m=1
- elif [ $arg == 'b' ]
+ elif [ "$arg" == 'b' ]
then
b=1
- elif [ $arg == 'm' ]
+ elif [ "$arg" == 'm' ]
then
m=1
fi
fi
printf "\033[32mCompilation successful\n\033[0m"
- make --silent all_tests SEP=$SEP
+ make --silent all_tests SEP="$SEP"
wait
+ valgrind --quiet --leak-check=full --log-file='tmp' ./tester - <test_files/.stdin > /dev/null
+ wait
+ if $(cmp -s ./correct/- ./results/-)
+ then
+ printf "\033[32m"
+ printf "stdin: OK\n"
+ printf "$(<tmp)\n"
+ else
+ printf "\033[31m"
+ printf "stdin: KO\n"
+ printf "diff -y ./correct/"$file" ./results/"$file"\n"
+ printf "$(diff -y ./correct/"$file" ./results/"$file")\n"
+ printf "$(<tmp)\n"
+ fi
+
for file in $(ls test_files/)
do
- valgrind --quiet --leak-check=full --log-file='tmp' ./tester $file > /dev/null
+ valgrind --quiet --leak-check=full --log-file='tmp' ./tester "$file" > /dev/null
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
+ 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[@]}
wait
for file in $(ls test_files/)
do
- valgrind --quiet --leak-check=full --log-file='tmp' ./tester $file > /dev/null
+ valgrind --quiet --leak-check=full --log-file='tmp' ./tester "$file" > /dev/null
wait
- if $(cmp -s ./correct/$file ./results/$file)
+ if $(cmp -s ./correct/"$file" ./results/"$file")
then
printf "\033[32m"
printf "$file: OK\n"
printf "\033[31m"
printf "$file: KO\n"
printf "diff -y ./correct/$file ./results/$file\n"
- printf "$(diff -y ./correct/$file ./results/$file)\n"
+ printf "$(diff -y ./correct/"$file" ./results/"$file")\n"
printf "$(<tmp)\n"
fi
done
printf "\033[0m\nTrying BUFFER_SIZE = $BS\n"
make --silent bonus BUFFER_SIZE=$BS
wait
- mix_res_path=$(valgrind --quiet --leak-check=full --log-file='tmp' ./tester_bonus $(find ./test_files/ -type f -printf "%f\n" | sort))
+ mix_res_path=$(valgrind --quiet --leak-check=full --log-file='tmp' ./tester_bonus - $(find ./test_files/ -type f -not -path "*/.*" -printf "%f\n" | sort) <test_files/.stdin)
if $(cmp -s ./correct/mix $mix_res_path)
then
printf "\033[32m"