Merge pull request #61 from tuvistavie/improve-plugin-test

Improve plugin tests
This commit is contained in:
Daniel Perez 2016-06-17 18:39:48 +09:00 committed by GitHub
commit f53ee42dc1
2 changed files with 29 additions and 5 deletions

View File

@ -68,13 +68,14 @@ This must be used wisely. For now AFAIK, it's only being used in the Elixir plug
You can use it as follows
```sh
asdf plugin-test <plugin-name> <plugin-url>
asdf plugin-test <plugin-name> <plugin-url> [test-command]
```
So for example to test the Elixir plugin, we would run
The two first arguments are required. 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 elixir https://github.com/asdf-vm/asdf-elixir.git
asdf plugin-test nodejs https://github.com/asdf-vm/asdf-nodejs.git 'node --version'
```
We strongly recommend you test your plugin on TravisCI, to make sure it works
@ -84,7 +85,7 @@ Here is a sample `.travis.yml` file, customize it to your needs
```yaml
language: c
script: asdf plugin-test elixir https://github.com/asdf-vm/asdf-elixir.git
script: asdf plugin-test nodejs https://github.com/asdf-vm/asdf-nodejs.git 'node --version'
before_script:
- git clone https://github.com/asdf-vm/asdf.git asdf
- . asdf/asdf.sh

View File

@ -6,9 +6,11 @@ fail_test() {
plugin_test_command() {
export ASDF_DIR=$(mktemp -dt asdf.XXXX)
git clone https://github.com/asdf-vm/asdf.git $ASDF_DIR
local plugin_name=$1
local plugin_url=$2
local plugin_command="${@:3}"
if [ -z "$plugin_name" -o -z "$plugin_url" ]; then
fail_test "please provide a plugin name and url"
@ -33,11 +35,32 @@ plugin_test_command() {
fail_test "list-all did not return any version"
fi
(asdf install $plugin_name ${versions[0]})
latest_version=${versions[${#versions[@]} - 1]}
(asdf install $plugin_name $latest_version)
if [ $? -ne 0 ]; then
fail_test "install exited with an error"
fi
cd $ASDF_DIR
(asdf local $plugin_name $latest_version)
if [ $? -ne 0 ]; then
fail_test "install did not add the requested version"
fi
(asdf reshim $plugin_name)
if [ $? -ne 0 ]; then
fail_test "could not reshim plugin"
fi
if [ -n "$plugin_command" ]; then
(PATH="$ASDF_DIR/bin":"$ASDF_DIR/shims":$PATH eval "$plugin_command")
exit_code=$?
if [ $exit_code -ne 0 ]; then
fail_test "$plugin_command failed with exit code $?"
fi
fi
rm -rf $ASDF_DIR
}