#!/bin/bash

function run {
  go test -a $@ |\
		GREP_COLORS='mt=01;32' egrep --line-buffered --color=always '^ok\ .*|$' |\
		GREP_COLORS='mt=00;38;5;226' egrep --line-buffered --color=always '^\?\ .*|$' |\
		GREP_COLORS='mt=01;31' egrep --line-buffered --color=always '.*FAIL.*|$'
}

# For piped commands return non-zero status if any command
# in the pipe returns a non-zero status
set -o pipefail
echo
echo "Running tests. Ignoring vendor folder."
run "$(go list ./... | grep -v -E 'vendor|cmd|contrib')"
# Exit if the previous command failed.
if [ $? != 0 ]; then
    exit 1
fi

echo
echo "Running tests in cmd directory."
run "$(go list ./... | grep -v -E 'vendor|contrib' | grep cmd) --args --debugmode"
