diff --git a/runTests.sh b/runTests.sh index 31a941e..9c1d556 100755 --- a/runTests.sh +++ b/runTests.sh @@ -87,11 +87,21 @@ main() { callTestsInFile() { source $1 + finishedTestCount=0 + [[ ! $VERBOSE ]] && initDotLine + for currFunc in $(compgen -A function); do - if [[ $currFunc == "test_"* ]]; then - callTest $currFunc - elif [[ $RUN_LARGE_TESTS && $currFunc == "testLarge_"* ]]; then - callTest $currFunc + local output + ((finishedTestCount+=1)) + if [[ $currFunc == "test_"* || $RUN_LARGE_TESTS && $currFunc == "testLarge_"* ]]; then + [[ ! $VERBOSE ]] && updateDotLine + + output=$(callTest $currFunc 2>&1) + fi + + if [[ -n $output ]]; then + (( _PRINTED_LINE_COUNT+=$(echo -e "$output" | wc -l) )) + echo -e "$output" fi done @@ -101,6 +111,19 @@ callTestsInFile() { exit $FAILING_TEST_COUNT } +initDotLine() { + echo "" # start with a blank line to print the dots on + _PRINTED_LINE_COUNT=1 # Tracks how many lines have been printed since the dot-line, so we know where it is. +} + +updateDotLine() { + tput cuu $_PRINTED_LINE_COUNT # move the cursor up to the dot-line + echo -ne "\r" # go to the start of the line + printf "%0.s." $(seq 0 $finishedTestCount) # print as may dots as tests that have run + tput cud $_PRINTED_LINE_COUNT # move the cursor back down. + echo -ne "\r" # go to the start of the line again +} + # Helper functions callTest() { @@ -129,6 +152,15 @@ callIfExists() { fi } +failUnexpected() { + maxSizeForMultiline=30 + if [[ "${#1}" -gt $maxSizeForMultiline || ${#2} -gt $maxSizeForMultiline ]]; then + failFromStackDepth 3 "expected: '$1'\n got: '$2'" + else + failFromStackDepth 3 "expected: '$1', got: '$2'" + fi +} + # allows specifyng the call-stack depth at which the error was thrown failFromStackDepth() { printf "FAIL: $test_file(${BASH_LINENO[$1-1]}) > ${FUNCNAME[$1]}\n" @@ -186,12 +218,13 @@ EOF assertEquals() { if [[ "$2" != "$1" ]]; then - maxSizeForMultiline=30 - if [[ "${#1}" -gt $maxSizeForMultiline || ${#2} -gt $maxSizeForMultiline ]]; then - failFromStackDepth 2 "expected: '$1'\n got: '$2'" - else - failFromStackDepth 2 "expected: '$1', got: '$2'" - fi + failUnexpected "$1" "$2" + fi +} + +assertMatches() { + if [[ "$2" != $1 ]]; then + failUnexpected "$1" "$2" fi }