Skip to content

Commit b721b2b

Browse files
authored
Merge branch 'master' into master
2 parents 45747a8 + 5d8953b commit b721b2b

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.github/workflows/bash_unit.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: bash_unit CI
2+
on:
3+
push:
4+
5+
jobs:
6+
ubuntu:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Unit testing with bash_unit
11+
run: FORCE_COLOR=true ./bash_unit tests/test*

README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Running tests in tests/test_core.sh
111111
Running test_fake_echo_stdin_when_no_params ... SUCCESS ✓
112112
Running test_fake_exports_faked_in_subshells ... SUCCESS ✓
113113
Running test_fake_transmits_params_to_fake_code ... SUCCESS ✓
114+
Running test_should_pretty_format_even_when_LANG_is_unset ... SUCCESS ✓
114115
Overall result: SUCCESS ✓
115116
```
116117

@@ -174,6 +175,7 @@ ok ✓ test_fake_can_fake_inline
174175
ok ✓ test_fake_echo_stdin_when_no_params
175176
ok ✓ test_fake_exports_faked_in_subshells
176177
ok ✓ test_fake_transmits_params_to_fake_code
178+
ok - test_should_pretty_format_even_when_LANG_is_unset
177179
```
178180

179181
== How to write tests

bash_unit

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ pretty_failure() {
243243
pretty_format() {
244244
local color="$1"
245245
local pretty_symbol="$2"
246-
local alt_symbol="$3"
246+
local alt_symbol="${3:-}"
247247
local term_utf8=false
248-
if is_terminal && [[ "$LANG" =~ .*UTF-8.* ]]
248+
#env
249+
if is_terminal && [[ "${LANG:-}" =~ .*UTF-8.* ]]
249250
then
250251
term_utf8=true
251252
fi
@@ -280,7 +281,7 @@ color() {
280281
}
281282

282283
is_terminal() {
283-
[ -t 1 ] || [[ "${FORCE_COLOR}" == true ]]
284+
[ -t 1 ] || [[ "${FORCE_COLOR:-}" == true ]]
284285
}
285286

286287
text_format() {

tests/test_core.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ EOF
150150
assert_equals 2 $(ps | "$GREP" pts | wc -l)
151151
}
152152

153+
test_should_pretty_format_even_when_LANG_is_unset() {
154+
# See https://github.com/pgrange/bash_unit/pull/81
155+
unset LANG
156+
assert "echo foo | pretty_format GREEN I"
157+
}
158+
153159
if [[ "${STICK_TO_CWD}" != true ]]
154160
then
155161
# do not test for cwd if STICK_TO_CWD is true

tests/test_doc.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ TEST_PATTERN='```test'
44
OUTPUT_PATTERN='```output'
55
LANG=C.UTF-8
66

7-
export FORCE_COLOR=false
87
export STICK_TO_CWD=true
9-
BASH_UNIT="eval ./bash_unit"
10-
#BASH_UNIT="eval FORCE_COLOR=false ./bash_unit"
8+
BASH_UNIT="eval FORCE_COLOR=false ./bash_unit"
119

1210
prepare_tests() {
1311
mkdir /tmp/$$
@@ -21,14 +19,19 @@ prepare_tests() {
2119
while grep -E '^'"$TEST_PATTERN"'$' $remaining >/dev/null
2220
do
2321
((++block))
24-
run_doc_test $remaining $swap |& sed '$a\' > $test_output$block
22+
run_doc_test $remaining $swap |& sed '$a\' | work_around_github_action_problem > $test_output$block
2523
doc_to_output $remaining $swap > $expected_output$block
2624
eval 'function test_block_'"$(printf %02d $block)"'() {
2725
assert "diff -u '"$expected_output$block"' '"$test_output$block"'"
2826
}'
2927
done
3028
}
3129
30+
work_around_github_action_problem() {
31+
# I have no idea what is happening with these broken pipes on github actions
32+
grep -v '^/usr/bin/grep: write error: Broken pipe$'
33+
}
34+
3235
function run_doc_test() {
3336
local remaining="$1"
3437
local swap="$2"

0 commit comments

Comments
 (0)