Merge pull request #381 from asdf-vm/tb/plugin-test-tool-version

Add --asdf-tool-version flag to plugin-test command
This commit is contained in:
Trevor Brown 2018-10-20 11:55:01 -04:00 committed by GitHub
commit 65ce0db5e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 9 deletions

View File

@ -98,7 +98,7 @@ asdf allows custom shim templates. For an executable called `foo`, if there's a
This must be used wisely. For now AFAIK, it's only being used in the Elixir plugin, because an executable is also read as an Elixir file apart from just being an executable. Which makes it not possible to use the standard bash shim.
**Important: Shim metadata **
**Important: Shim metadata**
If you create a custom shim, be sure to include a comment like the following (replacing your plugin name) in it:
@ -114,16 +114,22 @@ asdf uses this `asdf-plugin` metadata to remove unused shims when uninstalling.
You can use it as follows
```sh
asdf plugin-test <plugin-name> <plugin-url> [test-command]
asdf plugin-test <plugin-name> <plugin-url> [test-command] [--asdf-tool-version version]
```
The two first arguments are required. A command can also be passed to check it runs correctly.
The two first arguments are required. The second two arguments are optional. The third is a
command can also be passed to check it runs correctly.
For example to test the NodeJS plugin, we could run
```sh
asdf plugin-test nodejs https://github.com/asdf-vm/asdf-nodejs.git 'node --version'
```
The fourth is a tool version that can be specified if you want the test to install a
specific version of the tool. This can be useful if not all versions are compatible
with all the operating systems you are testing on. If you do not specify a version the
last version in the `list-all` output will be used.
We strongly recommend you test your plugin on TravisCI, to make sure it works
on both Linux and OSX.

View File

@ -1,9 +1,29 @@
plugin_test_command() {
local plugin_name=$1
local plugin_url=$2
local plugin_command="${*:3}"
local plugin_command_array=()
local plugin_command
local tool_version
# shellcheck disable=SC2086
set -- ${*:3}
while [[ $# -gt 0 ]]
do
case $1 in
--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
done
plugin_command="${plugin_command_array[*]}"
local exit_code
local TEST_DIR
@ -72,16 +92,23 @@ plugin_test_command() {
fail_test "list-all did not return any version"
fi
local latest_version
latest_version=${versions[${#versions[@]} - 1]}
local version
if ! (asdf install "$plugin_name" "$latest_version"); then
# Use the version passed in if it was set. Otherwise grab the latest
# version from the versions list
if [ -n "$tool_version" ]; then
version="$tool_version"
else
version=${versions[${#versions[@]} - 1]}
fi
if ! (asdf install "$plugin_name" "$version"); then
fail_test "install exited with an error"
fi
cd "$TEST_DIR" || fail_test "could not cd $TEST_DIR"
if ! (asdf local "$plugin_name" "$latest_version"); then
if ! (asdf local "$plugin_name" "$version"); then
fail_test "install did not add the requested version"
fi