Navigation Menu

Skip to content

Commit

Permalink
fix: Quote commands correctly in plugin-test (#1078)
Browse files Browse the repository at this point in the history
* fix: Quote commands correctly in plugin-test
* make it posix compliant
* default to $SHELL
  • Loading branch information
raxod502 committed Nov 2, 2021
1 parent d566a36 commit 69ff2d0
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions lib/commands/command-plugin-test.bash
Expand Up @@ -2,35 +2,42 @@

plugin_test_command() {

local plugin_name=$1
local plugin_url=$2
local plugin_command_array=()
local plugin_command
local plugin_name="$1"
local plugin_url="$2"
shift 2

local plugin_gitref="master"
local tool_version
# shellcheck disable=SC2086
set -- ${*:3}

while [[ $# -gt 0 ]]; do
case $1 in
--asdf-plugin-gitref)
plugin_gitref="$2"
shift # past flag
shift # past value
;;
--asdf-tool-version)
tool_version="$2"
shift # past flag
shift # past value
;;
*)
plugin_command_array+=("$1") # save it in an array for later
shift # past argument
;;
esac
local interpret_args_literally

for arg; do
shift
if [ -n "${interpret_args_literally}" ]; then
set -- "$@" "${arg}"
else
case "${arg}" in
--asdf-plugin-gitref)
plugin_gitref="$2"
shift 2
;;
--asdf-tool-version)
tool_version="$2"
shift 2
;;
--)
interpret_args_literally=true
shift
;;
*)
set -- "$@" "${arg}"
;;
esac
fi
done

plugin_command="${plugin_command_array[*]}"
if [ "$#" -eq 1 ]; then
set -- "${SHELL:-sh}" -c "$1"
fi

local exit_code
local TEST_DIR
Expand Down Expand Up @@ -128,11 +135,11 @@ plugin_test_command() {
fail_test "could not reshim plugin"
fi

if [ -n "$plugin_command" ]; then
$plugin_command
if [ "$#" -gt 0 ]; then
"$@"
exit_code=$?
if [ $exit_code != 0 ]; then
fail_test "$plugin_command failed with exit code $?"
fail_test "$* failed with exit code $?"
fi
fi

Expand All @@ -155,7 +162,7 @@ plugin_test_command() {
}

# run test in a subshell
(plugin_test)
(plugin_test "$@")
exit_code=$?
rm -rf "$TEST_DIR"
exit $exit_code
Expand Down

0 comments on commit 69ff2d0

Please sign in to comment.