diff --git a/src/console_results.sh b/src/console_results.sh index 2e551fc6..41be4331 100644 --- a/src/console_results.sh +++ b/src/console_results.sh @@ -1,6 +1,16 @@ #!/bin/bash -_SUCCESSFUL_TEST_COUNT=0 +_LINE_LENGTH=10 +_TOTAL_TESTS_FILE="/tmp/total_tests" +echo 0 > "$_TOTAL_TESTS_FILE" + +function increment_total_tests() { + local current_total + current_total=$(cat "$_TOTAL_TESTS_FILE") + local new_total=$((current_total + 1)) + echo "$new_total" > "$_TOTAL_TESTS_FILE" + echo $((new_total)) +} function console_results::render_result() { if [[ "$(state::is_duplicated_test_functions_found)" == true ]]; then @@ -108,23 +118,24 @@ function console_results::print_execution_time() { } function console_results::print_successful_test() { - ((_SUCCESSFUL_TEST_COUNT++)) + total_tests=$(increment_total_tests) if [[ "$SIMPLE_OUTPUT" == true ]]; then - if (( _SUCCESSFUL_TEST_COUNT % 50 != 0 )); then + if (( total_tests % _LINE_LENGTH != 0 )); then printf "." else - echo "." + printf ".\n" fi - else - local test_name=$1 - shift + return + fi - if [[ -z "$*" ]]; then - printf "%s✓ Passed%s: %s\n" "$_COLOR_PASSED" "$_COLOR_DEFAULT" "${test_name}" - else - printf "%s✓ Passed%s: %s (%s)\n" "$_COLOR_PASSED" "$_COLOR_DEFAULT" "${test_name}" "$*" - fi + local test_name=$1 + shift + + if [[ -z "$*" ]]; then + printf "%s✓ Passed%s: %s\n" "$_COLOR_PASSED" "$_COLOR_DEFAULT" "${test_name}" + else + printf "%s✓ Passed%s: %s (%s)\n" "$_COLOR_PASSED" "$_COLOR_DEFAULT" "${test_name}" "$*" fi } @@ -139,6 +150,17 @@ ${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s } function console_results::print_failed_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "F" + else + printf "F\n" + fi + return + fi + local test_name=$1 local expected=$2 local failure_condition_message=$3 @@ -147,7 +169,7 @@ function console_results::print_failed_test() { local extra_value=$6 printf "\ -${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s + ${_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}" @@ -160,6 +182,17 @@ ${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s } function console_results::print_failed_snapshot_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "F" + else + printf "F\n" + fi + return + fi + local test_name=$1 local snapshot_file=$2 @@ -177,6 +210,17 @@ function console_results::print_failed_snapshot_test() { } function console_results::print_skipped_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "S" + else + printf "S\n" + fi + return + fi + local test_name=$1 local reason=$2 @@ -188,6 +232,17 @@ function console_results::print_skipped_test() { } function console_results::print_incomplete_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "I" + else + printf "I\n" + fi + return + fi + local test_name=$1 local pending=$2 @@ -199,6 +254,17 @@ function console_results::print_incomplete_test() { } function console_results::print_snapshot_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "S" + else + printf "S\n" + fi + return + fi + local test_name test_name=$(helper::normalize_test_function_name "$1") @@ -206,6 +272,17 @@ function console_results::print_snapshot_test() { } function console_results::print_error_test() { + total_tests=$(increment_total_tests) + + if [[ "$SIMPLE_OUTPUT" == true ]]; then + if (( total_tests % _LINE_LENGTH != 0 )); then + printf "E" + else + printf "E\n" + fi + return + fi + local test_name test_name=$(helper::normalize_test_function_name "$1") local error="$2"