#!/bin/sh
# run - run tests
#
# Usage:
#   ./run zzsenha.sh zzcores.sh   # test zzsenha and zzcores
#   ./run                         # run all tests
#
# See README.md file for instructions.

script_dir=$(dirname "$0")
zz_root=$(cd "$script_dir"; cd ..; pwd)  # handles absolute and relative
tmp='./run.tmp'
tester='bash clitest'

cd "$script_dir"

# Check requirements
$tester -V > /dev/null || {
	printf '%s\n' "Ops... Não achei o programa testador: clitest"
	printf '%s\n' 'Baixe-o deste endereço:'
	printf '%s\n' 'https://raw.github.com/aureliojargas/clitest/master/clitest'
	exit 1
}

# Create temporary file with ZZ init in full paths
cat > "$tmp" <<EOF
. "$zz_root"/funcoeszz \\
	--cor 0 \\
	--path "$zz_root"/funcoeszz \\
	--dir  "$zz_root"/zz
EOF

# Note: To remove the dots ........ change 'dot' to 'none'
if test $# -gt 0
then
	# Test specific file(s)
	$tester --inline-prefix '#→ ' --progress dot --pre-flight ". $tmp" "$@"
	exitcode=$?
else
	# Test all files
	$tester --inline-prefix '#→ ' --progress dot --pre-flight ". $tmp" zz*.sh
	exitcode=$?
fi

rm "$tmp"
exit "$exitcode"
