Skip to content

Commit

Permalink
Merge pull request #90 from jneves/pass-params-as-array
Browse files Browse the repository at this point in the history
Pass params as array
  • Loading branch information
pgrange authored Jun 17, 2022
2 parents ade9ba2 + bbc7c38 commit 9628fdb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
12 changes: 7 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Running tests in tests/test_core.sh
Running test_fake_echo_stdin_when_no_params ... SUCCESS
Running test_fake_exports_faked_in_subshells ... SUCCESS
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
Overall result: SUCCESS
```
Expand Down Expand Up @@ -185,6 +186,7 @@ ok - test_fake_can_fake_inline
ok - test_fake_echo_stdin_when_no_params
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
```

Expand Down Expand Up @@ -664,7 +666,7 @@ test_code_gives_ps_appropriate_parameters() {
24162 pts/7 00:00:00 ps
8387 ? 0:00 /usr/sbin/apache2 -k start
EOF
assert_equals ax "$FAKE_PARAMS"
assert_equals ax "${FAKE_PARAMS[@]}"
}
export -f _ps
fake ps _ps
Expand Down Expand Up @@ -698,7 +700,7 @@ code() {

test_code_gives_ps_appropriate_parameters() {
_ps() {
assert_equals ax "$FAKE_PARAMS"
assert_equals ax "${FAKE_PARAMS[@]}"
}
export -f _ps
fake ps _ps
Expand Down Expand Up @@ -728,7 +730,7 @@ code() {

test_code_gives_ps_appropriate_parameters() {
_ps() {
echo $FAKE_PARAMS > /tmp/fake_params
echo ${FAKE_PARAMS[@]} > /tmp/fake_params
}
export -f _ps
fake ps _ps
Expand Down Expand Up @@ -763,7 +765,7 @@ code() {
}

test_code_gives_ps_appropriate_parameters() {
fake ps 'echo $FAKE_PARAMS >/tmp/fake_params'
fake ps 'echo ${FAKE_PARAMS[@]} >/tmp/fake_params'

code || true

Expand Down Expand Up @@ -792,7 +794,7 @@ test_get_data_from_fake() {
#Fasten you seat belt ...
coproc cat
exec {test_channel}>&${COPROC[1]}
fake ps 'echo $FAKE_PARAMS >&$test_channel'
fake ps 'echo ${FAKE_PARAMS[@]} >&$test_channel'

code || true

Expand Down
2 changes: 1 addition & 1 deletion bash_unit
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fake() {
shift
if [ $# -gt 0 ]
then
eval "function $command() { export FAKE_PARAMS=\"\$@\" ; $@ ; }"
eval "function $command() { export FAKE_PARAMS=(\"\$@\") ; $@ ; }"
else
eval "function $command() { echo \"$($CAT)\" ; }"
fi
Expand Down
10 changes: 10 additions & 0 deletions tests/test_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ test_fake_transmits_params_to_fake_code() {
ps aux
}

test_fake_transmits_params_to_fake_code_as_array() {
function _ps() {
assert_equals "1" "${#FAKE_PARAMS[@]}"
}
export -f _ps
fake ps _ps

ps "hello world"
}

test_fake_echo_stdin_when_no_params() {
fake ps << EOF
PID TTY TIME CMD
Expand Down

0 comments on commit 9628fdb

Please sign in to comment.