diff --git a/.travis.yml b/.travis.yml index 6abff65..4ad4180 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ install: - zsh ~/.zshrc - sh -c "export BINDIR=$HOME ; `curl -L https://raw.github.com/rylnd/shpec/master/install.sh`" + - chmod +x $HOME/.nvm/nvm.sh - $HOME/.nvm/nvm.sh - nvm install 6 && nvm use 6 - (cd test && npm install) diff --git a/resty b/resty index 3b6368f..25c89ce 100644 --- a/resty +++ b/resty @@ -337,4 +337,26 @@ HELP # With -W option, does not write to history file [ "$1" = "-W" ] && export _RESTY_NO_HISTORY="/dev/null" && [[ $# -gt 0 ]] && shift +# Force functions to be exported to subshells if it is supported +case "$SHELL" in + */bash|bash) + declare -fx \ + resty \ + resty-compute-host-option \ + resty-call \ + resty-load-alias \ + resty-unload-alias \ + resty-head \ + resty-options \ + resty-get \ + resty-post \ + resty-put \ + resty-patch \ + resty-delete \ + resty-trace \ + -resty-help-options + ;; +esac + + resty "$@" >/dev/null 2>&1 diff --git a/test/resty_shpec.sh b/test/resty_shpec.sh index e1ed0ae..92768cb 100644 --- a/test/resty_shpec.sh +++ b/test/resty_shpec.sh @@ -1,5 +1,21 @@ [[ "$SHELL" == "bash" ]] && shopt -s expand_aliases # needed for bash +RESTY_FUNCTIONS=() +RESTY_FUNCTIONS+=(resty) +RESTY_FUNCTIONS+=(resty-compute-host-option ) +RESTY_FUNCTIONS+=(resty-call) +RESTY_FUNCTIONS+=(resty-load-alias) +RESTY_FUNCTIONS+=(resty-unload-alias) +RESTY_FUNCTIONS+=(resty-head) +RESTY_FUNCTIONS+=(resty-options) +RESTY_FUNCTIONS+=(resty-get) +RESTY_FUNCTIONS+=(resty-post) +RESTY_FUNCTIONS+=(resty-put) +RESTY_FUNCTIONS+=(resty-patch) +RESTY_FUNCTIONS+=(resty-delete) +RESTY_FUNCTIONS+=(resty-trace) +RESTY_FUNCTIONS+=(-resty-help-options ) + describe "Resty" describe "Basic" @@ -26,6 +42,13 @@ describe "Resty" assert equal "$output" "hi there" end + if [ "${SHELL}" == "bash" ]; then + it "should work in a subshell" + exported_functions="$(printf "%d" $(bash -c "declare -F | grep $(printf " -e %s" ${RESTY_FUNCTIONS})" | wc -l))" + assert equal "$exported_functions" "${#RESTY_FUNCTIONS[@]}" + end + fi + end