From 19122b7186d57775f0e15985f1440079316bf36b Mon Sep 17 00:00:00 2001 From: Aki Arvio Date: Thu, 15 Jan 2026 07:38:08 +0200 Subject: [PATCH 1/2] 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. --- bash_unit | 4 ++-- tests/test_core.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bash_unit b/bash_unit index 9318a02..e24f406 100755 --- a/bash_unit +++ b/bash_unit @@ -357,8 +357,8 @@ pretty_format() { if $term_utf8 then echo -en " $pretty_symbol " - else - [[ -n "$alt_symbol" ]] && echo -en " $alt_symbol " + elif [[ -n "$alt_symbol" ]]; then + echo -en " $alt_symbol " fi ) | color "$color" } diff --git a/tests/test_core.sh b/tests/test_core.sh index c5fcede..02bd596 100644 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -225,6 +225,15 @@ test_should_pretty_format_even_when_LANG_is_unset() { assert "echo foo | pretty_format GREEN I" } +test_should_pretty_format_even_with_pipefail_set() { + # pretty_success must not fail when alt_symbol is empty with pipefail set. + ( + set -o pipefail + unset LANG + assert "echo foo | pretty_success" + ) +} + if [[ "${STICK_TO_CWD:-}" != true ]] then # do not test for cwd if STICK_TO_CWD is true From 9223a39c5f2963f878e167d66e94fb8b83871cf9 Mon Sep 17 00:00:00 2001 From: Pascal Grange Date: Sun, 18 Jan 2026 12:18:08 +0100 Subject: [PATCH 2/2] fix: addapt doc to match last evolution --- README.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 98fa737..84f847e 100644 --- a/README.adoc +++ b/README.adoc @@ -206,6 +206,7 @@ Running tests in tests/test_core.sh Running test_fake_transmits_params_to_fake_code ... SUCCESS Running test_fake_transmits_params_to_fake_code_as_array ... SUCCESS Running test_should_pretty_format_even_when_LANG_is_unset ... SUCCESS + Running test_should_pretty_format_even_with_pipefail_set ... SUCCESS Overall result: SUCCESS ``` @@ -315,7 +316,8 @@ ok - test_fake_exports_faked_in_subshells ok - test_fake_transmits_params_to_fake_code ok - test_fake_transmits_params_to_fake_code_as_array ok - test_should_pretty_format_even_when_LANG_is_unset -1..30 +ok - test_should_pretty_format_even_with_pipefail_set +1..31 ``` == How to write tests