2016-05-13 00:04:01 -07:00
|
|
|
fail_test() {
|
|
|
|
echo "FAILED: $1"
|
2017-09-04 10:04:56 -07:00
|
|
|
rm -rf "$ASDF_DIR"
|
2016-05-13 00:04:01 -07:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin_test_command() {
|
2017-09-04 10:04:56 -07:00
|
|
|
ASDF_DIR=$(mktemp -dt asdf.XXXX)
|
2017-09-04 10:49:38 -07:00
|
|
|
export ASDF_DIR
|
2017-09-04 10:04:56 -07:00
|
|
|
git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR"
|
2016-05-13 00:04:01 -07:00
|
|
|
|
|
|
|
local plugin_name=$1
|
|
|
|
local plugin_url=$2
|
2017-09-04 10:04:56 -07:00
|
|
|
local plugin_command="${*:3}"
|
2016-05-13 00:04:01 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then
|
2016-05-13 00:04:01 -07:00
|
|
|
fail_test "please provide a plugin name and url"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:49:38 -07:00
|
|
|
if ! (asdf plugin-add "$plugin_name" "$plugin_url"); then
|
2016-05-13 00:04:01 -07:00
|
|
|
fail_test "could not install $plugin_name from $plugin_url"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:49:38 -07:00
|
|
|
if ! (asdf plugin-list | grep "$plugin_name" > /dev/null); then
|
2016-05-13 00:04:01 -07:00
|
|
|
fail_test "$plugin_name was not properly installed"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local versions
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
if ! read -r -a versions <<< $(asdf list-all "$plugin_name"); then
|
2016-05-13 00:04:01 -07:00
|
|
|
fail_test "list-all exited with an error"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${#versions} -eq 0 ]; then
|
|
|
|
fail_test "list-all did not return any version"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local latest_version
|
2016-06-15 22:06:00 -07:00
|
|
|
latest_version=${versions[${#versions[@]} - 1]}
|
|
|
|
|
2017-09-04 10:49:38 -07:00
|
|
|
if ! (asdf install "$plugin_name" "$latest_version"); then
|
2016-05-13 00:04:01 -07:00
|
|
|
fail_test "install exited with an error"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
cd "$ASDF_DIR" || fail_test "could not cd $ASDF_DIR"
|
|
|
|
|
2017-09-04 10:49:38 -07:00
|
|
|
if ! (asdf local "$plugin_name" "$latest_version"); then
|
2016-06-15 22:06:00 -07:00
|
|
|
fail_test "install did not add the requested version"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:49:38 -07:00
|
|
|
if ! (asdf reshim "$plugin_name"); then
|
2016-06-15 22:06:00 -07:00
|
|
|
fail_test "could not reshim plugin"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$plugin_command" ]; then
|
2017-09-04 10:49:38 -07:00
|
|
|
(PATH="$ASDF_DIR/bin:$ASDF_DIR/shims:$PATH" eval "$plugin_command")
|
|
|
|
local exit_code
|
2016-06-15 22:06:00 -07:00
|
|
|
exit_code=$?
|
2017-09-04 10:49:38 -07:00
|
|
|
if [ $exit_code != 0 ]; then
|
2016-06-15 22:06:00 -07:00
|
|
|
fail_test "$plugin_command failed with exit code $?"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-12-21 18:58:11 -07:00
|
|
|
# Assert the scripts in bin are executable by asdf
|
2017-09-04 10:04:56 -07:00
|
|
|
for filename in "$ASDF_DIR/plugins/$plugin_name/bin"/*
|
2016-12-21 18:58:11 -07:00
|
|
|
do
|
|
|
|
if [ ! -x "$filename" ]; then
|
|
|
|
fail_test "Incorrect permissions on $filename. Must be executable by asdf"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-03-07 15:33:41 -07:00
|
|
|
# Assert that a license file exists in the plugin repo and is not empty
|
|
|
|
license_file="$ASDF_DIR/plugins/$plugin_name/LICENSE"
|
|
|
|
if [ -f "$license_file" ]; then
|
|
|
|
if [ ! -s "$license_file" ]; then
|
|
|
|
fail_test "LICENSE file in the plugin repository must not be empty"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
fail_test "LICENSE file must be present in the plugin repository"
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
rm -rf "$ASDF_DIR"
|
2016-05-13 00:04:01 -07:00
|
|
|
}
|