@@ -3,11 +3,19 @@ ref_file="../.ref_solutions/$dir_name.txt"
3
3
sol_file="../$dir_name.txt"
4
4
tmp_file='../.tmp.txt'
5
5
6
- # color output - need to check if Terminal supports!
7
- red=$(tput setaf 1)
8
- green=$(tput setaf 2)
9
- blue=$(tput setaf 4)
10
- clr_color=$(tput sgr0)
6
+ # color output
7
+ tcolors=$(tput colors)
8
+ if [[ -n $tcolors && $tcolors -ge 8 ]]; then
9
+ red=$(tput setaf 1)
10
+ green=$(tput setaf 2)
11
+ blue=$(tput setaf 4)
12
+ clr_color=$(tput sgr0)
13
+ else
14
+ red=''
15
+ green=''
16
+ blue=''
17
+ clr_color=''
18
+ fi
11
19
12
20
sub_sol=0
13
21
if [[ $1 == -s ]]; then
@@ -18,10 +26,14 @@ elif [[ $1 == -q ]]; then
18
26
# or show only the (unanswered)? question to be solved next
19
27
cat "$sol_file"
20
28
return
29
+ elif [[ -n $1 ]]; then
30
+ echo -e 'Unknown option...Exiting script'
31
+ return
21
32
fi
22
33
23
34
count=0
24
35
sol_count=0
36
+ err_count=0
25
37
while IFS= read -u3 -r ref_line && read -u4 -r sol_line; do
26
38
if [[ "${ref_line:0:9}" == Solution: ]]; then
27
39
(( count++ ))
@@ -31,7 +43,7 @@ while IFS= read -u3 -r ref_line && read -u4 -r sol_line; do
31
43
sub_sol=0
32
44
fi
33
45
34
- if [[ $(eval "${ref_line:10}") == $(eval "$sol_line") ]]; then
46
+ if [[ $(eval "command ${ref_line:10}") == $(eval "command $sol_line") ]]; then
35
47
(( sol_count++ ))
36
48
# use color if terminal supports
37
49
echo '---------------------------------------------'
@@ -40,6 +52,14 @@ while IFS= read -u3 -r ref_line && read -u4 -r sol_line; do
40
52
echo "${green}Reference solution:${clr_color} ${ref_line:10}"
41
53
echo '---------------------------------------------'
42
54
else
55
+ (( err_count++ ))
56
+ if [[ $err_count == 1 && -n $sol_line ]]; then
57
+ echo '---------------------------------------------'
58
+ echo "Mismatch for question $count:"
59
+ echo "$(tput bold)${red}Expected output is:${clr_color}$(tput rmso)"
60
+ eval "command ${ref_line:10}"
61
+ echo '---------------------------------------------'
62
+ fi
43
63
sol_line=''
44
64
fi
45
65
fi
0 commit comments