Skip to content

Commit 170f064

Browse files
committed
feat: add ID=random-str to each assertion
1 parent 4301a55 commit 170f064

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/runner.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function runner::run_test() {
158158
# Closes FD 3, which was used temporarily to hold the original stdout.
159159
exec 3>&-
160160

161-
runner::parse_result "$test_execution_result" "$@"
161+
runner::parse_result "$function_name" "$test_execution_result" "$@"
162162

163163
local subshell_output=$(\
164164
echo "$test_execution_result" |\
@@ -243,19 +243,23 @@ function runner::run_test() {
243243
}
244244

245245
function runner::parse_result() {
246+
local function_name=$1
247+
shift
246248
local execution_result=$1
247249
shift
248250
local args=("$@")
249251

250252
if env::is_parallel_run_enabled; then
251-
runner::parse_result_parallel "$execution_result" "${args[@]}"
253+
runner::parse_result_parallel "$function_name" "$execution_result" "${args[@]}"
252254
else
253-
runner::parse_result_sync "$execution_result"
255+
runner::parse_result_sync "$function_name" "$execution_result"
254256
fi
255257
}
256258

257259
# shellcheck disable=SC2155
258260
function runner::parse_result_parallel() {
261+
local function_name=$1
262+
shift
259263
local execution_result=$1
260264
shift
261265
local args=("$@")
@@ -283,7 +287,8 @@ function runner::parse_result_parallel() {
283287

284288
# shellcheck disable=SC2155
285289
function runner::parse_result_sync() {
286-
local execution_result=$1
290+
local function_name=$1
291+
local execution_result=$2
287292

288293
local assertions_failed=$(\
289294
echo "$execution_result" |\
@@ -315,6 +320,8 @@ function runner::parse_result_sync() {
315320
sed -E -e 's/.*##ASSERTIONS_SNAPSHOT=([0-9]*)##.*/\1/g'\
316321
)
317322

323+
log "$function_name" "$execution_result"
324+
318325
((_ASSERTIONS_PASSED += assertions_passed)) || true
319326
((_ASSERTIONS_FAILED += assertions_failed)) || true
320327
((_ASSERTIONS_SKIPPED += assertions_skipped)) || true

src/state.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ function state::export_subshell_context() {
148148
encoded_test_output=$(echo -n "$_TEST_OUTPUT" | base64)
149149
fi
150150

151-
echo "##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\
151+
echo "##ID=$(random_str)\
152+
##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\
152153
##ASSERTIONS_PASSED=$_ASSERTIONS_PASSED\
153154
##ASSERTIONS_SKIPPED=$_ASSERTIONS_SKIPPED\
154155
##ASSERTIONS_INCOMPLETE=$_ASSERTIONS_INCOMPLETE\

tests/unit/state_test.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ function test_set_duplicated_functions_merged() {
234234
}
235235

236236
function test_initialize_assertions_count() {
237+
mock random_str echo "abc123"
238+
237239
local export_assertions_count
238240
export_assertions_count=$(
239241
_ASSERTIONS_PASSED=10
@@ -247,7 +249,8 @@ function test_initialize_assertions_count() {
247249
)
248250

249251
assert_same\
250-
"##ASSERTIONS_FAILED=0\
252+
"##ID=abc123\
253+
##ASSERTIONS_FAILED=0\
251254
##ASSERTIONS_PASSED=0\
252255
##ASSERTIONS_SKIPPED=0\
253256
##ASSERTIONS_INCOMPLETE=0\
@@ -258,6 +261,8 @@ function test_initialize_assertions_count() {
258261
}
259262

260263
function test_export_assertions_count() {
264+
mock random_str echo "abc123"
265+
261266
local export_assertions_count
262267
export_assertions_count=$(
263268
_ASSERTIONS_PASSED=10
@@ -272,7 +277,8 @@ function test_export_assertions_count() {
272277
)
273278

274279
assert_same\
275-
"##ASSERTIONS_FAILED=5\
280+
"##ID=abc123\
281+
##ASSERTIONS_FAILED=5\
276282
##ASSERTIONS_PASSED=10\
277283
##ASSERTIONS_SKIPPED=42\
278284
##ASSERTIONS_INCOMPLETE=12\
@@ -282,12 +288,13 @@ function test_export_assertions_count() {
282288
}
283289

284290
function test_calculate_total_assertions() {
285-
local input="##ASSERTIONS_FAILED=1\
291+
local input="##ID=abc123\
292+
##ASSERTIONS_FAILED=1\
286293
##ASSERTIONS_PASSED=2\
287294
##ASSERTIONS_SKIPPED=3\
288295
##ASSERTIONS_INCOMPLETE=4\
289296
##ASSERTIONS_SNAPSHOT=5\
290-
##TEST_OUTPUT=##"
297+
##TEST_OUTPUT=3zhbEncodedBase64##"
291298

292299
assert_same 15 "$(state::calculate_total_assertions "$input")"
293300
}

0 commit comments

Comments
 (0)