Skip to content

Commit 9628fdb

Browse files
authored
Merge pull request #90 from jneves/pass-params-as-array
Pass params as array
2 parents ade9ba2 + bbc7c38 commit 9628fdb

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

README.adoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Running tests in tests/test_core.sh
114114
Running test_fake_echo_stdin_when_no_params ... SUCCESS
115115
Running test_fake_exports_faked_in_subshells ... SUCCESS
116116
Running test_fake_transmits_params_to_fake_code ... SUCCESS
117+
Running test_fake_transmits_params_to_fake_code_as_array ... SUCCESS
117118
Running test_should_pretty_format_even_when_LANG_is_unset ... SUCCESS
118119
Overall result: SUCCESS
119120
```
@@ -185,6 +186,7 @@ ok - test_fake_can_fake_inline
185186
ok - test_fake_echo_stdin_when_no_params
186187
ok - test_fake_exports_faked_in_subshells
187188
ok - test_fake_transmits_params_to_fake_code
189+
ok - test_fake_transmits_params_to_fake_code_as_array
188190
ok - test_should_pretty_format_even_when_LANG_is_unset
189191
```
190192

@@ -664,7 +666,7 @@ test_code_gives_ps_appropriate_parameters() {
664666
24162 pts/7 00:00:00 ps
665667
8387 ? 0:00 /usr/sbin/apache2 -k start
666668
EOF
667-
assert_equals ax "$FAKE_PARAMS"
669+
assert_equals ax "${FAKE_PARAMS[@]}"
668670
}
669671
export -f _ps
670672
fake ps _ps
@@ -698,7 +700,7 @@ code() {
698700

699701
test_code_gives_ps_appropriate_parameters() {
700702
_ps() {
701-
assert_equals ax "$FAKE_PARAMS"
703+
assert_equals ax "${FAKE_PARAMS[@]}"
702704
}
703705
export -f _ps
704706
fake ps _ps
@@ -728,7 +730,7 @@ code() {
728730

729731
test_code_gives_ps_appropriate_parameters() {
730732
_ps() {
731-
echo $FAKE_PARAMS > /tmp/fake_params
733+
echo ${FAKE_PARAMS[@]} > /tmp/fake_params
732734
}
733735
export -f _ps
734736
fake ps _ps
@@ -763,7 +765,7 @@ code() {
763765
}
764766

765767
test_code_gives_ps_appropriate_parameters() {
766-
fake ps 'echo $FAKE_PARAMS >/tmp/fake_params'
768+
fake ps 'echo ${FAKE_PARAMS[@]} >/tmp/fake_params'
767769

768770
code || true
769771

@@ -792,7 +794,7 @@ test_get_data_from_fake() {
792794
#Fasten you seat belt ...
793795
coproc cat
794796
exec {test_channel}>&${COPROC[1]}
795-
fake ps 'echo $FAKE_PARAMS >&$test_channel'
797+
fake ps 'echo ${FAKE_PARAMS[@]} >&$test_channel'
796798

797799
code || true
798800

bash_unit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fake() {
158158
shift
159159
if [ $# -gt 0 ]
160160
then
161-
eval "function $command() { export FAKE_PARAMS=\"\$@\" ; $@ ; }"
161+
eval "function $command() { export FAKE_PARAMS=(\"\$@\") ; $@ ; }"
162162
else
163163
eval "function $command() { echo \"$($CAT)\" ; }"
164164
fi

tests/test_core.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ test_fake_transmits_params_to_fake_code() {
164164
ps aux
165165
}
166166

167+
test_fake_transmits_params_to_fake_code_as_array() {
168+
function _ps() {
169+
assert_equals "1" "${#FAKE_PARAMS[@]}"
170+
}
171+
export -f _ps
172+
fake ps _ps
173+
174+
ps "hello world"
175+
}
176+
167177
test_fake_echo_stdin_when_no_params() {
168178
fake ps << EOF
169179
PID TTY TIME CMD

0 commit comments

Comments
 (0)