Skip to content

Commit 1e40407

Browse files
authored
Merge pull request #67 from tisnik/one-script-to-check-everything
One script to check everything
2 parents 5ca9ec8 + c6bd79e commit 1e40407

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ venv.bak/
3838
.idea
3939

4040
.DS_Store
41+
*.log
42+
*.err

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,60 @@ This repository contains the code for the model that serves the companion recomm
44

55
## Footnotes:
66

7+
#### Check for all possible issues
8+
9+
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:
10+
11+
```
12+
./check-all.sh
13+
```
14+
15+
Expected script output:
16+
17+
```
18+
Running all tests and checkers
19+
Check all BASH scripts
20+
OK
21+
Check documentation strings in all Python source file
22+
OK
23+
Detect common errors in all Python source file
24+
OK
25+
Detect dead code in all Python source file
26+
OK
27+
Run Python linter for Python source file
28+
OK
29+
Unit tests for this project
30+
OK
31+
Done
32+
33+
Overal result
34+
OK
35+
```
36+
37+
An example of script output when one error is detected:
38+
39+
```
40+
Running all tests and checkers
41+
Check all BASH scripts
42+
Error: please look into files check-bashscripts.log and check-bashscripts.err for possible causes
43+
Check documentation strings in all Python source file
44+
OK
45+
Detect common errors in all Python source file
46+
OK
47+
Detect dead code in all Python source file
48+
OK
49+
Run Python linter for Python source file
50+
OK
51+
Unit tests for this project
52+
OK
53+
Done
54+
55+
Overal result
56+
One error detected!
57+
```
58+
59+
Please note that the script creates bunch of `*.log` and `*.err` files that are temporary and won't be commited into the project repository.
60+
761
#### Coding standards:
862

963
- You can use scripts `run-linter.sh` and `check-docstyle.sh` to check if the code follows [PEP 8](https://www.python.org/dev/peps/pep-0008/) and [PEP 257](https://www.python.org/dev/peps/pep-0257/) coding standards. These scripts can be run w/o any arguments:

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 runtest
78+
check_results $? runtest
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)