@@ -90,12 +90,18 @@ for INFILE in "${INFILES[@]}"; do
90
90
echo -e " Test file $OUTFILE not found!\n"
91
91
continue
92
92
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 " ) ) "
95
97
if [ -n " $DIF " ]; then
98
+ # test failed
96
99
if [ -t 1 ]; then echo -e $( red " Test failed." )
97
100
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
99
105
echo " $DIF " | (while [[ $EXP -lt 6 ]] && read -r line; do
100
106
if [[ $line == " <" * ]]; then
101
107
if [ -t 1 ]; then echo -e " $( green " $line " ) "
@@ -112,16 +118,22 @@ for INFILE in "${INFILES[@]}"; do
112
118
fi
113
119
done
114
120
while [[ $GOT -ne $EXP ]]; do
115
- # get the next > lines until EXP == GOT
121
+ # get next > lines until they match the number of < lines
116
122
read -r line
117
123
if [[ $line == " >" * ]]; then
118
124
if [ -t 1 ]; then echo -e " $( red " $line " ) "
119
125
else echo -e " $line " ; fi
120
126
GOT=$(( GOT + 1 ))
121
127
fi
122
128
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
123
134
echo)
124
135
else
136
+ # test passed
125
137
if [ -t 1 ]; then
126
138
echo -e $( green " PASSED!" )
127
139
echo
0 commit comments