Skip to content

Commit dd7bff8

Browse files
authored
Merge pull request #309 from tisnik/one-script-to-check-everything
One script to check everything
2 parents 9e7e5dc + e98dede commit dd7bff8

3 files changed

Lines changed: 170 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ coverage.xml
2929
*config.py
3030

3131
.DS_Store
32+
*.err

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,60 @@ oc process -f data-model-importer-openshift-template.yaml -v AWS_BUCKET=<value>
552552

553553
### Footnotes
554554

555+
#### Check for all possible issues
556+
557+
The script named `check-all.sh` is to be used to check the sources for all detectable errors and issues. This script can be run w/o any arguments:
558+
559+
```
560+
./check-all.sh
561+
```
562+
563+
Expected script output:
564+
565+
```
566+
Running all tests and checkers
567+
Check all BASH scripts
568+
OK
569+
Check documentation strings in all Python source file
570+
OK
571+
Detect common errors in all Python source file
572+
OK
573+
Detect dead code in all Python source file
574+
OK
575+
Run Python linter for Python source file
576+
OK
577+
Unit tests for this project
578+
OK
579+
Done
580+
581+
Overal result
582+
OK
583+
```
584+
585+
An example of script output when one error is detected:
586+
587+
```
588+
Running all tests and checkers
589+
Check all BASH scripts
590+
Error: please look into files check-bashscripts.log and check-bashscripts.err for possible causes
591+
Check documentation strings in all Python source file
592+
OK
593+
Detect common errors in all Python source file
594+
OK
595+
Detect dead code in all Python source file
596+
OK
597+
Run Python linter for Python source file
598+
OK
599+
Unit tests for this project
600+
OK
601+
Done
602+
603+
Overal result
604+
One error detected!
605+
```
606+
607+
Please note that the script creates bunch of `*.log` and `*.err` files that are temporary and won't be commited into the project repository.
608+
555609
#### Coding standards
556610

557611
- Local setup instructions and files can be found at `local-setup` directory, in case anyone wants local DynamoDB support. Note that, the container images used in the backup directory are not the same that are used to host the project in OpenShift. This directory should be removed once the local development support for DynamoDB makes its way in the current master branch.

check-all.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/bash
2+
3+
# Script to check the sources for all detectable errors and issues
4+
5+
6+
# error counter
7+
errors=0
8+
9+
10+
11+
# check the terminal and set up the colors for terminal
12+
terminal_setup() {
13+
# try to detect the terminal
14+
TERM=${TERM:-xterm}
15+
16+
# set up terminal colors
17+
NORMAL=$(tput sgr0)
18+
RED=$(tput bold && tput setaf 1)
19+
GREEN=$(tput bold && tput setaf 2)
20+
YELLOW=$(tput bold && tput setaf 3)
21+
BLUE=$(tput bold && tput setaf 4)
22+
}
23+
24+
25+
26+
# run selected checker or test script
27+
run_checker() {
28+
local cmd="$1.sh"
29+
local log="$1.log"
30+
local err="$1.err"
31+
# run the checker, redirect all logs and errors
32+
"./${cmd}" > "${log}" 2> "${err}"
33+
return $?
34+
}
35+
36+
37+
38+
# check results
39+
check_results() {
40+
if [ "$1" -eq 0 ]
41+
then
42+
printf " %sOK%s\n" "${GREEN}" "${NORMAL}"
43+
else
44+
printf " %sError%s: " "${RED}" "${NORMAL}"
45+
printf "please look into files %s%s.log%s and %s%s.err%s for possible causes\n" "${BLUE}" "$2" "${NORMAL}" "${BLUE}" "$2" "${NORMAL}"
46+
errors=$((errors+1))
47+
fi
48+
}
49+
50+
51+
52+
# run all checkers
53+
run_all_checkers() {
54+
printf "%sRunning all tests and checkers%s\n" "${YELLOW}" "${NORMAL}"
55+
56+
echo " Check all BASH scripts"
57+
run_checker check-bashscripts
58+
check_results $? check-bashscripts
59+
60+
echo " Check documentation strings in all Python source file"
61+
run_checker check-docstyle
62+
check_results $? check-docstyle
63+
64+
echo " Detect common errors in all Python source file"
65+
run_checker detect-common-errors
66+
check_results $? detect-common-errors
67+
68+
echo " Detect dead code in all Python source file"
69+
run_checker detect-dead-code
70+
check_results $? detect-dead-code
71+
72+
echo " Run Python linter for Python source file"
73+
run_checker run-linter
74+
check_results $? run-linter
75+
76+
echo " Unit tests for this project"
77+
run_checker runtests
78+
check_results $? runtests
79+
80+
printf "%sDone%s\n\n" "${YELLOW}" "${NORMAL}"
81+
}
82+
83+
84+
85+
# print out overall results
86+
overall_results() {
87+
printf "%sOveral result%s\n" "${YELLOW}" "${NORMAL}"
88+
89+
if [ $errors -eq 0 ]
90+
then
91+
printf " %sOK%s\n" "${GREEN}" "${NORMAL}"
92+
else
93+
if [ $errors -eq 1 ]
94+
then
95+
printf " %sOne%s %serror detected!%s\n" "${BLUE}" "${NORMAL}" "${RED}" "${NORMAL}"
96+
else
97+
printf " %s%s%s %serrors detected!%s\n" "${BLUE}" $errors "${NORMAL}" "${RED}" "${NORMAL}"
98+
fi
99+
fi
100+
}
101+
102+
103+
104+
terminal_setup
105+
106+
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
107+
108+
pushd "${SCRIPT_DIR}/"
109+
run_all_checkers
110+
overall_results
111+
popd
112+
113+
# 0 - ok
114+
# >0 - some errors has been detected
115+
exit $errors

0 commit comments

Comments
 (0)