Skip to content

Commit

Permalink
improve diff files
Browse files Browse the repository at this point in the history
  • Loading branch information
vitoriagalli committed Sep 26, 2020
1 parent e390586 commit 4637fd1
Show file tree
Hide file tree
Showing 53 changed files with 301 additions and 258 deletions.
33 changes: 6 additions & 27 deletions unit_tests/run_atoi_base.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
#! /bin/bash

initialize_expected_results ()
{
echo "56" > 0.exp.txt
echo "-255" > 1.exp.txt
echo "-42" > 2.exp.txt
echo "29" > 3.exp.txt
echo "-501" > 4.exp.txt
echo "105" > 5.exp.txt
echo "-3" > 6.exp.txt
echo "0" > 7.exp.txt
echo "0" > 8.exp.txt
echo "0" > 9.exp.txt
echo "0" > 10.exp.txt
echo "0" > 11.exp.txt
echo "0" > 12.exp.txt
echo "0" > 13.exp.txt
echo "0" > 14.exp.txt
echo "0" > 15.exp.txt
echo "0" > 16.exp.txt
echo "0" > 17.exp.txt
echo "0" > 18.exp.txt
}

test_input()
{
ERROR=$( ./atoi_base "$1" 2>&1 >/dev/null )
if [ $? = 0 ]
then
./atoi_base "$1" > "$1".txt
diff "$1".txt "$1".exp.txt > diffs/atoi_base."$1".txt
DIFF=$(diff "$1".txt "$1".exp.txt)
DIFF=$(diff "$1".txt txt/atoibase/"$1".exp.txt)
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/atoi_base."$1".txt
cat txt/atoibase/"$1".exp.txt >> diffs/atoi_base."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/atoi_base."$1".txt
cat "$1".txt >> diffs/atoi_base."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
rm -rf diffs/atoi_base."$1".txt
fi
rm -f "$1".txt "$1".exp.txt
else
Expand All @@ -46,10 +25,10 @@ test_input()

echo -e ""
echo -e "\033[0;1m> ft_atoi_base\033[0m"

COMP=$( clang testers/test_atoi_base.c -L. -lasm -o atoi_base 2>&1 >/dev/null )
if [ $? = 0 ]
then
initialize_expected_results
clang -Wall -Werror -Wextra testers/test_atoi_base.c -L. -lasm -o atoi_base
for i in {0..18}
do
Expand Down
33 changes: 19 additions & 14 deletions unit_tests/run_linked_list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@
test_leak()
{
valgrind --leak-check=full \
--log-file=valgrind."$1".txt \
--log-file=valgrind.txt \
./"$FUNCT" "$1" 2>&1 >/dev/null
MEM=$(cat valgrind."$1".txt | grep "All heap blocks were freed -- no leaks are possible")
MEM=$(cat valgrind.txt | grep "All heap blocks were freed -- no leaks are possible")
if [ "$MEM" = "" ]
then
echo -e "\033[0;31m[LEAK]\033[0m"
else
echo -e "\033[0;32m[NO_LEAK]\033[0m"
fi
rm -f valgrind."$1".txt
rm -f valgrind.txt
}

test_function()
test_output()
{
./"$FUNCT" "$1" > "$1".txt
diff "$1".txt txt/"$FUNCT"."$1".exp.txt > diffs/"$FUNCT"."$1".txt
DIFF=$(diff "$1".txt txt/"$FUNCT"."$1".exp.txt)
DIFF=$(diff "$1".txt txt/linkedlist/"$FUNCT"."$1".exp.txt)
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat txt/linkedlist/"$FUNCT"."$1".exp.txt >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat "$1".txt >> diffs/ft_"$FUNCT"."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
rm -rf diffs/"$FUNCT"."$1".txt
fi
rm -f "$1".txt
}
Expand All @@ -35,12 +37,7 @@ test_input()
ERROR=$( ./"$FUNCT" "$1" 2>&1 >/dev/null )
if [ $? = 0 ]
then
if [ "$2" = 'leak' ]
then
test_leak "$1"
else
test_function "$1"
fi
"$TEST" "$1"
else
echo -e "\033[0;31m[ERROR]\033[0m"
fi
Expand All @@ -49,6 +46,14 @@ test_input()
FUNCT=$1
echo -e ""
echo -e "\033[0;1m> ft_"$FUNCT"\033[0m"

if [ "$2" = "leak" ]
then
TEST="test_leak"
else
TEST="test_output"
fi

COMP=$( clang testers/test_linked_list.c testers/test_"$FUNCT".c \
-L. -lasm -o "$FUNCT" 2>&1 >/dev/null )
if [ $? = 0 ]
Expand All @@ -57,7 +62,7 @@ then
testers/test_"$FUNCT".c -L. -lasm -g -o "$FUNCT" 2>&1 >/dev/null
for i in {0..4}
do
test_input $i $2
test_input $i ${INPUT[i]}
done
rm -f "$FUNCT"
else
Expand Down
48 changes: 30 additions & 18 deletions unit_tests/run_stdfunct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,32 @@
test_leak()
{
valgrind --leak-check=full \
--log-file=valgrind."$1".txt \
./"$FUNCT" "$1" 2>&1 >/dev/null
MEM=$(cat valgrind."$1".txt | grep "All heap blocks were freed -- no leaks are possible")
--log-file=valgrind.txt \
./"$FUNCT" "$IMPLEM" "$2" 2>&1 >/dev/null
MEM=$(cat valgrind.txt | grep "All heap blocks were freed -- no leaks are possible")
if [ "$MEM" = "" ]
then
echo -e "\033[0;31m[LEAK]\033[0m"
else
echo -e "\033[0;32m[NO_LEAK]\033[0m"
fi
rm -f valgrind."$1".txt
rm -f valgrind.txt
}

test_function()
test_output()
{
./"$FUNCT" $ORIG "$2" > a
./"$FUNCT" $IMPLEM "$2" > b
diff a b > diffs/ft_"$FUNCT"."$1".txt
DIFF=$(diff a b)
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat a >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat b >> diffs/ft_"$FUNCT"."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
rm -rf diffs/ft_"$FUNCT"."$1".txt
fi
rm -f a b
}
Expand All @@ -36,12 +38,7 @@ test_input()
ERROR=$( ./"$FUNCT" $IMPLEM "$2" 2>&1 >/dev/null )
if [ $? = 0 ]
then
if [ "$3" = 'leak' ] && [ "$FUNCT" = "strdup" ]
then
test_leak "$2"
else
test_function "$1" "$2"
fi
"$TEST" "$1" "$2"
else
echo -e "\033[0;31m[ERROR]\033[0m"
fi
Expand All @@ -50,15 +47,30 @@ test_input()
FUNCT=$1
echo -e ""
echo -e "\033[0;1m> ft_"$FUNCT"\033[0m"

INPUT=(
"Hello World!"
"lorem\tipsum\tdolor\nsit\namet\n"
"testing functions\0123456789"
""
" "
)

if [ "$2" = "leak" ]
then
TEST="test_leak"
else
TEST="test_output"
fi

COMP=$( clang testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT" 2>&1 >/dev/null )
if [ $? = 0 ]
then
clang -Wall -Werror -Wextra testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT"
test_input 1 "Hello World!" "$2"
test_input 2 "lorem\tipsum\tdolor\nsit\namet\n" "$2"
test_input 3 "\n\n\f\r\t" "$2"
test_input 4 "" "$2"
test_input 5 " " "$2"
for i in {0..4}
do
test_input $i ${INPUT[i]}
done
rm -f "$FUNCT"
else
echo -e "\033[0;31m[DONT COMPILE]\033[0m"
Expand Down
101 changes: 61 additions & 40 deletions unit_tests/run_syscall.sh
Original file line number Diff line number Diff line change
@@ -1,74 +1,95 @@
#! /bin/bash

make_diff ()
prepare_function()
{
diff "$2" "$3" > diffs/ft_"$FUNCT"."$1".txt
DIFF=$(diff a b)
if [ "$DIFF" != "" ]
if [ "$FUNCT" = "read" ]
then
echo -e "\033[0;31m[KO]\033[0m"
else
echo -e "\033[0;32m[OK]\033[0m"
rm -f diffs/ft_"$FUNCT"."$1".txt
echo "testing read function" > read.txt
echo "testing read function" > ft_read.txt
fi
}

test_std()
check_error()
{
if [ "$FUNCT" == "read" ]
if [ "$FUNCT" = "read" ] && [ $1 = $STD ]
then
echo -e "\e[2mtesting stdin\e[0m"
else
ERROR_STD=$( ./"$FUNCT"_std $IMPLEM 2>&1 >/dev/null )
ERROR_FD=$( ./"$FUNCT" "$1" $IMPLEM ft_"$FUNCT".txt 2>&1 >/dev/null )
fi
if [ $? = 0 ]
}

make_diff ()
{
DIFF=$(diff "$2" "$3")
if [ "$DIFF" != "" ]
then
./"$FUNCT"_std $ORIG > a
./"$FUNCT"_std $IMPLEM > b
make_diff "$1" a b
rm -f a b
echo -e "\033[0;31m[KO]\033[0m"

echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat a >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat b >> diffs/ft_"$FUNCT"."$1".txt

else
echo -e "\033[0;31m[ERROR]\033[0m"
echo -e "\033[0;32m[OK]\033[0m"
rm -f diffs/ft_"$FUNCT"."$1".txt
fi
}

test_fd()
run_compare()
{
if [ "$FUNCT" == "read" ]
then
echo "testing read function" > read.txt
echo "testing read function" > ft_read.txt
fi
ERROR_FD=$( ./"$FUNCT"_fd "$2" $IMPLEM ft_"$FUNCT".txt 2>&1 >/dev/null )
if [ $? = 0 ]
then
./"$FUNCT"_fd "$2" $ORIG "$FUNCT".txt > a
./"$FUNCT"_fd "$2" $IMPLEM ft_"$FUNCT".txt > b
make_diff "$1" "$FUNCT".txt ft_"$FUNCT".txt
make_diff "$1" a b
./"$FUNCT" "$1" "$ORIG" "$FUNCT".txt > a
./"$FUNCT" "$1" "$IMPLEM" ft_"$FUNCT".txt > b
DIFF=$(diff a b)
if [ "$DIFF" != "" ]
then
echo -e "\033[0;31m[KO]\033[0m"
echo "--- EXPECTED RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat "$FUNCT".txt >> diffs/ft_"$FUNCT"."$1".txt
echo "" >> diffs/ft_"$FUNCT"."$1".txt
cat a >> diffs/ft_"$FUNCT"."$1".txt
echo "--- ACTUAL RESULT ---" >> diffs/ft_"$FUNCT"."$1".txt
cat ft_"$FUNCT".txt >> diffs/ft_"$FUNCT"."$1".txt
echo "" >> diffs/ft_"$FUNCT"."$1".txt
cat b >> diffs/ft_"$FUNCT"."$1".txt
else
echo -e "\033[0;32m[OK]\033[0m"
fi
rm -rf a b
rm -rf "$FUNCT".txt ft_"$FUNCT".txt
else
echo -e "\033[0;31m[ERROR]\033[0m"
fi
[ -f read.txt ] && rm read.txt
[ -f ft_read.txt ] && rm ft_read.txt
}

FD_OPEN=0
FD_WRONG=1
test_input()
{
prepare_function
check_error "$1"
run_compare "$1"
}

STD=0
FD_OPEN=1
FD_WRONG=2

FUNCT=$1
echo -e ""
echo -e "\033[0;1m> ft_"$FUNCT"\033[0m"
COMP=$( clang testers/test_"$FUNCT"_fd.c -L. -lasm -o "$FUNCT"_fd 2>&1 >/dev/null )

COMP=$( clang testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT" 2>&1 >/dev/null )
if [ $? = 0 ]
then
clang -Wall -Werror -Wextra testers/test_"$FUNCT"_std.c -L. -lasm -o "$FUNCT"_std
clang -Wall -Werror -Wextra testers/test_"$FUNCT"_fd.c -L. -lasm -o "$FUNCT"_fd
test_std 1
test_fd 2 $FD_OPEN
test_fd 3 $FD_WRONG
rm -f "$FUNCT"_std "$FUNCT"_fd
clang -Wall -Werror -Wextra testers/test_"$FUNCT".c -L. -lasm -o "$FUNCT"
test_input $STD
test_input $FD_OPEN
test_input $FD_WRONG
rm -f "$FUNCT"
else
echo -e "\033[0;31m[DONT COMPILE]\033[0m"
fi

rm -f "$FUNCT".txt
rm -f ft_"$FUNCT".txt
11 changes: 6 additions & 5 deletions unit_tests/testers/header_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vscabell <vscabell@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/21 22:04:20 by vscabell #+# #+# */
/* Updated: 2020/09/24 02:43:44 by vscabell ### ########.fr */
/* Updated: 2020/09/26 18:23:37 by vscabell ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,10 +20,11 @@
# include <errno.h>
# include <fcntl.h>

# define FD_OPEN '0'
# define FD_WRONG '1'
# define ORIG '0'
# define IMPLEM '1'
# define STD 0
# define FD_OPEN 1
# define FD_WRONG 2
# define ORIG 0
# define IMPLEM 1

size_t ft_strlen(const char *s);
char *ft_strcpy(char *dest, const char *src);
Expand Down
Loading

0 comments on commit 4637fd1

Please sign in to comment.