Skip to content

Commit eceec9a

Browse files
authored
Merge pull request #495 from TypedDevs/fix/494-false-negative-from-test-doubles-with-pipe
Fix false negative from assert_have_been_called_with with pipes
2 parents 01a7621 + bd9ec75 commit eceec9a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- tear_down
1313
- set_up_before_script
1414
- tear_down_after_script
15+
- Fix false negative from `assert_have_been_called_with` with pipes
1516

1617
## [0.24.0](https://github.com/TypedDevs/bashunit/compare/0.23.0...0.24.0) - 2025-09-14
1718

src/test_doubles.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function spy() {
5959
serialized+=\"\$(printf '%q' \"\$arg\")$'\\x1f'\"
6060
done
6161
serialized=\${serialized%$'\\x1f'}
62-
printf '%s|%s\\n' \"\$raw\" \"\$serialized\" >> '$params_file'
62+
printf '%s\x1e%s\\n' \"\$raw\" \"\$serialized\" >> '$params_file'
6363
local _c=\$(cat '$times_file')
6464
_c=\$((_c+1))
6565
echo \"\$_c\" > '$times_file'
@@ -115,7 +115,7 @@ function assert_have_been_called_with() {
115115
fi
116116

117117
local raw
118-
IFS='|' read -r raw _ <<<"$line"
118+
IFS=$'\x1e' read -r raw _ <<<"$line"
119119

120120
if [[ "$expected" != "$raw" ]]; then
121121
state::add_assertions_failed

tests/unit/test_doubles_test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ function test_spy_unsuccessful_not_called() {
166166
"actual" "1 times")" \
167167
"$(assert_not_called ps)"
168168
}
169+
170+
function test_spy_with_pipe_in_arguments() {
171+
spy grep
172+
173+
grep -E 'foo|bar'
174+
175+
assert_have_been_called_with grep '-E foo|bar'
176+
}

0 commit comments

Comments
 (0)