Skip to content

Commit

Permalink
Merge pull request #371 from tisnik/one-script-to-check-everything
Browse files Browse the repository at this point in the history
One script to check everything
  • Loading branch information
tisnik authored Jul 17, 2019
2 parents b2af30c + 95c9524 commit 184e37e
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ html/
latex/

.DS_Store
*.err
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,60 @@ Note both jobs require [authentication](#authentication-authorization).

### Footnotes

#### Check for all possible issues

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:

```
./check-all.sh
```

Expected script output:

```
Running all tests and checkers
Check all BASH scripts
OK
Check documentation strings in all Python source file
OK
Detect common errors in all Python source file
OK
Detect dead code in all Python source file
OK
Run Python linter for Python source file
OK
Unit tests for this project
OK
Done
Overal result
OK
```

An example of script output when one error is detected:

```
Running all tests and checkers
Check all BASH scripts
Error: please look into files check-bashscripts.log and check-bashscripts.err for possible causes
Check documentation strings in all Python source file
OK
Detect common errors in all Python source file
OK
Detect dead code in all Python source file
OK
Run Python linter for Python source file
OK
Unit tests for this project
OK
Done
Overal result
One error detected!
```

Please note that the script creates bunch of `*.log` and `*.err` files that are temporary and won't be commited into the project repository.

#### Coding standards

- 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:
Expand Down
115 changes: 115 additions & 0 deletions check-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 runtest
check_results $? runtest

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

0 comments on commit 184e37e

Please sign in to comment.