Skip to content

Commit a031987

Browse files
author
meonlol
committed
update to improved test-runner
1 parent 753b877 commit a031987

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

runTests.sh

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,21 @@ main() {
8787
callTestsInFile() {
8888
source $1
8989

90+
finishedTestCount=0
91+
[[ ! $VERBOSE ]] && initDotLine
92+
9093
for currFunc in $(compgen -A function); do
91-
if [[ $currFunc == "test_"* ]]; then
92-
callTest $currFunc
93-
elif [[ $RUN_LARGE_TESTS && $currFunc == "testLarge_"* ]]; then
94-
callTest $currFunc
94+
local output
95+
((finishedTestCount+=1))
96+
if [[ $currFunc == "test_"* || $RUN_LARGE_TESTS && $currFunc == "testLarge_"* ]]; then
97+
[[ ! $VERBOSE ]] && updateDotLine
98+
99+
output=$(callTest $currFunc 2>&1)
100+
fi
101+
102+
if [[ -n $output ]]; then
103+
(( _PRINTED_LINE_COUNT+=$(echo -e "$output" | wc -l) ))
104+
echo -e "$output"
95105
fi
96106
done
97107

@@ -101,6 +111,19 @@ callTestsInFile() {
101111
exit $FAILING_TEST_COUNT
102112
}
103113

114+
initDotLine() {
115+
echo "" # start with a blank line to print the dots on
116+
_PRINTED_LINE_COUNT=1 # Tracks how many lines have been printed since the dot-line, so we know where it is.
117+
}
118+
119+
updateDotLine() {
120+
tput cuu $_PRINTED_LINE_COUNT # move the cursor up to the dot-line
121+
echo -ne "\r" # go to the start of the line
122+
printf "%0.s." $(seq 0 $finishedTestCount) # print as may dots as tests that have run
123+
tput cud $_PRINTED_LINE_COUNT # move the cursor back down.
124+
echo -ne "\r" # go to the start of the line again
125+
}
126+
104127
# Helper functions
105128

106129
callTest() {
@@ -129,6 +152,15 @@ callIfExists() {
129152
fi
130153
}
131154

155+
failUnexpected() {
156+
maxSizeForMultiline=30
157+
if [[ "${#1}" -gt $maxSizeForMultiline || ${#2} -gt $maxSizeForMultiline ]]; then
158+
failFromStackDepth 3 "expected: '$1'\n got: '$2'"
159+
else
160+
failFromStackDepth 3 "expected: '$1', got: '$2'"
161+
fi
162+
}
163+
132164
# allows specifyng the call-stack depth at which the error was thrown
133165
failFromStackDepth() {
134166
printf "FAIL: $test_file(${BASH_LINENO[$1-1]}) > ${FUNCNAME[$1]}\n"
@@ -186,12 +218,13 @@ EOF
186218

187219
assertEquals() {
188220
if [[ "$2" != "$1" ]]; then
189-
maxSizeForMultiline=30
190-
if [[ "${#1}" -gt $maxSizeForMultiline || ${#2} -gt $maxSizeForMultiline ]]; then
191-
failFromStackDepth 2 "expected: '$1'\n got: '$2'"
192-
else
193-
failFromStackDepth 2 "expected: '$1', got: '$2'"
194-
fi
221+
failUnexpected "$1" "$2"
222+
fi
223+
}
224+
225+
assertMatches() {
226+
if [[ "$2" != $1 ]]; then
227+
failUnexpected "$1" "$2"
195228
fi
196229
}
197230

0 commit comments

Comments
 (0)