Skip to content

Commit 1928bef

Browse files
Aki Arviopgrange
authored andcommitted
Fix pretty_format failure under set -o pipefail
Previously pretty_format used a conditional with &&. When the caller had pipefail enabled and alt_symbol was empty, the conditional could return a non-zero status and cause the whole pipeline to fail. This change prevents false failures when running tests with pipefail enabled.
1 parent 650b6da commit 1928bef

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

bash_unit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ pretty_format() {
357357
if $term_utf8
358358
then
359359
echo -en " $pretty_symbol "
360-
else
361-
[[ -n "$alt_symbol" ]] && echo -en " $alt_symbol "
360+
elif [[ -n "$alt_symbol" ]]; then
361+
echo -en " $alt_symbol "
362362
fi
363363
) | color "$color"
364364
}

tests/test_core.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ test_should_pretty_format_even_when_LANG_is_unset() {
225225
assert "echo foo | pretty_format GREEN I"
226226
}
227227

228+
test_should_pretty_format_even_with_pipefail_set() {
229+
# pretty_success must not fail when alt_symbol is empty with pipefail set.
230+
(
231+
set -o pipefail
232+
unset LANG
233+
assert "echo foo | pretty_success"
234+
)
235+
}
236+
228237
if [[ "${STICK_TO_CWD:-}" != true ]]
229238
then
230239
# do not test for cwd if STICK_TO_CWD is true

0 commit comments

Comments
 (0)