Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/console_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ ${COLOR_FAINT}Total assertions:${COLOR_DEFAULT} ${COLOR_BOLD}${totalAssertions}$

if [ "$totalFailed" -gt 0 ]; then
printf "${COLOR_FAINT}Total assertions failed:${COLOR_DEFAULT} ${COLOR_BOLD}${COLOR_FAILED}${totalFailed}${COLOR_DEFAULT}\n"
_TIME_TERMINATION=$((($(date +%s%N) - $_TIME_START)/1000000))
printf "${COLOR_BOLD}%s${COLOR_DEFAULT}\n" "Time taken: ${_TIME_TERMINATION} ms"
exit 1
else
printf "${COLOR_ALL_PASSED}All assertions passed.${COLOR_DEFAULT}\n"
fi

_TIME_TERMINATION=$((($(date +%s%N) - $_TIME_START)/1000000))
printf "${COLOR_BOLD}%s${COLOR_DEFAULT}\n" "Time taken: ${_TIME_TERMINATION} ms"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tito-Kati ☝ we should refactor all to be like this, is easy to read, and not just that, the static analysis tool likes it better

exit 0
}

# Set a trap to call renderResult when the script exits
Expand Down
1 change: 1 addition & 0 deletions src/test_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ _TOTAL_TESTS=0
# shellcheck disable=SC2155
# shellcheck disable=SC2034
callTestFunctions() {
_TIME_START=$(date +%s%N);
local script="$1"
local filter="$2"
local prefix="test"
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/render_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,23 @@ function test_render_result_not_all_assertions_passed() {
"All assertions passed"\
"$(renderResult $total_tests $assertions_passed $assertions_failed)"
}

function test_render_time_of_execution_when_all_assertions_passed() {
local total_tests=2
local assertions_passed=5
local assertions_failed=1

assertMatches\
".*Time taken: [[:digit:]]+ ms"\
"$(renderResult $total_tests $assertions_passed $assertions_failed)"
}

function test_render_time_of_execution_when_not_all_assertions_passed() {
local total_tests=2
local assertions_passed=5
local assertions_failed=1

assertMatches\
".*Time taken: [[:digit:]]+ ms"\
"$(renderResult $total_tests $assertions_passed $assertions_failed)"
}