diff --git a/src/runner.sh b/src/runner.sh index 8c9729ce..f768bbd2 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -158,7 +158,7 @@ function runner::run_test() { # Closes FD 3, which was used temporarily to hold the original stdout. exec 3>&- - runner::parse_result "$test_execution_result" "$@" + runner::parse_result "$function_name" "$test_execution_result" "$@" local subshell_output=$(\ echo "$test_execution_result" |\ @@ -211,7 +211,12 @@ function runner::run_test() { logger::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 + if env::is_parallel_run_enabled; then + echo "matando el proceso padre?" + ps --ppid "$MAIN_BASHUNIT_PID" -o pid= | xargs -I{} kill -9 {} + else + exit 1 + fi fi return fi @@ -243,19 +248,23 @@ function runner::run_test() { } function runner::parse_result() { + local function_name=$1 + shift local execution_result=$1 shift local args=("$@") if env::is_parallel_run_enabled; then - runner::parse_result_parallel "$execution_result" "${args[@]}" + runner::parse_result_parallel "$function_name" "$execution_result" "${args[@]}" else - runner::parse_result_sync "$execution_result" + runner::parse_result_sync "$function_name" "$execution_result" fi } # shellcheck disable=SC2155 function runner::parse_result_parallel() { + local function_name=$1 + shift local execution_result=$1 shift local args=("$@") @@ -283,7 +292,8 @@ function runner::parse_result_parallel() { # shellcheck disable=SC2155 function runner::parse_result_sync() { - local execution_result=$1 + local function_name=$1 + local execution_result=$2 local assertions_failed=$(\ echo "$execution_result" |\ @@ -315,6 +325,8 @@ function runner::parse_result_sync() { sed -E -e 's/.*##ASSERTIONS_SNAPSHOT=([0-9]*)##.*/\1/g'\ ) + log "$function_name" "$execution_result" + ((_ASSERTIONS_PASSED += assertions_passed)) || true ((_ASSERTIONS_FAILED += assertions_failed)) || true ((_ASSERTIONS_SKIPPED += assertions_skipped)) || true diff --git a/src/state.sh b/src/state.sh index 86ce427c..982742ea 100644 --- a/src/state.sh +++ b/src/state.sh @@ -148,7 +148,8 @@ function state::export_subshell_context() { encoded_test_output=$(echo -n "$_TEST_OUTPUT" | base64) fi - echo "##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\ + echo "##ID=$(random_str)\ +##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\ ##ASSERTIONS_PASSED=$_ASSERTIONS_PASSED\ ##ASSERTIONS_SKIPPED=$_ASSERTIONS_SKIPPED\ ##ASSERTIONS_INCOMPLETE=$_ASSERTIONS_INCOMPLETE\ diff --git a/tests/unit/state_test.sh b/tests/unit/state_test.sh index 9fa4fda1..7deffde0 100644 --- a/tests/unit/state_test.sh +++ b/tests/unit/state_test.sh @@ -234,6 +234,8 @@ function test_set_duplicated_functions_merged() { } function test_initialize_assertions_count() { + mock random_str echo "abc123" + local export_assertions_count export_assertions_count=$( _ASSERTIONS_PASSED=10 @@ -247,7 +249,8 @@ function test_initialize_assertions_count() { ) assert_same\ - "##ASSERTIONS_FAILED=0\ + "##ID=abc123\ +##ASSERTIONS_FAILED=0\ ##ASSERTIONS_PASSED=0\ ##ASSERTIONS_SKIPPED=0\ ##ASSERTIONS_INCOMPLETE=0\ @@ -258,6 +261,8 @@ function test_initialize_assertions_count() { } function test_export_assertions_count() { + mock random_str echo "abc123" + local export_assertions_count export_assertions_count=$( _ASSERTIONS_PASSED=10 @@ -272,7 +277,8 @@ function test_export_assertions_count() { ) assert_same\ - "##ASSERTIONS_FAILED=5\ + "##ID=abc123\ +##ASSERTIONS_FAILED=5\ ##ASSERTIONS_PASSED=10\ ##ASSERTIONS_SKIPPED=42\ ##ASSERTIONS_INCOMPLETE=12\ @@ -282,12 +288,13 @@ function test_export_assertions_count() { } function test_calculate_total_assertions() { - local input="##ASSERTIONS_FAILED=1\ + local input="##ID=abc123\ + ##ASSERTIONS_FAILED=1\ ##ASSERTIONS_PASSED=2\ ##ASSERTIONS_SKIPPED=3\ ##ASSERTIONS_INCOMPLETE=4\ ##ASSERTIONS_SNAPSHOT=5\ - ##TEST_OUTPUT=##" + ##TEST_OUTPUT=3zhbEncodedBase64##" assert_same 15 "$(state::calculate_total_assertions "$input")" }