Skip to content

Commit

Permalink
feat: add ID=random-str to each assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 11, 2024
1 parent 4301a55 commit 170f064
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" |\
Expand Down Expand Up @@ -243,19 +243,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=("$@")
Expand Down Expand Up @@ -283,7 +287,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" |\
Expand Down Expand Up @@ -315,6 +320,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
Expand Down
3 changes: 2 additions & 1 deletion src/state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
15 changes: 11 additions & 4 deletions tests/unit/state_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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\
Expand All @@ -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
Expand All @@ -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\
Expand All @@ -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")"
}

0 comments on commit 170f064

Please sign in to comment.