Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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() {
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading