forked from coders-school/object-oriented-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.sh
More file actions
89 lines (75 loc) · 2.44 KB
/
check.sh
File metadata and controls
89 lines (75 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
#RED="\e[41m"
#GREEN="\e[42m"
#BOLD="\e[1m"
#DEFAULT="\e[0m"
FILE=$1
failed=0
if [ ! -e "$FILE" ]; then
echo -e "Given file does not exist - $FILE"
exit 1
fi
function check()
{
if [ "$1" != 0 ]; then
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
((failed+=1))
else
echo -e ✅ $GREEN "FOUND" $DEFAULT
fi
}
function negative_check()
{
if [ "$1" == 0 ]; then
echo -e ❌ $RED "FAILED ON" "$@" $DEFAULT
((failed+=1))
else
echo -e ✅ $GREEN "NOT FOUND" $DEFAULT
fi
}
function positive_lookup()
{
echo -e "---"
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
pcregrep -M "$2" "$FILE"
check $? $1
}
function negative_lookup()
{
echo -e "---"
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
pcregrep -M "$2" "$FILE"
negative_check $? $1
}
function does_file_exist()
{
echo -e "---"
echo -e 🔍 $BOLD "CHECKING: $1" $DEFAULT
if [[ -f "$1" ]]; then
echo -e ✅ $GREEN "FILE EXISTS" $DEFAULT
else
echo -e ❌ $RED "FILE DOES NOT EXIST" $DEFAULT
((failed+=1))
fi
}
echo -e $BOLD "Performing checks on $FILE" $DEFAULT
# Part 1
positive_lookup "\${PROJECT_NAME}" "[$]\{PROJECT_NAME\}"
positive_lookup "source files list in the variable named with UPPERCASE_WITH_UNDERSCORE convention" "set\([A-Z_]*(\s+(.*\.cpp))+\)"
positive_lookup "static library with source files list or cpp files mentioned directly" "add_library\(.*STATIC.*(\s.*cpp)+\)|add_library\(.*STATIC\s+([\$\{A-Z_\}]*)\)"
negative_lookup "static library should not have main.cpp" "add_library\(.*STATIC(\s.*\.cpp)*(\s+main\.cpp)+\)"
positive_lookup "executable with main.cpp" "add_executable\([$]{PROJECT_NAME}\s+main\.cpp\)"
positive_lookup "executable should be linked with the library" "target_link_libraries\([\$]\{PROJECT_NAME\}\s.+\)"
does_file_exist ".github/workflows/main.yml"
# Part 2
does_file_exist "CMakeLists.txt.in"
positive_lookup "binary with tests exist" "add_executable\([\$]\{PROJECT_NAME\}-ut(\s+[[:word:]]+\.cpp)+\)|add_executable\([\$]\{PROJECT_NAME\}-ut\s+([\$\{A-Z_\}]*)\)"
positive_lookup "test binary added to ctest" "add_test\(NAME.*\s+COMMAND\s+[\$]\{PROJECT_NAME\}-ut\)"
positive_lookup "testing is enabled" "enable_testing\(\)"
echo -e "==="
if [ $failed == 0 ]; then
echo -e 💚💚💚 $GREEN "ALL CHECKS PASSED" 💚💚💚 $DEFAULT
else
echo -e ❗️❗️❗️ $RED $failed "CHECKS FAILED" ❗️❗️❗️ $DEFAULT
fi
exit $failed