Skip to content

Commit 072a57e

Browse files
author
Daniel Perez
committed
Add command and instructions to test plugin.
1 parent dbbb0a5 commit 072a57e

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

bin/asdf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
1717
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
1818

1919
source $(dirname $(dirname $0))/lib/commands/plugin-push.sh
20+
source $(dirname $(dirname $0))/lib/commands/plugin-test.sh
2021

2122

2223
callback_args="${@:2}"
@@ -75,6 +76,9 @@ case $1 in
7576
"plugin-push")
7677
plugin_push_command $callback_args;;
7778

79+
"plugin-test")
80+
plugin_test_command $callback_args;;
81+
7882
*)
7983
help_command
8084
exit 1;;

docs/creating-plugins.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ Prints the version of the tool to use if a legacy version file is found in the c
6161
asdf allows custom shim templates. For an executable called `foo`, if there's a `shims/foo` file in the plugin, then asdf will copy that file instead of using it's standard shim template.
6262

6363
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.
64+
65+
## Testing plugins
66+
67+
`asdf` contains the `plugin-test` command to test your plugin.
68+
You can use it as follows
69+
70+
```sh
71+
asdf plugin-test <plugin-name> <plugin-url>
72+
```
73+
74+
So for example to test the Elixir plugin, we would run
75+
76+
```sh
77+
asdf plugin-test elixir https://github.com/asdf-vm/asdf-elixir.git
78+
```
79+
80+
We strongly recommend you test your plugin on TravisCI, to make sure it works
81+
on both Linux and OSX.
82+
83+
Here is a sample `.travis.yml` file, customize it to your needs
84+
85+
```yaml
86+
language: c
87+
script: asdf plugin-test elixir https://github.com/asdf-vm/asdf-elixir.git
88+
before_script:
89+
- git clone https://github.com/asdf-vm/asdf.git asdf
90+
- . asdf/asdf.sh
91+
os:
92+
- linux
93+
- osx
94+
```

lib/commands/plugin-add.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ plugin_add_command() {
77

88
if [ -d $plugin_path ]; then
99
echo "Plugin named $plugin_name already added"
10+
exit 1
1011
else
1112
git clone $source_url $plugin_path
1213
if [ $? -eq 0 ]; then
1314
chmod +x $plugin_path/bin/*
15+
else
16+
exit 1
1417
fi
1518
fi
1619
}

lib/commands/plugin-test.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
fail_test() {
2+
echo "FAILED: $1"
3+
rm -rf $ASDF_DIR
4+
exit 1
5+
}
6+
7+
plugin_test_command() {
8+
export ASDF_DIR=$(mktemp -dt asdf.XXXX)
9+
10+
local plugin_name=$1
11+
local plugin_url=$2
12+
13+
if [ -z "$plugin_name" -o -z "$plugin_url" ]; then
14+
fail_test "please provide a plugin name and url"
15+
fi
16+
17+
(asdf plugin-add $plugin_name $plugin_url)
18+
if [ $? -ne 0 ]; then
19+
fail_test "could not install $plugin_name from $plugin_url"
20+
fi
21+
22+
if ! asdf plugin-list | grep $plugin_name > /dev/null; then
23+
fail_test "$plugin_name was not properly installed"
24+
fi
25+
26+
read -a versions <<< $(asdf list-all $plugin_name)
27+
28+
if [ $? -ne 0 ]; then
29+
fail_test "list-all exited with an error"
30+
fi
31+
32+
if [ ${#versions} -eq 0 ]; then
33+
fail_test "list-all did not return any version"
34+
fi
35+
36+
(asdf install $plugin_name ${versions[0]})
37+
38+
if [ $? -ne 0 ]; then
39+
fail_test "install exited with an error"
40+
fi
41+
42+
rm -rf $ASDF_DIR
43+
}

0 commit comments

Comments
 (0)