#! /usr/bin/env bash # run script/test -h for help # COLORS OFF='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' set -e function usage() { echo -e "\t ================== script/test usage ==================" echo -e "\t-h --help : displays help message" echo -e "\t-k --no-linter : disables linting tests" echo -e "\n\t Suggested flags for development: script/test" } while [ "$1" != "" ]; do PARAM=`echo $1 | awk -F= '{print $1}'` VALUE=`echo $1 | awk -F= '{print $2}'` case $PARAM in -h | --help) usage exit ;; -k | --no-linter) no_linter=1 ;; *) echo "ERROR: unknown parameter \"$PARAM\"" usage exit 1 ;; esac shift done # setup export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" [ -z "$RBENV_VERSION" ] && export RBENV_VERSION=$(cat "$DIR/.ruby-version") # Run Rubocop if [[ -z $no_linter ]]; then echo -e "\n๐Ÿค– ${BLUE}Running Rubocop: $(date "+%H:%M:%S")${OFF}\n" bundle exec bin/rubocop else echo -e "\nโฉ ${BLUE}Skipping Rubocop${OFF}" fi # run tests echo -e "\n๐Ÿงช ${BLUE}Running tests: $(date "+%H:%M:%S")${OFF}\n" cd "$(dirname $0)/.." bundle exec bin/rspec spec && rspec_exit=$? || rspec_exit=$? total_coverage=$(cat "$DIR/coverage/total-coverage.txt") if grep -q "100.0" "$DIR/coverage/total-coverage.txt"; then cov_exit=0 echo -e "\nโœ… Total Coverage: ${GREEN}$total_coverage${OFF}" else cov_exit=1 echo -e "\nโŒ Total Coverage: ${RED}$total_coverage${OFF}" fi echo "" echo "---------------------------------------" echo "๐Ÿ“Š Summary Results" echo "---------------------------------------" echo "" if [[ $rspec_exit == 0 ]]; then echo -e "โœ… ${GREEN}rspec: exitcode=${rspec_exit}${OFF}" else echo -e "โŒ ${RED}rspec: exitcode=${rspec_exit}${OFF}" fi if [[ $cov_exit == 0 ]]; then echo -e "โœ… \033[0;32mcoverage: exitcode=${cov_exit}\033[0m" else echo -e "โŒ \033[0;31mcoverage: exitcode=${cov_exit}\033[0m" fi [ $rspec_exit -gt 0 ] && exit 1 [ $cov_exit -gt 0 ] && exit 1 exit 0