diff --git a/bash_unit b/bash_unit index 9318a02..e9e2288 100755 --- a/bash_unit +++ b/bash_unit @@ -17,6 +17,7 @@ # https://github.com/bash-unit/bash_unit # shellcheck disable=2317 # Ignore unreachable - most function are not called. +# shellcheck disable=2329 # Ignore unreachable - most function are not called. # shellcheck disable=2155 # Ignore Declare and assign separately # spellchecker: ignore NOCOLOR SHUF @@ -413,8 +414,7 @@ text_format() { } notify_message() { local message="$1" - # shellcheck disable=SC2059 - [[ -z "$message" ]] || printf -- "$message\n" + [[ -z "$message" ]] || printf -- "%b\n" "$message" } notify_stdout() { diff --git a/tests/test_cli.sh b/tests/test_cli.sh index 5959348..96264aa 100644 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -204,6 +204,30 @@ test_one_test_should_stop_when_assert_fails() { "$($BASH_UNIT <(echo 'test_fail() { echo "before failure" >&2 ; assert false ; echo "after failure" >&2 ; }') 2>&1 >/dev/null)" } +test_notify_message_handles_percent_signs_as_literal_text() { + # Test that printf in notify_message doesn't interpret % as placeholder + bash_unit_output=$($BASH_UNIT <(echo 'test_percent() { fail "Expected 100% but got 50%" ; }') 2>&1 | "$GREP" "Expected 100% but got 50%") + assert_equals "Expected 100% but got 50%" "$bash_unit_output" +} + +test_notify_message_handles_percent_signs_as_literal_text_tap_format() { + # Test that printf in notify_message doesn't interpret % as placeholder + bash_unit_output=$($BASH_UNIT -f tap <(echo 'test_percent() { fail "Expected 100% but got 50%" ; }') 2>&1 | "$GREP" "Expected 100% but got 50%") + assert_equals "# Expected 100% but got 50%" "$bash_unit_output" +} + +test_notify_message_renders_unicode_characters_correctly() { + # Test that notify_message properly interprets Unicode escape sequences and newlines + bash_unit_output=$($BASH_UNIT <(printf '%s\n' 'test_escape() { fail "Symbol: \u2713\nMultiline message" ; }') 2>&1 || : ) + assert_matches "Symbol: ✓"$'\n'"Multiline message" "$bash_unit_output" +} + +test_notify_message_renders_unicode_characters_correctly_tap_format() { + # Test that notify_message properly interprets Unicode escape sequences and newlines in TAP format + bash_unit_output=$($BASH_UNIT -f tap <(printf '%s\n' 'test_escape() { fail "Symbol: \u2713\nMultiline message" ; }') 2>&1 || : ) + assert_matches "# Symbol: ✓"$'\n'"# Multiline message" "$bash_unit_output" +} + setup() { # fake basic unix commands bash_unit relies on so that # we ensure bash_unit keeps working when people fake