Skip to content

Commit

Permalink
update to improved test-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
meonlol committed Jan 6, 2018
1 parent 753b877 commit a031987
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a031987

Please sign in to comment.