Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Quote commands correctly in plugin-test #1078

Merged
merged 7 commits into from Nov 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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