Skip to content

Commit 184e37e

Browse files
authored
Merge pull request #371 from tisnik/one-script-to-check-everything
One script to check everything
2 parents b2af30c + 95c9524 commit 184e37e

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ html/
8686
latex/
8787

8888
.DS_Store
89+
*.err

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,60 @@ Note both jobs require [authentication](#authentication-authorization).
491491

492492
### Footnotes
493493

494+
#### Check for all possible issues
495+
496+
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:
497+
498+
```
499+
./check-all.sh
500+
```
501+
502+
Expected script output:
503+
504+
```
505+
Running all tests and checkers
506+
Check all BASH scripts
507+
OK
508+
Check documentation strings in all Python source file
509+
OK
510+
Detect common errors in all Python source file
511+
OK
512+
Detect dead code in all Python source file
513+
OK
514+
Run Python linter for Python source file
515+
OK
516+
Unit tests for this project
517+
OK
518+
Done
519+
520+
Overal result
521+
OK
522+
```
523+
524+
An example of script output when one error is detected:
525+
526+
```
527+
Running all tests and checkers
528+
Check all BASH scripts
529+
Error: please look into files check-bashscripts.log and check-bashscripts.err for possible causes
530+
Check documentation strings in all Python source file
531+
OK
532+
Detect common errors in all Python source file
533+
OK
534+
Detect dead code in all Python source file
535+
OK
536+
Run Python linter for Python source file
537+
OK
538+
Unit tests for this project
539+
OK
540+
Done
541+
542+
Overal result
543+
One error detected!
544+
```
545+
546+
Please note that the script creates bunch of `*.log` and `*.err` files that are temporary and won't be commited into the project repository.
547+
494548
#### Coding standards
495549

496550
- 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)