Skip to content

Commit 1bb782e

Browse files
committed
💲
1 parent 29d4cba commit 1bb782e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ctest.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,18 @@ for INFILE in "${INFILES[@]}"; do
9090
echo -e "Test file $OUTFILE not found!\n"
9191
continue
9292
else
93-
OUTPUT=$(./a.out < "$INFILE")
94-
DIF="$(diff -Z "$OUTFILE" <(echo "$OUTPUT"))"
93+
# run the program with the input file
94+
OUTPUT=$(./a.out < "$INFILE")
95+
# compare the output with the expected output
96+
DIF="$(diff -Z "$OUTFILE" <(echo "$OUTPUT"))"
9597
if [ -n "$DIF" ]; then
98+
# test failed
9699
if [ -t 1 ]; then echo -e $(red "Test failed.")
97100
else echo -e "Test failed."; fi
98-
EXP=0; GOT=0
101+
102+
EXP=0; GOT=0 # number of expected and got lines
103+
104+
# print the first 6 mismatches
99105
echo "$DIF" | (while [[ $EXP -lt 6 ]] && read -r line; do
100106
if [[ $line == "<"* ]]; then
101107
if [ -t 1 ]; then echo -e " $(green "$line")"
@@ -112,16 +118,22 @@ for INFILE in "${INFILES[@]}"; do
112118
fi
113119
done
114120
while [[ $GOT -ne $EXP ]]; do
115-
# get the next > lines until EXP == GOT
121+
# get next > lines until they match the number of < lines
116122
read -r line
117123
if [[ $line == ">"* ]]; then
118124
if [ -t 1 ]; then echo -e " $(red "$line")"
119125
else echo -e " $line"; fi
120126
GOT=$((GOT + 1))
121127
fi
122128
done
129+
# indicate if there are more mismatches than shown
130+
LINES=$(echo "$DIF" | grep -c "<")
131+
if [[ $LINES -gt EXP ]]; then
132+
echo -e "\n ... ($((LINES - EXP)) more)"
133+
fi
123134
echo)
124135
else
136+
# test passed
125137
if [ -t 1 ]; then
126138
echo -e $(green "PASSED!")
127139
echo

0 commit comments

Comments
 (0)