Skip to content

Commit

Permalink
Merge pull request #373 from TypedDevs/fix/ubuntu-tr-warning-on-ci
Browse files Browse the repository at this point in the history
Fix tr warning on ubuntu's CI
  • Loading branch information
Chemaclass authored Oct 13, 2024
2 parents 9a74d96 + e297056 commit 843cd51
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
7 changes: 6 additions & 1 deletion src/globals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ function is_command_available() {

function random_str() {
local length=${1:-6}
LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c "$length"
local chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
local str=''
for (( i=0; i<length; i++ )); do
str+="${chars:RANDOM%${#chars}:1}"
done
echo "$str"
}

function temp_file() {
Expand Down
20 changes: 3 additions & 17 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function runner::run_test() {
subshell_output=$line
fi

local runtime_output="${test_execution_result%%##TEST_ID=*}"
local runtime_output="${test_execution_result%%##ASSERTIONS_=*}"

local runtime_error=""
for error in "command not found" "unbound variable" "permission denied" \
Expand Down Expand Up @@ -281,14 +281,7 @@ function runner::parse_result_parallel() {
count=$((count + 1))
done

if env::is_dev_mode_enabled; then
local test_id=$(\
echo "$execution_result" |\
tail -n 1 |\
sed -E -e 's/.*##TEST_ID=([a-zA-Z0-9]*)##.*/\1/g'\
)
log "debug" "[PARA] test_id:$test_id" "function_name:$function_name" "execution_result:$execution_result"
fi
log "debug" "[PARA]" "function_name:$function_name" "execution_result:$execution_result"

runner::parse_result_sync "$function_name" "$execution_result"

Expand Down Expand Up @@ -329,14 +322,7 @@ function runner::parse_result_sync() {
sed -E -e 's/.*##ASSERTIONS_SNAPSHOT=([0-9]*)##.*/\1/g'\
)

if env::is_dev_mode_enabled; then
local test_id=$(\
echo "$execution_result" |\
tail -n 1 |\
sed -E -e 's/.*##TEST_ID=([a-zA-Z0-9]*)##.*/\1/g'\
)
log "debug" "[SYNC] test_id:$test_id" "function_name:$function_name" "execution_result:$execution_result"
fi
log "debug" "[SYNC]" "function_name:$function_name" "execution_result:$execution_result"

((_ASSERTIONS_PASSED += assertions_passed)) || true
((_ASSERTIONS_FAILED += assertions_failed)) || true
Expand Down
4 changes: 0 additions & 4 deletions src/state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ function state::export_subshell_context() {
encoded_test_output=$(echo -n "$_TEST_OUTPUT" | base64)
fi

local test_id
test_id=$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 8)

cat <<EOF
##TEST_ID=$test_id\
##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\
##ASSERTIONS_PASSED=$_ASSERTIONS_PASSED\
##ASSERTIONS_SKIPPED=$_ASSERTIONS_SKIPPED\
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/state_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ function test_initialize_assertions_count() {
)

assert_same\
"##TEST_ID=abc123\
##ASSERTIONS_FAILED=0\
"##ASSERTIONS_FAILED=0\
##ASSERTIONS_PASSED=0\
##ASSERTIONS_SKIPPED=0\
##ASSERTIONS_INCOMPLETE=0\
Expand All @@ -277,8 +276,7 @@ function test_export_assertions_count() {
)

assert_same\
"##TEST_ID=abc123\
##ASSERTIONS_FAILED=5\
"##ASSERTIONS_FAILED=5\
##ASSERTIONS_PASSED=10\
##ASSERTIONS_SKIPPED=42\
##ASSERTIONS_INCOMPLETE=12\
Expand All @@ -288,8 +286,7 @@ function test_export_assertions_count() {
}

function test_calculate_total_assertions() {
local input="##TEST_ID=abc123\
##ASSERTIONS_FAILED=1\
local input="##ASSERTIONS_FAILED=1\
##ASSERTIONS_PASSED=2\
##ASSERTIONS_SKIPPED=3\
##ASSERTIONS_INCOMPLETE=4\
Expand Down

0 comments on commit 843cd51

Please sign in to comment.