diff --git a/bashunit b/bashunit index f4b61f7e..98d9a439 100755 --- a/bashunit +++ b/bashunit @@ -25,7 +25,7 @@ source "$BASHUNIT_ROOT_DIR/src/console_results.sh" source "$BASHUNIT_ROOT_DIR/src/helpers.sh" source "$BASHUNIT_ROOT_DIR/src/upgrade.sh" source "$BASHUNIT_ROOT_DIR/src/assertions.sh" -source "$BASHUNIT_ROOT_DIR/src/log_junit.sh" +source "$BASHUNIT_ROOT_DIR/src/reports.sh" source "$BASHUNIT_ROOT_DIR/src/runner.sh" source "$BASHUNIT_ROOT_DIR/src/bashunit.sh" source "$BASHUNIT_ROOT_DIR/src/main.sh" diff --git a/src/main.sh b/src/main.sh index b637511d..0d87998b 100644 --- a/src/main.sh +++ b/src/main.sh @@ -35,11 +35,11 @@ function main::exec_tests() { exit_code=$? if [[ -n "$BASHUNIT_LOG_JUNIT" ]]; then - log_junit::generate_junit_xml "$BASHUNIT_LOG_JUNIT" + reports::generate_junit_xml "$BASHUNIT_LOG_JUNIT" fi if [[ -n "$BASHUNIT_REPORT_HTML" ]]; then - log_junit::generate_report_html "$BASHUNIT_REPORT_HTML" + reports::generate_report_html "$BASHUNIT_REPORT_HTML" fi cleanup_temp_files diff --git a/src/log_junit.sh b/src/reports.sh similarity index 74% rename from src/log_junit.sh rename to src/reports.sh index bb956c1a..73bf6011 100755 --- a/src/log_junit.sh +++ b/src/reports.sh @@ -1,46 +1,46 @@ #!/bin/bash -TEST_FILES=() -TEST_NAMES=() -TEST_STATUSES=() -TEST_DURATIONS=() -TEST_ASSERTIONS=() - -function log_junit::test_snapshot() { - log_junit::log "$1" "$2" "$3" "$4" "snapshot" +_REPORTS_TEST_FILES=() +_REPORTS_TEST_NAMES=() +_REPORTS_TEST_STATUSES=() +_REPORTS_TEST_DURATIONS=() +_REPORTS_TEST_ASSERTIONS=() + +function reports::add_snapshot() { + reports::log_test "$1" "$2" "$3" "$4" "snapshot" } -function log_junit::test_incomplete() { - log_junit::log "$1" "$2" "$3" "$4" "incomplete" +function reports::add_incomplete() { + reports::log_test "$1" "$2" "$3" "$4" "incomplete" } -function log_junit::test_skipped() { - log_junit::log "$1" "$2" "$3" "$4" "skipped" +function reports::add_skipped() { + reports::log_test "$1" "$2" "$3" "$4" "skipped" } -function log_junit::test_passed() { - log_junit::log "$1" "$2" "$3" "$4" "passed" +function reports::add_passed() { + reports::log_test "$1" "$2" "$3" "$4" "passed" } -function log_junit::test_failed() { - log_junit::log "$1" "$2" "$3" "$4" "failed" +function reports::add_failed() { + reports::log_test "$1" "$2" "$3" "$4" "failed" } -function log_junit::log() { +function reports::log_test() { local file="$1" local test_name="$2" local duration="$3" local assertions="$4" local status="$5" - TEST_FILES+=("$file") - TEST_NAMES+=("$test_name") - TEST_STATUSES+=("$status") - TEST_ASSERTIONS+=("$assertions") - TEST_DURATIONS+=("$duration") + _REPORTS_TEST_FILES+=("$file") + _REPORTS_TEST_NAMES+=("$test_name") + _REPORTS_TEST_STATUSES+=("$status") + _REPORTS_TEST_ASSERTIONS+=("$assertions") + _REPORTS_TEST_DURATIONS+=("$duration") } -function log_junit::generate_junit_xml() { +function reports::generate_junit_xml() { local output_file="$1" local test_passed test_passed=$(state::get_tests_passed) @@ -58,17 +58,17 @@ function log_junit::generate_junit_xml() { { echo "" echo "" - echo " " - for i in "${!TEST_NAMES[@]}"; do - local file="${TEST_FILES[$i]}" - local name="${TEST_NAMES[$i]}" - local assertions="${TEST_ASSERTIONS[$i]}" - local status="${TEST_STATUSES[$i]}" - local test_time="${TEST_DURATIONS[$i]}" + for i in "${!_REPORTS_TEST_NAMES[@]}"; do + local file="${_REPORTS_TEST_FILES[$i]}" + local name="${_REPORTS_TEST_NAMES[$i]}" + local assertions="${_REPORTS_TEST_ASSERTIONS[$i]}" + local status="${_REPORTS_TEST_STATUSES[$i]}" + local test_time="${_REPORTS_TEST_DURATIONS[$i]}" echo " "$output_file" } -function log_junit::generate_report_html() { +function reports::generate_report_html() { local output_file="$1" local test_passed test_passed=$(state::get_tests_passed) @@ -103,11 +103,11 @@ function log_junit::generate_report_html() { # Collect test cases by file : > "$temp_file" # Clear temp file if it exists - for i in "${!TEST_NAMES[@]}"; do - local file="${TEST_FILES[$i]}" - local name="${TEST_NAMES[$i]}" - local status="${TEST_STATUSES[$i]}" - local test_time="${TEST_DURATIONS[$i]}" + for i in "${!_REPORTS_TEST_NAMES[@]}"; do + local file="${_REPORTS_TEST_FILES[$i]}" + local name="${_REPORTS_TEST_NAMES[$i]}" + local status="${_REPORTS_TEST_STATUSES[$i]}" + local test_time="${_REPORTS_TEST_DURATIONS[$i]}" local test_case="$file|$name|$status|$test_time" echo "$test_case" >> "$temp_file" @@ -148,13 +148,13 @@ function log_junit::generate_report_html() { echo " " echo " " echo " " - echo " ${#TEST_NAMES[@]}" + echo " ${#_REPORTS_TEST_NAMES[@]}" echo " $test_passed" echo " $tests_failed" echo " $tests_incomplete" echo " $tests_skipped" echo " $tests_snapshot" - echo " ${time}" + echo " $time" echo " " echo " " echo " " diff --git a/src/runner.sh b/src/runner.sh index e5e33e07..5b3f2191 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -205,14 +205,14 @@ function runner::run_test() { if [[ -n $runtime_error ]]; then state::add_tests_failed console_results::print_error_test "$function_name" "$runtime_error" - log_junit::test_failed "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_failed "$test_file" "$function_name" "$duration" "$total_assertions" runner::write_failure_result_output "$test_file" "$runtime_error" return fi if [[ "$current_assertions_failed" != "$(state::get_assertions_failed)" ]]; then state::add_tests_failed - log_junit::test_failed "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_failed "$test_file" "$function_name" "$duration" "$total_assertions" runner::write_failure_result_output "$test_file" "$subshell_output" if env::is_stop_on_failure_enabled; then exit 1 @@ -223,19 +223,19 @@ function runner::run_test() { if [[ "$current_assertions_snapshot" != "$(state::get_assertions_snapshot)" ]]; then state::add_tests_snapshot console_results::print_snapshot_test "$function_name" - log_junit::test_snapshot "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_snapshot "$test_file" "$function_name" "$duration" "$total_assertions" return fi if [[ "$current_assertions_incomplete" != "$(state::get_assertions_incomplete)" ]]; then state::add_tests_incomplete - log_junit::test_incomplete "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_incomplete "$test_file" "$function_name" "$duration" "$total_assertions" return fi if [[ "$current_assertions_skipped" != "$(state::get_assertions_skipped)" ]]; then state::add_tests_skipped - log_junit::test_skipped "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_skipped "$test_file" "$function_name" "$duration" "$total_assertions" return fi @@ -243,7 +243,7 @@ function runner::run_test() { console_results::print_successful_test "${label}" "$duration" "$@" state::add_tests_passed - log_junit::test_passed "$test_file" "$function_name" "$duration" "$total_assertions" + reports::add_passed "$test_file" "$function_name" "$duration" "$total_assertions" } function runner::parse_result() {