|
1 | | -fail_test() { |
2 | | - echo "FAILED: $1" |
3 | | - rm -rf "$ASDF_DIR" |
4 | | - exit 1 |
5 | | -} |
6 | 1 |
|
7 | 2 | plugin_test_command() { |
8 | | - ASDF_DIR=$(mktemp -dt asdf.XXXX) |
9 | | - export ASDF_DIR |
10 | | - git clone https://github.com/asdf-vm/asdf.git "$ASDF_DIR" |
11 | 3 |
|
12 | 4 | local plugin_name=$1 |
13 | 5 | local plugin_url=$2 |
14 | 6 | local plugin_command="${*:3}" |
15 | 7 |
|
16 | | - if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then |
17 | | - fail_test "please provide a plugin name and url" |
18 | | - fi |
| 8 | + local exit_code |
| 9 | + local TEST_DIR |
19 | 10 |
|
20 | | - if ! (asdf plugin-add "$plugin_name" "$plugin_url"); then |
21 | | - fail_test "could not install $plugin_name from $plugin_url" |
22 | | - fi |
| 11 | + TEST_DIR=$(mktemp -dt asdf.XXXX) |
| 12 | + git clone "$ASDF_DIR/.git" "$TEST_DIR" |
23 | 13 |
|
24 | | - if ! (asdf plugin-list | grep "^$plugin_name$" > /dev/null); then |
25 | | - fail_test "$plugin_name was not properly installed" |
26 | | - fi |
| 14 | + fail_test() { |
| 15 | + echo "FAILED: $1" |
| 16 | + rm -rf "$TEST_DIR" |
| 17 | + exit 1 |
| 18 | + } |
27 | 19 |
|
28 | | - local versions |
29 | | - # shellcheck disable=SC2046 |
30 | | - if ! read -r -a versions <<< $(asdf list-all "$plugin_name"); then |
31 | | - fail_test "list-all exited with an error" |
32 | | - fi |
| 20 | + plugin_test() { |
| 21 | + export ASDF_DIR=$TEST_DIR |
33 | 22 |
|
34 | | - if [ ${#versions} -eq 0 ]; then |
35 | | - fail_test "list-all did not return any version" |
36 | | - fi |
| 23 | + # shellcheck disable=SC1090 |
| 24 | + source "$ASDF_DIR/asdf.sh" |
37 | 25 |
|
38 | | - local latest_version |
39 | | - latest_version=${versions[${#versions[@]} - 1]} |
| 26 | + if [ -z "$plugin_name" ] || [ -z "$plugin_url" ]; then |
| 27 | + fail_test "please provide a plugin name and url" |
| 28 | + fi |
40 | 29 |
|
41 | | - if ! (asdf install "$plugin_name" "$latest_version"); then |
42 | | - fail_test "install exited with an error" |
43 | | - fi |
| 30 | + if ! (asdf plugin-add "$plugin_name" "$plugin_url"); then |
| 31 | + fail_test "could not install $plugin_name from $plugin_url" |
| 32 | + fi |
44 | 33 |
|
45 | | - cd "$ASDF_DIR" || fail_test "could not cd $ASDF_DIR" |
| 34 | + if ! (asdf plugin-list | grep "^$plugin_name$" > /dev/null); then |
| 35 | + fail_test "$plugin_name was not properly installed" |
| 36 | + fi |
46 | 37 |
|
47 | | - if ! (asdf local "$plugin_name" "$latest_version"); then |
48 | | - fail_test "install did not add the requested version" |
49 | | - fi |
50 | 38 |
|
51 | | - if ! (asdf reshim "$plugin_name"); then |
52 | | - fail_test "could not reshim plugin" |
53 | | - fi |
| 39 | + local versions |
| 40 | + # shellcheck disable=SC2046 |
| 41 | + if ! read -r -a versions <<< $(asdf list-all "$plugin_name"); then |
| 42 | + fail_test "list-all exited with an error" |
| 43 | + fi |
| 44 | + |
| 45 | + if [ ${#versions} -eq 0 ]; then |
| 46 | + fail_test "list-all did not return any version" |
| 47 | + fi |
| 48 | + |
| 49 | + local latest_version |
| 50 | + latest_version=${versions[${#versions[@]} - 1]} |
| 51 | + |
| 52 | + if ! (asdf install "$plugin_name" "$latest_version"); then |
| 53 | + fail_test "install exited with an error" |
| 54 | + fi |
| 55 | + |
| 56 | + cd "$TEST_DIR" || fail_test "could not cd $TEST_DIR" |
| 57 | + |
| 58 | + if ! (asdf local "$plugin_name" "$latest_version"); then |
| 59 | + fail_test "install did not add the requested version" |
| 60 | + fi |
54 | 61 |
|
55 | | - if [ -n "$plugin_command" ]; then |
56 | | - (PATH="$ASDF_DIR/bin:$ASDF_DIR/shims:$PATH" "$plugin_command") |
57 | | - local exit_code |
58 | | - exit_code=$? |
59 | | - if [ $exit_code != 0 ]; then |
60 | | - fail_test "$plugin_command failed with exit code $?" |
| 62 | + if ! (asdf reshim "$plugin_name"); then |
| 63 | + fail_test "could not reshim plugin" |
61 | 64 | fi |
62 | | - fi |
63 | 65 |
|
64 | | - # Assert the scripts in bin are executable by asdf |
65 | | - for filename in "$ASDF_DIR/plugins/$plugin_name/bin"/* |
66 | | - do |
67 | | - if [ ! -x "$filename" ]; then |
68 | | - fail_test "Incorrect permissions on $filename. Must be executable by asdf" |
| 66 | + if [ -n "$plugin_command" ]; then |
| 67 | + $plugin_command |
| 68 | + exit_code=$? |
| 69 | + if [ $exit_code != 0 ]; then |
| 70 | + fail_test "$plugin_command failed with exit code $?" |
| 71 | + fi |
69 | 72 | fi |
70 | | - done |
71 | 73 |
|
72 | | - # Assert that a license file exists in the plugin repo and is not empty |
73 | | - license_file="$ASDF_DIR/plugins/$plugin_name/LICENSE" |
74 | | - if [ -f "$license_file" ]; then |
75 | | - if [ ! -s "$license_file" ]; then |
76 | | - fail_test "LICENSE file in the plugin repository must not be empty" |
| 74 | + # Assert the scripts in bin are executable by asdf |
| 75 | + for filename in "$ASDF_DIR/plugins/$plugin_name/bin"/* |
| 76 | + do |
| 77 | + if [ ! -x "$filename" ]; then |
| 78 | + fail_test "Incorrect permissions on $filename. Must be executable by asdf" |
| 79 | + fi |
| 80 | + done |
| 81 | + |
| 82 | + # Assert that a license file exists in the plugin repo and is not empty |
| 83 | + license_file="$ASDF_DIR/plugins/$plugin_name/LICENSE" |
| 84 | + if [ -f "$license_file" ]; then |
| 85 | + if [ ! -s "$license_file" ]; then |
| 86 | + fail_test "LICENSE file in the plugin repository must not be empty" |
| 87 | + fi |
| 88 | + else |
| 89 | + fail_test "LICENSE file must be present in the plugin repository" |
77 | 90 | fi |
78 | | - else |
79 | | - fail_test "LICENSE file must be present in the plugin repository" |
80 | | - fi |
| 91 | + } |
81 | 92 |
|
82 | | - rm -rf "$ASDF_DIR" |
| 93 | + # run test in a subshell |
| 94 | + (plugin_test) |
| 95 | + exit_code=$? |
| 96 | + rm -rf "$TEST_DIR" |
| 97 | + exit $exit_code |
83 | 98 | } |
0 commit comments