1+ #! /bin/bash
2+
3+ # RED="\e[41m"
4+ # GREEN="\e[42m"
5+ # BOLD="\e[1m"
6+ # DEFAULT="\e[0m"
7+
8+ FILE=$1
9+ failed=0
10+
11+ if [ ! -e " $FILE " ]; then
12+ echo -e " Given file does not exist - $FILE "
13+ exit 1
14+ fi
15+
16+ function check()
17+ {
18+ if [ " $1 " != 0 ]; then
19+ echo -e ❌ $RED " FAILED ON" " $@ " $DEFAULT
20+ (( failed+= 1 ))
21+ else
22+ echo -e ✅ $GREEN " FOUND" $DEFAULT
23+ fi
24+ }
25+
26+ function negative_check()
27+ {
28+ if [ " $1 " == 0 ]; then
29+ echo -e ❌ $RED " FAILED ON" " $@ " $DEFAULT
30+ (( failed+= 1 ))
31+ else
32+ echo -e ✅ $GREEN " NOT FOUND" $DEFAULT
33+ fi
34+ }
35+
36+ function min_2_allowed_check()
37+ {
38+ if [ " $1 " -lt 2 ]; then
39+ echo -e ❌ $RED " FAILED ON" " $@ " $DEFAULT
40+ (( failed+= 1 ))
41+ else
42+ echo -e ✅ $GREEN " OK" $DEFAULT
43+ fi
44+ }
45+
46+ function positive_lookup()
47+ {
48+ echo -e " ---"
49+ echo -e 🔍 $BOLD " CHECKING: $1 " $DEFAULT
50+ egrep " $2 " " $FILE "
51+ check $? $1
52+ }
53+
54+ function negative_lookup()
55+ {
56+ echo -e " ---"
57+ echo -e 🔍 $BOLD " CHECKING: $1 " $DEFAULT
58+ egrep " $2 " " $FILE "
59+ negative_check $? $1
60+ }
61+
62+ function min_2_allowed_lookup()
63+ {
64+ echo -e " ---"
65+ echo -e 🔍 $BOLD " CHECKING: $1 " $DEFAULT
66+ min_2_allowed_check ` egrep " $2 " " $FILE " -c` $1
67+ }
68+
69+ function does_file_exist()
70+ {
71+ echo -e " ---"
72+ echo -e 🔍 $BOLD " CHECKING: $1 " $DEFAULT
73+ if [[ -f " $1 " ]]; then
74+ echo -e ✅ $GREEN " FILE EXISTS" $DEFAULT
75+ else
76+ echo -e ❌ $RED " FILE DOES NOT EXIST" $DEFAULT
77+ (( failed+= 1 ))
78+ fi
79+ }
80+
81+ echo -e $BOLD " Performing checks on $FILE " $DEFAULT
82+
83+ does_file_exist $FILE
84+ min_2_allowed_lookup " should have more than 1 add_executable" " add_executable"
85+ positive_lookup " should have enable_testing" " enable_testing"
86+ positive_lookup " should have add_test" " add_test"
87+
88+ echo -e " ==="
89+
90+ if [ $failed == 0 ]; then
91+ echo -e 💚💚💚 $GREEN " ALL CHECKS PASSED" 💚💚💚 $DEFAULT
92+ else
93+ echo -e ❗️❗️❗️ $RED $failed " CHECKS FAILED" ❗️❗️❗️ $DEFAULT
94+ fi
95+
96+ exit $failed
0 commit comments