Skip to content

Commit 5516b06

Browse files
committed
💲
1 parent b8d3d6d commit 5516b06

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

ctest.sh

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ if [ ! -d "$DIR" ]; then
4242
exit 1
4343
fi
4444

45-
readarray -d '' infiles < <(printf '%s\0' ./tests/*.in | sort -zV)
46-
len=${#infiles[@]}
47-
if [ $len -eq 0 ]; then
45+
readarray -d '' INFILES < <(printf '%s\0' ./tests/*.in | sort -zV)
46+
LEN=${#INFILES[@]}
47+
if [ $LEN -eq 0 ]; then
4848
echo "No test cases found!"
4949
exit 1
5050
fi
@@ -53,20 +53,20 @@ if [ -t 1 ]; then echo -e "${CYANBACK} ==:: TEST RESULTS ::== ${ENDCOLOR}"
5353
else echo "==:: TEST RESULTS ::=="; fi
5454
echo
5555

56-
for infile in "${infiles[@]}"; do
57-
if [ -t 1 ]; then echo -e "${BOLDBLUE}Test ${infile:8} ${ENDCOLOR}"
56+
for INFILE in "${INFILES[@]}"; do
57+
if [ -t 1 ]; then echo -e "${BOLDBLUE}Test ${INFILE:8} ${ENDCOLOR}"
5858
echo -e "${BOLDBLUE}---------- ${ENDCOLOR}"
59-
else echo -e "Test $infile\n---------- "; fi
60-
outfile="${infile%.*}.out"
61-
if [ ! -f "$outfile" ]; then
62-
echo -e "Test file $outfile not found!\n"
59+
else echo -e "Test $INFILE\n---------- "; fi
60+
OUTFILE="${INFILE%.*}.out"
61+
if [ ! -f "$OUTFILE" ]; then
62+
echo -e "Test file $OUTFILE not found!\n"
6363
continue
6464
else
65-
dif="$(diff "$outfile" <(./a.out < "$infile"))"
66-
if [ -n "$dif" ]; then
65+
DIF="$(diff "$OUTFILE" <(./a.out < "$INFILE"))"
66+
if [ -n "$DIF" ]; then
6767
if [ -t 1 ]; then echo -e "${RED}Test failed.${ENDCOLOR}
68-
\nDifference : ${RED}$dif${ENDCOLOR}\n"
69-
else echo -e "FAILED.\nDifference : $dif\n"; fi
68+
\nDifference : ${RED}$DIF${ENDCOLOR}\n"
69+
else echo -e "FAILED.\nDifference : $DIF\n"; fi
7070
else
7171
if [ -t 1 ]; then echo -e "${GREEN}PASSED!${ENDCOLOR}\n"
7272
else echo -e "PASSED!\n"; fi
@@ -83,32 +83,32 @@ else echo -e "Valgrind test\n------------- "; fi
8383
if ! [ -x "$(command -v valgrind)" ]; then
8484
echo -e "Test failed. Valgrind not installed.\n"
8585
else
86-
TEST=$(valgrind ./a.out < "${infiles["$((len-1))"]}" 2>&1 >/dev/null)\
86+
TEST=$(valgrind ./a.out < "${INFILES["$((LEN-1))"]}" 2>&1 >/dev/null)\
8787
CHECK1=$(echo "$TEST" | grep -c "in use at exit: 0 bytes in 0 blocks")
8888
CHECK2=$(echo "$TEST" | grep -c "0 errors from 0 contexts")
8989
if [[ $CHECK1 -ne 0 && $CHECK2 -ne 0 ]]; then
9090
if [ -t 1 ]; then echo -e "${GREEN}PASSED!\n${ENDCOLOR}"
9191
else echo -e "PASSED!\n"; fi
9292
PASSED=$((PASSED + 1))
9393
else
94-
if [ -t 1 ]; then echo -e "${RED}Memory leaks detected!\n${ENDCOLOR}"
95-
else echo -e "Memory leaks detected!\n"; fi
94+
if [ -t 1 ]; then echo -e "${RED}Memory issues detected!\n${ENDCOLOR}"
95+
else echo -e "Memory issues detected!\n"; fi
9696
fi
9797
fi
9898

99-
len=$((len + 1)) # Add 1 for valgrind test
99+
LEN=$((LEN + 1)) # Add 1 for valgrind test
100100

101-
if [ $PASSED -eq $len ]; then
101+
if [ $PASSED -eq $LEN ]; then
102102
if [ -t 1 ]; then echo -e "${GREEN}You have passed all tests! \(ᵔᵕᵔ)/${ENDCOLOR}"
103103
else echo "All tests passed!"; fi
104-
elif [ $PASSED -eq $(($len-1)) ]; then
105-
if [ -t 1 ]; then echo -e "${MAGENTA}You have passed $PASSED out of $len tests."
104+
elif [ $PASSED -eq $(($LEN-1)) ]; then
105+
if [ -t 1 ]; then echo -e "${MAGENTA}You have passed $PASSED out of $LEN tests."
106106
echo -e "Almost there...! (◎_◎)${ENDCOLOR}"
107-
else echo -e "Passed $PASSED out of $len tests."; fi
107+
else echo -e "Passed $PASSED out of $LEN tests."; fi
108108
else
109-
if [ -t 1 ]; then echo -e "${MAGENTA}You have passed $PASSED out of $len tests.
109+
if [ -t 1 ]; then echo -e "${MAGENTA}You have passed $PASSED out of $LEN tests.
110110
(._.)${ENDCOLOR}"
111-
else echo "Passed $PASSED out of $len tests."; fi
111+
else echo "Passed $PASSED out of $LEN tests."; fi
112112
fi
113113
echo
114114

0 commit comments

Comments
 (0)