forked from fabric8-analytics/fabric8-analytics-rudra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-all.sh
executable file
·115 lines (82 loc) · 2.55 KB
/
check-all.sh
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Script to check the sources for all detectable errors and issues
# error counter
errors=0
# check the terminal and set up the colors for terminal
terminal_setup() {
# try to detect the terminal
TERM=${TERM:-xterm}
# set up terminal colors
NORMAL=$(tput sgr0)
RED=$(tput bold && tput setaf 1)
GREEN=$(tput bold && tput setaf 2)
YELLOW=$(tput bold && tput setaf 3)
BLUE=$(tput bold && tput setaf 4)
}
# run selected checker or test script
run_checker() {
local cmd="$1.sh"
local log="$1.log"
local err="$1.err"
# run the checker, redirect all logs and errors
"./${cmd}" > "${log}" 2> "${err}"
return $?
}
# check results
check_results() {
if [ "$1" -eq 0 ]
then
printf " %sOK%s\n" "${GREEN}" "${NORMAL}"
else
printf " %sError%s: " "${RED}" "${NORMAL}"
printf "please look into files %s%s.log%s and %s%s.err%s for possible causes\n" "${BLUE}" "$2" "${NORMAL}" "${BLUE}" "$2" "${NORMAL}"
errors=$((errors+1))
fi
}
# run all checkers
run_all_checkers() {
printf "%sRunning all tests and checkers%s\n" "${YELLOW}" "${NORMAL}"
echo " Check all BASH scripts"
run_checker check-bashscripts
check_results $? check-bashscripts
echo " Check documentation strings in all Python source file"
run_checker check-docstyle
check_results $? check-docstyle
echo " Detect common errors in all Python source file"
run_checker detect-common-errors
check_results $? detect-common-errors
echo " Detect dead code in all Python source file"
run_checker detect-dead-code
check_results $? detect-dead-code
echo " Run Python linter for Python source file"
run_checker run-linter
check_results $? run-linter
echo " Unit tests for this project"
run_checker runtests
check_results $? runtests
printf "%sDone%s\n\n" "${YELLOW}" "${NORMAL}"
}
# print out overall results
overall_results() {
printf "%sOveral result%s\n" "${YELLOW}" "${NORMAL}"
if [ $errors -eq 0 ]
then
printf " %sOK%s\n" "${GREEN}" "${NORMAL}"
else
if [ $errors -eq 1 ]
then
printf " %sOne%s %serror detected!%s\n" "${BLUE}" "${NORMAL}" "${RED}" "${NORMAL}"
else
printf " %s%s%s %serrors detected!%s\n" "${BLUE}" $errors "${NORMAL}" "${RED}" "${NORMAL}"
fi
fi
}
terminal_setup
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
pushd "${SCRIPT_DIR}/"
run_all_checkers
overall_results
popd
# 0 - ok
# >0 - some errors has been detected
exit $errors