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