Skip to content

Commit bc993e1

Browse files
committed
fix(compat): use glob pattern instead of regex for code fence
Replace regex matching with glob pattern matching for code fence detection to avoid backtick escaping issues in Bash 3.0. Changed from: [[ "$line" =~ ^\`\`\` ]] To: [[ "$line" == '```'* ]] This is more reliable across all Bash versions.
1 parent ea2970a commit bc993e1

21 files changed

Lines changed: 142 additions & 63 deletions

src/console_header.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ function bashunit::console_header::print_version_with_env() {
1111
bashunit::console_header::print_version "$filter" "$@"
1212

1313
if bashunit::env::is_dev_mode_enabled; then
14-
printf "%sDev log:%s %s\n" "${_BASHUNIT_COLOR_INCOMPLETE}" "${_BASHUNIT_COLOR_DEFAULT}" "$BASHUNIT_DEV_LOG"
14+
printf "%sDev log:%s %s\n" \
15+
"${_BASHUNIT_COLOR_INCOMPLETE}" "${_BASHUNIT_COLOR_DEFAULT}" "$BASHUNIT_DEV_LOG"
1516
fi
1617
}
1718

@@ -51,9 +52,9 @@ EOF
5152
printf "%s%sbashunit%s - %s\n" \
5253
"$_BASHUNIT_COLOR_BOLD" "$_BASHUNIT_COLOR_PASSED" "$_BASHUNIT_COLOR_DEFAULT" "$BASHUNIT_VERSION"
5354
else
54-
printf "${_BASHUNIT_COLOR_BOLD}${_BASHUNIT_COLOR_PASSED}bashunit${_BASHUNIT_COLOR_DEFAULT} - %s | Tests: %s\n" \
55-
"$BASHUNIT_VERSION" \
56-
"$total_tests"
55+
printf "%s%sbashunit%s - %s | Tests: %s\n" \
56+
"${_BASHUNIT_COLOR_BOLD}" "${_BASHUNIT_COLOR_PASSED}" "${_BASHUNIT_COLOR_DEFAULT}" \
57+
"$BASHUNIT_VERSION" "$total_tests"
5758
fi
5859
}
5960

src/console_results.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ function bashunit::console_results::print_failure_message() {
241241
local line
242242
line="$(printf "\
243243
${_BASHUNIT_COLOR_FAILED}✗ Failed${_BASHUNIT_COLOR_DEFAULT}: %s
244-
${_BASHUNIT_COLOR_FAINT}Message:${_BASHUNIT_COLOR_DEFAULT} ${_BASHUNIT_COLOR_BOLD}'%s'${_BASHUNIT_COLOR_DEFAULT}\n" \
244+
${_BASHUNIT_COLOR_FAINT}Message:${_BASHUNIT_COLOR_DEFAULT} \
245+
${_BASHUNIT_COLOR_BOLD}'%s'${_BASHUNIT_COLOR_DEFAULT}\n" \
245246
"${test_name}" "${failure_message}")"
246247

247248
bashunit::state::print_line "failure" "$line"

src/doc.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function bashunit::doc::print_asserts() {
1717

1818
# Patterns stored in variable for Bash 3.0 compatibility
1919
local _doc_pattern='^## ([A-Za-z0-9_]+)'
20-
local _code_fence_pattern='^\`\`\`'
2120
local line
2221
while IFS='' read -r line || [[ -n "$line" ]]; do
2322
if [[ $line =~ $_doc_pattern ]]; then
@@ -33,7 +32,9 @@ function bashunit::doc::print_asserts() {
3332
fi
3433

3534
if ((should_print)); then
36-
if [[ "$line" =~ $_code_fence_pattern ]]; then
35+
# Check for code fence using pattern matching instead of regex
36+
# Avoids backtick escaping issues in Bash 3.0
37+
if [[ "$line" == '```'* ]]; then
3738
echo "--------------"
3839
echo "$docstring"
3940
should_print=0

src/runner.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# Pre-compiled regex pattern for parsing test result assertions
55
if [[ -z ${_BASHUNIT_RUNNER_PARSE_RESULT_REGEX+x} ]]; then
6-
declare -r _BASHUNIT_RUNNER_PARSE_RESULT_REGEX='ASSERTIONS_FAILED=([0-9]*)##ASSERTIONS_PASSED=([0-9]*)##''ASSERTIONS_SKIPPED=([0-9]*)##ASSERTIONS_INCOMPLETE=([0-9]*)##ASSERTIONS_SNAPSHOT=([0-9]*)##''TEST_EXIT_CODE=([0-9]*)'
6+
declare -r _BASHUNIT_RUNNER_PARSE_RESULT_REGEX='ASSERTIONS_FAILED=([0-9]*)##'\
7+
'ASSERTIONS_PASSED=([0-9]*)##ASSERTIONS_SKIPPED=([0-9]*)##'\
8+
'ASSERTIONS_INCOMPLETE=([0-9]*)##ASSERTIONS_SNAPSHOT=([0-9]*)##TEST_EXIT_CODE=([0-9]*)'
79
fi
810

911
function bashunit::runner::restore_workdir() {

src/state.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,16 @@ function bashunit::state::export_subshell_context() {
231231
fi
232232

233233
cat <<EOF
234-
##ASSERTIONS_FAILED=$_BASHUNIT_ASSERTIONS_FAILED##ASSERTIONS_PASSED=$_BASHUNIT_ASSERTIONS_PASSED##ASSERTIONS_SKIPPED=$_BASHUNIT_ASSERTIONS_SKIPPED##ASSERTIONS_INCOMPLETE=$_BASHUNIT_ASSERTIONS_INCOMPLETE##ASSERTIONS_SNAPSHOT=$_BASHUNIT_ASSERTIONS_SNAPSHOT##TEST_EXIT_CODE=$_BASHUNIT_TEST_EXIT_CODE##TEST_HOOK_FAILURE=$_BASHUNIT_TEST_HOOK_FAILURE##TEST_HOOK_MESSAGE=$encoded_test_hook_message##TEST_TITLE=$encoded_test_title##TEST_OUTPUT=$encoded_test_output##
234+
##ASSERTIONS_FAILED=$_BASHUNIT_ASSERTIONS_FAILED\
235+
##ASSERTIONS_PASSED=$_BASHUNIT_ASSERTIONS_PASSED\
236+
##ASSERTIONS_SKIPPED=$_BASHUNIT_ASSERTIONS_SKIPPED\
237+
##ASSERTIONS_INCOMPLETE=$_BASHUNIT_ASSERTIONS_INCOMPLETE\
238+
##ASSERTIONS_SNAPSHOT=$_BASHUNIT_ASSERTIONS_SNAPSHOT\
239+
##TEST_EXIT_CODE=$_BASHUNIT_TEST_EXIT_CODE\
240+
##TEST_HOOK_FAILURE=$_BASHUNIT_TEST_HOOK_FAILURE\
241+
##TEST_HOOK_MESSAGE=$encoded_test_hook_message\
242+
##TEST_TITLE=$encoded_test_title\
243+
##TEST_OUTPUT=$encoded_test_output##
235244
EOF
236245
}
237246

tests/acceptance/bashunit_direct_fn_call_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ function test_bashunit_direct_fn_call_failure() {
7878
local expected="foo"
7979
local actual="bar"
8080

81-
assert_match_snapshot "$(./bashunit --no-parallel -a assert_same --env "$TEST_ENV_FILE" "$expected" $actual 2>&1)"
82-
assert_general_error "$(./bashunit --no-parallel -a assert_same --env "$TEST_ENV_FILE" "$expected" $actual)"
81+
assert_match_snapshot \
82+
"$(./bashunit --no-parallel -a assert_same --env "$TEST_ENV_FILE" "$expected" $actual 2>&1)"
83+
assert_general_error \
84+
"$(./bashunit --no-parallel -a assert_same --env "$TEST_ENV_FILE" "$expected" $actual)"
8385
}
8486

8587
function test_bashunit_direct_fn_call_non_existing_fn() {

tests/acceptance/bashunit_fail_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function test_bashunit_when_a_test_fail_verbose_output_option() {
2121
}
2222

2323
function test_different_verbose_snapshots_matches() {
24-
bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?"
24+
bashunit::todo \
25+
"The different snapshots for these tests should also be identical, option to choose snapshot name?"
2526
}
2627

2728
function test_bashunit_when_a_test_fail_simple_output_env() {
@@ -53,5 +54,6 @@ function test_bashunit_with_a_test_fail_and_exit_immediately() {
5354
}
5455

5556
function test_different_simple_snapshots_matches() {
56-
bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?"
57+
bashunit::todo \
58+
"The different snapshots for these tests should also be identical, option to choose snapshot name?"
5759
}

tests/acceptance/bashunit_pass_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function test_bashunit_when_a_test_passes_verbose_output_option() {
2121
}
2222

2323
function test_different_verbose_snapshots_matches() {
24-
bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?"
24+
bashunit::todo \
25+
"The different snapshots for these tests should also be identical, option to choose snapshot name?"
2526
}
2627

2728
function test_bashunit_when_a_test_passes_simple_output_env() {
@@ -39,5 +40,6 @@ function test_bashunit_when_a_test_passes_simple_output_option() {
3940
}
4041

4142
function test_different_simple_snapshots_matches() {
42-
bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?"
43+
bashunit::todo \
44+
"The different snapshots for these tests should also be identical, option to choose snapshot name?"
4345
}

tests/acceptance/bashunit_report_html_test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function set_up_before_script() {
99
function test_bashunit_when_report_html_option() {
1010
local test_file=./tests/acceptance/fixtures/test_bashunit_when_report_html.sh
1111

12-
assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --report-html custom.html "$test_file")"
12+
assert_match_snapshot \
13+
"$(./bashunit --no-parallel --env "$TEST_ENV_FILE" --report-html custom.html "$test_file")"
1314
assert_file_exists custom.html
1415

1516
if [[ -f custom.html ]]; then

tests/acceptance/bashunit_script_temp_file_cleanup_test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function test_script_temp_files_are_cleaned_up_after_test_run() {
3333
# Check that no parallel temp files remain in the temp directory
3434

3535
if [[ -d "$parallel_temp_base_dir" ]]; then
36-
remaining_files=$(find "$parallel_temp_base_dir" -name "script_with_setup_temp_file" 2>/dev/null || true)
36+
remaining_files=$(find "$parallel_temp_base_dir" \
37+
-name "script_with_setup_temp_file" 2>/dev/null || true)
3738

3839
assert_empty "$remaining_files"
3940

0 commit comments

Comments
 (0)