diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index e34734d8..57b5efa5 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -59,7 +59,11 @@ Installation: https://github.com/koalaman/shellcheck#installing
#### Example of usage
```bash
-shellcheck ./**/**/**.sh -C
+# using make
+make lint
+
+# using shellcheck itself
+shellcheck ./**/*.sh -C
```
#### We recommend
diff --git a/Makefile b/Makefile
index b52d794b..44ef0e47 100644
--- a/Makefile
+++ b/Makefile
@@ -40,8 +40,9 @@ help:
@echo " test/list List all the test under the tests directory"
@echo " test/watch Automatically run the test every second"
@echo " env/example Makes a copy of the keys on your .env file"
- @echo " pre_commit/install installs the pre-commit hook"
- @echo " pre_commit/run function that will be called when the pre-commit runs"
+ @echo " pre_commit/install Installs the pre-commit hook"
+ @echo " pre_commit/run Function that will be called when the pre-commit runs"
+ @echo " lint Run shellcheck"
SRC_SCRIPTS_DIR=src
TEST_SCRIPTS_DIR=tests
@@ -68,3 +69,6 @@ pre_commit/install:
cp $(PRE_COMMIT_SCRIPTS_FILE) ./.git/hooks/
pre_commit/run: test env/example
+
+lint:
+ shellcheck ./**/*.sh -C && echo "Shellcheck: OK!"
\ No newline at end of file
diff --git a/bashunit b/bashunit
index fd9d46d3..45f69d4d 100755
--- a/bashunit
+++ b/bashunit
@@ -5,8 +5,8 @@ readonly BASH_UNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
source "$BASH_UNIT_ROOT_DIR/src/env_configuration.sh"
source "$BASH_UNIT_ROOT_DIR/src/check_os.sh"
source "$BASH_UNIT_ROOT_DIR/src/colors.sh"
-source "$BASH_UNIT_ROOT_DIR/src/assert.sh"
source "$BASH_UNIT_ROOT_DIR/src/console_results.sh"
+source "$BASH_UNIT_ROOT_DIR/src/assert.sh"
source "$BASH_UNIT_ROOT_DIR/src/test_runner.sh" "$@"
diff --git a/example/README.md b/example/README.md
index 27a54208..30f9f429 100644
--- a/example/README.md
+++ b/example/README.md
@@ -7,22 +7,17 @@ An example using this **bashunit** testing library.
This demo uses **bashunit** itself as [git-submodule](https://git-scm.com/book/de/v2/Git-Tools-Submodule) inside the `tools/bashunit` directory.
1) Install the git submodule
-
-```bash
-git submodule update --init --recursive
-```
-
+ ```bash
+ git submodule update --init --recursive
+ ```
2) Update to the latest version
-
-```bash
-git submodule update --remote
-```
-
+ ```bash
+ git submodule update --remote
+ ```
3) Run the tests
-
-```bash
-tools/bashunit/bashunit logic_test.sh
-```
+ ```bash
+ tools/bashunit/bashunit logic_test.sh
+ ```
diff --git a/src/assert.sh b/src/assert.sh
index 6cfba3bf..53fc5bca 100755
--- a/src/assert.sh
+++ b/src/assert.sh
@@ -1,22 +1,11 @@
#!/bin/bash
-export TEST=true
-
-export assertEquals
-export assertContains
-export assertNotContains
-export assertMatches
-export assertNotMatches
-
-_TOTAL_ASSERTIONS_FAILED=0
-_TOTAL_ASSERTIONS_PASSED=0
-
-normalizeFnName() {
- local originalFnName="$1"
+function normalizeFunctionName() {
+ local original_function_name="$1"
local result
# Remove "test_" prefix
- result="${originalFnName#test_}"
+ result="${original_function_name#test_}"
# Replace underscores with spaces
result="${result//_/ }"
# Remove "test" prefix
@@ -27,83 +16,83 @@ normalizeFnName() {
echo "$result"
}
-assertEquals() {
+function assertEquals() {
local expected="$1"
local actual="$2"
- local label="${3:-$(normalizeFnName "${FUNCNAME[1]}")}"
+ local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
if [[ "$expected" != "$actual" ]]; then
- ((_TOTAL_ASSERTIONS_FAILED++))
+ ((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "${expected}" "but got" "${actual}"
- exit 1
+ return 1
else
- ((_TOTAL_ASSERTIONS_PASSED++))
- printf "${COLOR_PASSED}%s${COLOR_DEFAULT}: ${label}\n" "✓ Passed"
+ ((_ASSERTIONS_PASSED++))
+ return 0
fi
}
-assertContains() {
+function assertContains() {
local expected="$1"
local actual="$2"
- local label="${3:-$(normalizeFnName "${FUNCNAME[1]}")}"
+ local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
case "$actual" in
*"$expected"*)
- ((_TOTAL_ASSERTIONS_PASSED++))
- printSuccessfulTest "${label}"
+ ((_ASSERTIONS_PASSED++))
+ return 0
;;
*)
- ((_TOTAL_ASSERTIONS_FAILED++))
+ ((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "${actual}" "to contain" "${expected}"
- exit 1
+ return 1
;;
esac
}
-assertNotContains() {
+function assertNotContains() {
local expected="$1"
- local actual="$2"
- local label="${3:-$(normalizeFnName "${FUNCNAME[1]}")}"
+ local actual="$2"
+ local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
- case "$actual" in
- *"$expected"*)
- ((_TOTAL_ASSERTIONS_FAILED++))
- printFailedTest "${label}" "${actual}" "to not contain" "${expected}"
- exit 1
- ;;
- *)
- ((_TOTAL_ASSERTIONS_PASSED++))
- printSuccessfulTest "${label}"
- ;;
- esac
+ case "$actual" in
+ *"$expected"*)
+ ((_ASSERTIONS_FAILED++))
+ printFailedTest "${label}" "${actual}" "to not contain" "${expected}"
+ return 1
+ ;;
+ *)
+ ((_ASSERTIONS_PASSED++))
+ return 0
+ ;;
+ esac
}
-assertMatches() {
+function assertMatches() {
local expected="$1"
local actual="$2"
- local label="${3:-$(normalizeFnName "${FUNCNAME[1]}")}"
+ local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
if [[ $actual =~ $expected ]]; then
- ((_TOTAL_ASSERTIONS_PASSED++))
- printSuccessfulTest "${label}"
+ ((_ASSERTIONS_PASSED++))
+ return 0
else
- ((_TOTAL_ASSERTIONS_FAILED++))
+ ((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "${actual}" "to match" "${expected}"
- exit 1
+ return 1
fi
}
-assertNotMatches() {
+function assertNotMatches() {
local expected="$1"
local actual="$2"
- local label="${3:-$(normalizeFnName "${FUNCNAME[1]}")}"
+ local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
if [[ $actual =~ $expected ]]; then
- ((_TOTAL_ASSERTIONS_FAILED++))
+ ((_ASSERTIONS_FAILED++))
printFailedTest "${label}" "${actual}" "to not match" "${expected}"
- exit 1
+ return 1
else
- ((_TOTAL_ASSERTIONS_PASSED++))
- printSuccessfulTest "${label}"
+ ((_ASSERTIONS_PASSED++))
+ return 0
fi
}
diff --git a/src/check_os.sh b/src/check_os.sh
index c4b54b57..ed540939 100644
--- a/src/check_os.sh
+++ b/src/check_os.sh
@@ -1,11 +1,12 @@
#!/bin/bash
-export OS="Unknown"
+# shellcheck disable=SC2034
+_OS="Unknown"
if [ "$(uname)" == "Linux" ]; then
- OS="Linux"
+ _OS="Linux"
elif [ "$(uname)" == "Darwin" ]; then
- OS="OSX"
+ _OS="OSX"
elif [[ $(uname) == *"MINGW"* ]]; then
- OS="Windows"
+ _OS="Windows"
fi
diff --git a/src/colors.sh b/src/colors.sh
index d39d9c09..92d1ec41 100644
--- a/src/colors.sh
+++ b/src/colors.sh
@@ -1,8 +1,9 @@
#!/bin/bash
-export COLOR_DEFAULT="\e[0m"
-export COLOR_BOLD="\e[1m"
-export COLOR_FAINT="\e[2m"
-export COLOR_FAILED="\e[31m"
-export COLOR_PASSED="\e[32m"
-export COLOR_ALL_PASSED="\e[42m"
+# shellcheck disable=SC2034
+_COLOR_DEFAULT=$'\e[0m'
+_COLOR_BOLD=$'\e[1m'
+_COLOR_FAINT=$'\e[2m'
+_COLOR_FAILED=$'\e[31m'
+_COLOR_PASSED=$'\e[32m'
+_COLOR_ALL_PASSED=$'\e[42m'
diff --git a/src/console_results.sh b/src/console_results.sh
index 7bddff41..e91c9071 100644
--- a/src/console_results.sh
+++ b/src/console_results.sh
@@ -1,56 +1,75 @@
#!/bin/bash
-export renderResult
-export printSuccessfulTest
+_START_TIME=$(date +%s%N);
+_TESTS_PASSED=0
+_TESTS_FAILED=0
+_ASSERTIONS_PASSED=0
+_ASSERTIONS_FAILED=0
function renderResult() {
- local totalTests=$1
- local totalPassed=$2
- local totalFailed=$3
+ local tests_passed=$1
+ local tests_failed=$2
+ local assertions_passed=$3
+ local assertions_failed=$4
echo ""
- local totalAssertions=$((totalPassed + totalFailed))
- printf "\
-${COLOR_FAINT}%s${COLOR_DEFAULT} ${COLOR_BOLD}${totalTests}${COLOR_DEFAULT}
-${COLOR_FAINT}%s${COLOR_DEFAULT} ${COLOR_BOLD}${totalAssertions}${COLOR_DEFAULT}\n" \
- "Total tests:" "Total assertions:"
-
- if [ "$totalFailed" -gt 0 ]; then
- printf "${COLOR_FAINT}%s${COLOR_DEFAULT} ${COLOR_BOLD}${COLOR_FAILED}${totalFailed}${COLOR_DEFAULT}\n"\
- "Total assertions failed:"
- printExecTime
+ local total_tests=$((tests_passed + tests_failed))
+ local total_assertions=$((assertions_passed + assertions_failed))
+
+ printf "%sTests: %s" "$_COLOR_FAINT" "$_COLOR_DEFAULT"
+ if [[ $tests_passed -gt 0 ]] || [[ $assertions_passed -gt 0 ]]; then
+ printf " %s%s passed%s," "$_COLOR_PASSED" "$tests_passed" "$_COLOR_DEFAULT"
+ fi
+ if [[ $tests_failed -gt 0 ]]; then
+ printf " %s%s failed%s," "$_COLOR_FAILED" "$tests_failed" "$_COLOR_DEFAULT"
+ fi
+ printf " %s total\n" "$total_tests"
+
+
+ printf "%sAssertions:%s" "$_COLOR_FAINT" "$_COLOR_DEFAULT"
+ if [[ $tests_passed -gt 0 ]] || [[ $assertions_passed -gt 0 ]]; then
+ printf " %s%s passed%s," "$_COLOR_PASSED" "$assertions_passed" "$_COLOR_DEFAULT"
+ fi
+ if [[ $tests_failed -gt 0 ]]; then
+ printf " %s%s failed%s," "$_COLOR_FAILED" "$assertions_failed" "$_COLOR_DEFAULT"
+ fi
+ printf " %s total\n" "$total_assertions"
+
+ if [[ "$tests_failed" -gt 0 ]]; then
+ printExecutionTime
exit 1
- else
- printf "${COLOR_ALL_PASSED}%s${COLOR_DEFAULT}\n" "All assertions passed."
fi
- printExecTime
+ printf "%s%s%s\n" "$_COLOR_ALL_PASSED" "All tests passed" "$_COLOR_DEFAULT"
+ printExecutionTime
+ exit 0
}
-function printExecTime() {
- if [[ $OS != "OSX" ]]; then
- _TIME_TERMINATION=$((($(date +%s%N) - "$_TIME_START") / 1000000))
- printf "${COLOR_BOLD}%s${COLOR_DEFAULT}\n" "Time taken: ${_TIME_TERMINATION} ms"
+function printExecutionTime() {
+ if [ "$_OS" != "OSX" ]; then
+ _EXECUTION_TIME=$((($(date +%s%N) - "$_START_TIME") / 1000000))
+ printf "${_COLOR_BOLD}%s${_COLOR_DEFAULT}\n" "Time taken: ${_EXECUTION_TIME} ms"
fi
}
function printSuccessfulTest() {
- testName=$1
- printf "${COLOR_PASSED}✓ Passed${COLOR_DEFAULT}: %s\n" "${testName}"
+ local test_name=$1
+ printf "%s✓ Passed%s: %s\n" "$_COLOR_PASSED" "$_COLOR_DEFAULT" "${test_name}"
}
function printFailedTest() {
- testName=$1
- expected=$2
- failureConditionMessage=$3
- actual=$4
+ local test_name=$1
+ local expected=$2
+ local failure_condition_message=$3
+ local actual=$4
+
printf "\
-${COLOR_FAILED}✗ Failed${COLOR_DEFAULT}: %s
- ${COLOR_FAINT}Expected${COLOR_DEFAULT} ${COLOR_BOLD}'%s'${COLOR_DEFAULT}
- ${COLOR_FAINT}%s${COLOR_DEFAULT} ${COLOR_BOLD}'%s'${COLOR_DEFAULT}\n"\
- "${testName}" "${expected}" "${failureConditionMessage}" "${actual}"
+${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s
+ ${_COLOR_FAINT}Expected${_COLOR_DEFAULT} ${_COLOR_BOLD}'%s'${_COLOR_DEFAULT}
+ ${_COLOR_FAINT}%s${_COLOR_DEFAULT} ${_COLOR_BOLD}'%s'${_COLOR_DEFAULT}\n"\
+ "${test_name}" "${expected}" "${failure_condition_message}" "${actual}"
}
# Set a trap to call renderResult when the script exits
-trap 'renderResult $_TOTAL_TESTS $_TOTAL_ASSERTIONS_PASSED $_TOTAL_ASSERTIONS_FAILED' EXIT
+trap 'renderResult $_TESTS_PASSED $_TESTS_FAILED $_ASSERTIONS_PASSED $_ASSERTIONS_FAILED' EXIT
diff --git a/src/env_configuration.sh b/src/env_configuration.sh
index e9c9a601..426e44bc 100644
--- a/src/env_configuration.sh
+++ b/src/env_configuration.sh
@@ -1,9 +1,10 @@
#!/bin/bash
set -o allexport
+# shellcheck source=/dev/null
source .env set
set +o allexport
-if [[ -z "$PARALLEL_RUN" ]]; then
- PARALLEL_RUN=true
+if [ -z "$PARALLEL_RUN" ]; then
+ PARALLEL_RUN=false
fi
diff --git a/src/test_runner.sh b/src/test_runner.sh
index 60020fc3..a0faf0a9 100755
--- a/src/test_runner.sh
+++ b/src/test_runner.sh
@@ -1,80 +1,88 @@
#!/bin/bash
-export _TOTAL_TESTS
-
-_TOTAL_TESTS=0
-
-# shellcheck disable=SC2155
-# shellcheck disable=SC2034
-callTestFunctions() {
- _TIME_START=$(date +%s%N);
+function callTestFunctions() {
local script="$1"
local filter="$2"
local prefix="test"
# Use declare -F to list all function names
- local function_names=$(declare -F | awk '{print $3}')
+ local function_names
+ function_names=$(declare -F | awk '{print $3}')
local functions_to_run=()
- for func_name in $function_names; do
- if [[ $func_name == ${prefix}* ]]; then
- local func_name_lower=$(echo "$func_name" | tr '[:upper:]' '[:lower:]')
- local filter_lower=$(echo "$filter" | tr '[:upper:]' '[:lower:]')
+ for function_name in $function_names; do
+ if [[ $function_name == ${prefix}* ]]; then
+ local lower_case_function_name
+ lower_case_function_name=$(echo "$function_name" | tr '[:upper:]' '[:lower:]')
+ local lower_case_filter
+ lower_case_filter=$(echo "$filter" | tr '[:upper:]' '[:lower:]')
- if [[ -z $filter || $func_name_lower == *"$filter_lower"* ]]; then
- functions_to_run+=("$func_name")
+ if [[ -z $filter || $lower_case_function_name == *"$lower_case_filter"* ]]; then
+ functions_to_run+=("$function_name")
fi
fi
done
if [ "${#functions_to_run[@]}" -gt 0 ]; then
echo "Running $script"
- for func_name in "${functions_to_run[@]}"; do
- ((_TOTAL_TESTS++))
+ for function_name in "${functions_to_run[@]}"; do
if [ "$PARALLEL_RUN" = true ] ; then
- "$func_name" &
+ runTest "$function_name" &
else
- "$func_name"
+ runTest "$function_name"
fi
- unset "$func_name"
+ unset "$function_name"
done
fi
}
+function runTest() {
+ local function_name="$1"
+
+ "$function_name"
+ local exit_code=$?
+
+ if [ $exit_code -eq 0 ]; then
+ ((_TESTS_PASSED++))
+ local label="${3:-$(normalizeFunctionName "$function_name")}"
+ printSuccessfulTest "${label}"
+ else
+ ((_TESTS_FAILED++))
+ fi
+}
+
###############
#### MAIN #####
###############
-FILES=()
-FILTER=""
+_FILES=()
+_FILTER=""
-# Parse command line arguments
-while [[ $# -gt 0 ]]; do
- key="$1"
- case $key in
+while [ $# -gt 0 ]; do
+ argument="$1"
+ case $argument in
--filter)
- FILTER="$2"
+ _FILTER="$2"
shift
shift
;;
*)
- FILES+=("$key") # Add the argument to the list of files
+ _FILES+=("$argument")
shift
;;
esac
done
-if [ ${#FILES[@]} -eq 0 ]; then
+if [ ${#_FILES[@]} -eq 0 ]; then
echo "Error: At least one file path is required."
- echo "Usage: $0 "
+ echo "Usage: $0 "
exit 1
fi
-# Print the "Running $script" message before entering the loop
-for test_script in "${FILES[@]}"; do
+for test_file in "${_FILES[@]}"; do
# shellcheck disable=SC1090
- source "$test_script"
- callTestFunctions "$test_script" "$FILTER"
+ source "$test_file"
+ callTestFunctions "$test_file" "$_FILTER"
if [ "$PARALLEL_RUN" = true ] ; then
- wait # Wait to finish the run of all the test from the same file
+ wait
fi
done
diff --git a/tests/unit/assert_test.sh b/tests/unit/assert_test.sh
index 7bb713da..a371cc01 100644
--- a/tests/unit/assert_test.sh
+++ b/tests/unit/assert_test.sh
@@ -1,8 +1,7 @@
#!/bin/bash
function test_successful_assertEquals() {
- assertEquals "$(printSuccessfulTest "Successful assertEquals")"\
- "$(assertEquals "1" "1")"
+ assertEquals "" "$(assertEquals "1" "1")"
}
function test_unsuccessful_assertEquals() {
@@ -10,20 +9,8 @@ function test_unsuccessful_assertEquals() {
"$(assertEquals "1" "2")"
}
-function testCamelCase() {
- assertEquals "$(printSuccessfulTest "CamelCase")" "$(assertEquals "1" "1")"
-}
-
-function test_multiple_asserts() {
- assertEquals "1" "1" "1 equals 1"
- assertEquals "2" "2" "2 equals 2"
- assertEquals "3" "3" "3 equals 3"
- assertEquals "4" "4" "4 equals 4"
-}
-
function test_successful_assertContains() {
- assertEquals "$(printSuccessfulTest "Successful assertContains")"\
- "$(assertContains "Linux" "GNU/Linux")"
+ assertEquals "" "$(assertContains "Linux" "GNU/Linux")"
}
function test_unsuccessful_assertContains() {
@@ -32,8 +19,7 @@ function test_unsuccessful_assertContains() {
}
function test_successful_assertNotContains() {
- assertEquals "$(printSuccessfulTest "Successful assertNotContains")"\
- "$(assertNotContains "Linus" "GNU/Linux")"
+ assertEquals "" "$(assertNotContains "Linus" "GNU/Linux")"
}
function test_unsuccessful_assertNotContains() {
@@ -42,8 +28,7 @@ function test_unsuccessful_assertNotContains() {
}
function test_successful_assertMatches() {
- assertEquals "$(printSuccessfulTest "Successful assertMatches")"\
- "$(assertMatches ".*Linu*" "GNU/Linux")"
+ assertEquals "" "$(assertMatches ".*Linu*" "GNU/Linux")"
}
function test_unsuccessful_assertMatches() {
@@ -52,11 +37,11 @@ function test_unsuccessful_assertMatches() {
}
function test_successful_assertNotMatches() {
- assertEquals "$(printSuccessfulTest "Successful assertNotMatches")" \
- "$(assertNotMatches ".*Pinux*" "GNU/Linux")"
+ assertEquals "" "$(assertNotMatches ".*Pinux*" "GNU/Linux")"
}
function test_unsuccessful_assertNotMatches() {
- assertEquals "$(printFailedTest "Unsuccessful assertNotMatches" "GNU/Linux" "to not match" ".*Linu*")"\
- "$(assertNotMatches ".*Linu*" "GNU/Linux")"
+ assertEquals\
+ "$(printFailedTest "Unsuccessful assertNotMatches" "GNU/Linux" "to not match" ".*Linu*")"\
+ "$(assertNotMatches ".*Linu*" "GNU/Linux")"
}
diff --git a/tests/unit/console_results_test.sh b/tests/unit/console_results_test.sh
new file mode 100644
index 00000000..f21e8578
--- /dev/null
+++ b/tests/unit/console_results_test.sh
@@ -0,0 +1,171 @@
+#!/bin/bash
+
+function test_not_render_passed_tests_when_no_passed_tests_nor_assertions() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertNotMatches\
+ ".*Tests:[^\n]*passed[^\n]*total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_not_render_passed_assertions_when_no_passed_tests_nor_assertions() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertNotMatches\
+ ".*Assertions:[^\n]*passed[^\n]*total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_passed_tests_when_passed_tests() {
+ local test_passed=1
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Tests:[^\n]*1 passed[^\n]*1 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_passed_tests_when_passed_assertions() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=1
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Tests:[^\n]*0 passed[^\n]*0 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_passed_assertions_when_passed_tests() {
+ local test_passed=1
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Assertions:[^\n]*0 passed[^\n]*0 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_passed_assertions_when_passed_assertions() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=1
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Assertions:[^\n]*1 passed[^\n]*1 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_not_render_failed_tests_when_not_failed_tests() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertNotMatches\
+ ".*Tests:[^\n]*failed[^\n]*total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_not_render_failed_assertions_when_not_failed_tests() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertNotMatches\
+ ".*Assertions:[^\n]*failed[^\n]*total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_failed_tests_when_failed_tests() {
+ local test_passed=0
+ local test_failed=1
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Tests:[^\n]*1 failed[^\n]*1 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_failed_assertions_when_failed_tests() {
+ local test_passed=0
+ local test_failed=1
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertMatches\
+ ".*Assertions:[^\n]*0 failed[^\n]*0 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_not_render_all_tests_passed_when_failed_tests() {
+ local test_passed=0
+ local test_failed=1
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertNotMatches\
+ ".*All tests passed.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_all_tests_passed_when_not_failed_tests() {
+ local test_passed=0
+ local test_failed=0
+ local assertions_passed=0
+ local assertions_failed=0
+
+ assertMatches\
+ ".*All tests passed.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_total_tests_is_the_sum_of_passed_and_failed_tests() {
+ local test_passed=4
+ local test_failed=2
+ local assertions_passed=1
+ local assertions_failed=3
+
+ assertMatches\
+ ".*Tests:[^\n]*6 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_total_asserts_is_the_sum_of_passed_and_failed_asserts() {
+ local test_passed=4
+ local test_failed=2
+ local assertions_passed=1
+ local assertions_failed=3
+
+ assertMatches\
+ ".*Assertions:[^\n]*4 total.*"\
+ "$(renderResult $test_passed $test_failed $assertions_passed $assertions_failed)"
+}
+
+function test_render_time_of_execution_when_all_assertions_passed() {
+ if [[ $_OS != "OSX" ]]; then
+ assertMatches\
+ ".*Time taken: [[:digit:]]+ ms"\
+ "$(renderResult)"
+ fi
+}
+
+function test_render_time_of_execution_when_not_all_assertions_passed() {
+ if [[ $_OS != "OSX" ]]; then
+ assertMatches\
+ ".*Time taken: [[:digit:]]+ ms"\
+ "$(renderResult)"
+ fi
+}
diff --git a/tests/unit/render_test.sh b/tests/unit/render_test.sh
deleted file mode 100644
index 95eac847..00000000
--- a/tests/unit/render_test.sh
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/bash
-
-function test_render_result_total_tests() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=1
-
- # shellcheck disable=SC2059
- assertContains\
- "$(printf "${COLOR_FAINT}Total tests:${COLOR_DEFAULT} ${COLOR_BOLD}2${COLOR_DEFAULT}")"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
-}
-
-function test_render_result_total_assertions() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=1
- # shellcheck disable=SC2059
- assertContains\
- "$(printf "${COLOR_FAINT}Total assertions:${COLOR_DEFAULT} ${COLOR_BOLD}6${COLOR_DEFAULT}")"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
-}
-
-function test_render_result_total_assertions_failed() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=1
-
-# shellcheck disable=SC2059
- assertContains\
- "$(printf "${COLOR_FAINT}Total assertions failed:${COLOR_DEFAULT} ${COLOR_BOLD}${COLOR_FAILED}1${COLOR_DEFAULT}")"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
-
-}
-
-function test_render_result_not_total_assertions_failed() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=0
-
- assertNotContains\
- "Total assertions failed"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
-}
-
-function test_render_result_all_assertions_passed() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=0
-
- assertContains\
- "All assertions passed."\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
-}
-
-function test_render_result_not_all_assertions_passed() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=1
-
- assertNotContains\
- "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
-
- if [[ $OS != "OSX" ]]; then
- assertMatches\
- ".*Time taken: [[:digit:]]+ ms"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
- fi
-}
-
-function test_render_time_of_execution_when_not_all_assertions_passed() {
- local total_tests=2
- local assertions_passed=5
- local assertions_failed=1
-
- if [[ $OS != "OSX" ]]; then
- assertMatches\
- ".*Time taken: [[:digit:]]+ ms"\
- "$(renderResult $total_tests $assertions_passed $assertions_failed)"
- fi
-}