diff --git a/script/test b/script/test index 268e3ad..9dd6cd2 100755 --- a/script/test +++ b/script/test @@ -34,43 +34,68 @@ function inc_color { } function colorpipe { - local line - global_color=$((global_color + 1)) - if ((global_color > 6)); then - global_color=1 - fi + local c=$1 line while read -r line; do - tput setaf "$global_color" - printf "%s" "$line" + tput setaf "$c" + printf "\t%s" "$line" tput sgr0 echo done } +failures=0 + +function runc { + tput setaf 8 + tput bold + printf "Running:" + printf " %q" "$@" + printf "\n" + tput sgr0 + + global_color=$((global_color + 1)) + if ((global_color > 7)); then + global_color=2 + fi + + "$@" | colorpipe "$global_color" || failures=$((failures + 1)) +} + header "Running tests..." -colorpipe < <(go test ./... -v) +runc go test ./... -v +header "Running examples..." for example in examples/*; do if [ ! -d "$example" ]; then continue fi - header "Running example $example" - # compgen -G is a badly documented trick to resolve wildcards into a # single file or an empty string. template=$(compgen -G "${example}"/*.template || :) json=$(compgen -G "${example}/*.json" || :) - if [ -r "${json}" ]; then - colorpipe < <( - env RUNNING_WITH=json TODAY_IS="$(date)" go run ./*.go --json-data "$json" "$template" - ) + yaml=$(compgen -G "${example}/*.yaml" || :) + TODAY_IS=$(date '+%x') + + if [ -r "${json}" ] || [ -r "${yaml}" ]; then + if [ -r "${json}" ]; then + runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=json-data go run ./... --data "$json" "$template" + fi + if [ -r "${yaml}" ]; then + runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=yaml-data go run ./... --data "$yaml" "$template" + fi else - colorpipe < <( - env RUNNING_WITH=env TODAY_IS="$(date)" go run ./*.go "$template" - ) + runc env "TODAY_IS=$TODAY_IS" RUNNING_WITH=env go run ./... "$template" fi done +if ((failures > 0)); then + tput setaf 1 # red + tput bold + printf "FAILURES: %d\n" "$failures" + tput sgr0 + exit 1 +fi + # vim: set ft=sh :