Skip to content

Commit

Permalink
refactor: reports.sh variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 12, 2024
1 parent b15838a commit 67410f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
61 changes: 26 additions & 35 deletions src/reports.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#!/bin/bash
# shellcheck disable=SC2155

_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 reports::add_test_snapshot() {
reports::add_test "$1" "$2" "$3" "$4" "snapshot"
}

function reports::add_incomplete() {
reports::log_test "$1" "$2" "$3" "$4" "incomplete"
function reports::add_test_incomplete() {
reports::add_test "$1" "$2" "$3" "$4" "incomplete"
}

function reports::add_skipped() {
reports::log_test "$1" "$2" "$3" "$4" "skipped"
function reports::add_test_skipped() {
reports::add_test "$1" "$2" "$3" "$4" "skipped"
}

function reports::add_passed() {
reports::log_test "$1" "$2" "$3" "$4" "passed"
function reports::add_test_passed() {
reports::add_test "$1" "$2" "$3" "$4" "passed"
}

function reports::add_failed() {
reports::log_test "$1" "$2" "$3" "$4" "failed"
function reports::add_test_failed() {
reports::add_test "$1" "$2" "$3" "$4" "failed"
}

function reports::log_test() {
function reports::add_test() {
local file="$1"
local test_name="$2"
local duration="$3"
Expand All @@ -42,18 +43,13 @@ function reports::log_test() {

function reports::generate_junit_xml() {
local output_file="$1"
local test_passed
test_passed=$(state::get_tests_passed)
local tests_skipped
tests_skipped=$(state::get_tests_skipped)
local tests_incomplete
tests_incomplete=$(state::get_tests_incomplete)
local tests_snapshot
tests_snapshot=$(state::get_tests_snapshot)
local tests_failed
tests_failed=$(state::get_tests_failed)
local time
time=$(clock::total_runtime_in_milliseconds)

local test_passed=$(state::get_tests_passed)
local tests_skipped=$(state::get_tests_skipped)
local tests_incomplete=$(state::get_tests_incomplete)
local tests_snapshot=$(state::get_tests_snapshot)
local tests_failed=$(state::get_tests_failed)
local time=$(clock::total_runtime_in_milliseconds)

{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
Expand Down Expand Up @@ -85,18 +81,13 @@ function reports::generate_junit_xml() {

function reports::generate_report_html() {
local output_file="$1"
local test_passed
test_passed=$(state::get_tests_passed)
local tests_skipped
tests_skipped=$(state::get_tests_skipped)
local tests_incomplete
tests_incomplete=$(state::get_tests_incomplete)
local tests_snapshot
tests_snapshot=$(state::get_tests_snapshot)
local tests_failed
tests_failed=$(state::get_tests_failed)
local time
time=$(clock::total_runtime_in_milliseconds)

local test_passed=$(state::get_tests_passed)
local tests_skipped=$(state::get_tests_skipped)
local tests_incomplete=$(state::get_tests_incomplete)
local tests_snapshot=$(state::get_tests_snapshot)
local tests_failed=$(state::get_tests_failed)
local time=$(clock::total_runtime_in_milliseconds)

# Temporary file to store test cases by file
local temp_file="temp_test_cases.txt"
Expand Down
12 changes: 6 additions & 6 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
reports::add_failed "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_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
reports::add_failed "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_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
Expand All @@ -223,27 +223,27 @@ function runner::run_test() {
if [[ "$current_assertions_snapshot" != "$(state::get_assertions_snapshot)" ]]; then
state::add_tests_snapshot
console_results::print_snapshot_test "$function_name"
reports::add_snapshot "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_snapshot "$test_file" "$function_name" "$duration" "$total_assertions"
return
fi

if [[ "$current_assertions_incomplete" != "$(state::get_assertions_incomplete)" ]]; then
state::add_tests_incomplete
reports::add_incomplete "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_incomplete "$test_file" "$function_name" "$duration" "$total_assertions"
return
fi

if [[ "$current_assertions_skipped" != "$(state::get_assertions_skipped)" ]]; then
state::add_tests_skipped
reports::add_skipped "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_skipped "$test_file" "$function_name" "$duration" "$total_assertions"
return
fi

local label="$(helper::normalize_test_function_name "$function_name")"

console_results::print_successful_test "${label}" "$duration" "$@"
state::add_tests_passed
reports::add_passed "$test_file" "$function_name" "$duration" "$total_assertions"
reports::add_test_passed "$test_file" "$function_name" "$duration" "$total_assertions"
}

function runner::parse_result() {
Expand Down

0 comments on commit 67410f7

Please sign in to comment.