Problem
mock and spy build the double with eval "function $command() { … }", so a
name that is not a usable function name produces raw bash internals in the test
output:
functiontest_mock_with_args_in_name() {
bashunit::mock "ls -l"echo hi
assert_same "ok""ok"
}✗ Error: Mock with args in name
eval: line 58: syntax error near unexpected token `-l'
./src/doubles/mock.sh: eval: line 58: `function ls -l() { echo hi "$@"; }'
./src/doubles/mock.sh: line 63: export: ls -l: not a function
Passing the arguments along with the command (mock "ls -l" rather than
mock ls) is an easy mistake, and the message points at bashunit's internals
rather than at the call that caused it. The run does continue — later tests
still execute — so this is DX, not correctness.
Which names actually break
| accepted by bash | rejected |
|---|
foo-bar, a.b, x+y, a$b, a:b, foo_bar | whitespace, ;, |, &, (, ), ", ' |
So the check has to be narrow: plenty of odd-looking names are legitimate
command names and legal function names, and rejecting those would break
working suites.
Fix
A shared guard in the doubles module that rejects only what breaks the eval,
with a message naming the argument and the likely cause — the shape
env.sh already uses ("Only accept valid shell identifiers (defends the eval
below)").
Problem
mockandspybuild the double witheval "function $command() { … }", so aname that is not a usable function name produces raw bash internals in the test
output:
Passing the arguments along with the command (
mock "ls -l"rather thanmock ls) is an easy mistake, and the message points at bashunit's internalsrather than at the call that caused it. The run does continue — later tests
still execute — so this is DX, not correctness.
Which names actually break
foo-bar,a.b,x+y,a$b,a:b,foo_bar;,|,&,(,),",'So the check has to be narrow: plenty of odd-looking names are legitimate
command names and legal function names, and rejecting those would break
working suites.
Fix
A shared guard in the doubles module that rejects only what breaks the
eval,with a message naming the argument and the likely cause — the shape
env.shalready uses ("Only accept valid shell identifiers (defends the evalbelow)").