Skip to content

Commit 2714990

Browse files
committed
Fix: mock a command which contains special characters
1 parent d9a6c16 commit 2714990

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

bach.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ SCRIPT
367367
mockfunc="$(@generate_mock_function_name "${cmd[@]}")"
368368
#stderr name="$name"
369369
#body="function ${mockfunc}() { @debug Running mock : '${cmd[*]}' :; $func; }"
370-
declare mockfunc_seq="${mockfunc//@/__}_SEQ"
371-
mockfunc_seq="${mockfunc_seq//-/__}"
370+
declare mockfunc_seq="${mockfunc//_/__}_SEQ"
371+
mockfunc_seq="${mockfunc_seq//[-\!+.@\[\]\{\}~]/_}"
372372
body="function ${mockfunc}() {
373373
declare -gxi ${mockfunc_seq}=\"\${${mockfunc_seq}:-0}\";
374374
if bach--is-function \"${mockfunc}_\$(( ${mockfunc_seq} + 1))\"; then

tests/bach-testing-framework.test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,16 @@ test-mock-builtin-command-with-external-commands1-assert() {
217217
}
218218

219219

220+
test-mock-command-contains-special-characters() {
221+
set -x
222+
@mock 'omg_!@[1]{2}+~.sh'
223+
224+
'omg_!@[1]{2}+~.sh' --version
225+
}
226+
test-mock-command-contains-special-characters-assert() {
227+
@dryrun 'omg_!@[1]{2}+~.sh' --version
228+
}
229+
220230
test-mock-builtin-command-with-external-commands2() {
221231
@mock command mycmd param1 === @stdout myoutput
222232

0 commit comments

Comments
 (0)