-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for changing the location of plugin scripts
- Loading branch information
Showing
21 changed files
with
257 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plugin_directory = asdf-plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Akash Manohar J | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
exit 0 |
12 changes: 12 additions & 0 deletions
12
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/get-version-from-legacy-file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
get_legacy_version() { | ||
current_directory=$1 | ||
version_file="$current_directory/.dummy-version" | ||
|
||
if [ -f "$version_file" ]; then | ||
cat "$version_file" | ||
fi | ||
} | ||
|
||
get_legacy_version "$1" |
10 changes: 10 additions & 0 deletions
10
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/help.overview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Dummy plugin documentation" | ||
echo | ||
echo "Dummy plugin is a plugin only used for unit tests" | ||
|
||
if [ -n "$ASDF_INSTALL_VERSION" ]; then | ||
echo | ||
echo "Details specific for version $ASDF_INSTALL_VERSION" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
# We want certain versions to fail installation for various reasons in the tests | ||
check_dummy_versions() { | ||
local bad_versions=" other-dummy " | ||
if [[ "$bad_versions" == *" $ASDF_INSTALL_VERSION "* ]]; then | ||
echo "Dummy couldn't install version: $ASDF_INSTALL_VERSION (on purpose)" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_dummy_versions | ||
mkdir -p "$ASDF_INSTALL_PATH" | ||
env >"$ASDF_INSTALL_PATH/env" | ||
echo "$ASDF_INSTALL_VERSION" >"$ASDF_INSTALL_PATH/version" | ||
|
||
# create the dummy executable | ||
mkdir -p "$ASDF_INSTALL_PATH/bin" | ||
cat <<EOF >"$ASDF_INSTALL_PATH/bin/dummy" | ||
echo This is Dummy ${ASDF_INSTALL_VERSION}! \$2 \$1 | ||
EOF | ||
chmod +x "$ASDF_INSTALL_PATH/bin/dummy" | ||
mkdir -p "$ASDF_INSTALL_PATH/bin/subdir" | ||
cat <<EOF >"$ASDF_INSTALL_PATH/bin/subdir/other_bin" | ||
echo This is Other Bin ${ASDF_INSTALL_VERSION}! \$2 \$1 | ||
EOF | ||
chmod +x "$ASDF_INSTALL_PATH/bin/subdir/other_bin" |
10 changes: 10 additions & 0 deletions
10
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/latest-stable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
get_latest_stable() { | ||
query=$1 | ||
|
||
version_list=(1.0.0 1.1.0 2.0.0) | ||
printf "%s\n" "${version_list[@]}" | grep -E "^\\s*$query" | tail -1 | ||
} | ||
|
||
get_latest_stable "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
versions_list=(1.0.0 1.1.0 2.0.0) | ||
echo "${versions_list[@]}" | ||
# Sending message to STD error to ensure that it is ignored | ||
echo "ignore this error" >&2 |
3 changes: 3 additions & 0 deletions
3
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/list-legacy-filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo ".dummy-version .dummyrc" |
4 changes: 4 additions & 0 deletions
4
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/parse-legacy-file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# shellcheck disable=SC2020 | ||
tr <"$1" -d "dummy-" |
3 changes: 3 additions & 0 deletions
3
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/post-plugin-add
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "plugin add path=${ASDF_PLUGIN_PATH} source_url=${ASDF_PLUGIN_SOURCE_URL}" |
3 changes: 3 additions & 0 deletions
3
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/post-plugin-update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "plugin updated path=${ASDF_PLUGIN_PATH} old git-ref=${ASDF_PLUGIN_PREV_REF} new git-ref=${ASDF_PLUGIN_POST_REF}" |
3 changes: 3 additions & 0 deletions
3
test/fixtures/dummy_subdir_plugin/asdf-plugin/bin/pre-plugin-remove
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "plugin-remove ${ASDF_PLUGIN_PATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bats | ||
|
||
load test_helpers | ||
|
||
setup() { | ||
setup_asdf_dir | ||
} | ||
|
||
teardown() { | ||
clean_asdf_dir | ||
} | ||
|
||
@test "plugin_add install subdirectory plugin" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf plugin-list | ||
# whitespace between 'elixir' and url is from printf %-15s %s format | ||
[ "$output" = "dummy-subdir" ] | ||
} | ||
|
||
@test "plugin_remove command removes the subdirectory plugin directory" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf plugin-remove "dummy-subdir" | ||
[ "$status" -eq 0 ] | ||
[ ! -d "$ASDF_DIR/plugins/dummy-subdir" ] | ||
} | ||
|
||
@test "list_all_command lists available versions" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf list-all dummy-subdir | ||
[ "$(echo -e "1.0.0\n1.1.0\n2.0.0")" == "$output" ] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "install_command installs the correct version" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf install dummy-subdir 1.1.0 | ||
# whitespace between 'elixir' and url is from printf %-15s %s format | ||
[ "$(cat "$ASDF_DIR/installs/dummy-subdir/1.1.0/version")" = "1.1.0" ] | ||
} | ||
|
||
@test "list_command should list plugins with installed versions" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf install dummy-subdir 1.0.0 | ||
run asdf install dummy-subdir 1.1.0 | ||
run asdf list | ||
[[ "$output" == "$(echo -e "dummy-subdir\n 1.0.0\n 1.1.0")"* ]] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "[latest_command - dummy_plugin] shows latest stable version" { | ||
install_mock_subdir_plugin "dummy-subdir" | ||
|
||
run asdf latest "dummy-subdir" | ||
[ "2.0.0" == "$output" ] | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "plugin_test_command works with no options provided for subdirectory plugin" { | ||
install_mock_subdir_plugin_repo dummy-subdir | ||
|
||
run asdf plugin-test dummy-subdir "${BASE_DIR}/repo-dummy-subdir" | ||
echo "status = ${status}" | ||
echo "output = ${output}" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "asdf plugin-update should pull latest default branch (refs/remotes/origin/HEAD) for subdirectory plugin" { | ||
install_mock_subdir_plugin_repo dummy-subdir | ||
run asdf plugin add "dummy-subdir" "${BASE_DIR}/repo-dummy-subdir" | ||
|
||
run asdf plugin-update dummy-subdir | ||
repo_head="$(git --git-dir "$ASDF_DIR/plugins/dummy-subdir/.git" --work-tree "$ASDF_DIR/plugins/dummy-subdir" rev-parse --abbrev-ref HEAD)" | ||
[ "$status" -eq 0 ] | ||
[[ "$output" =~ "Updating dummy-subdir to master"* ]] | ||
[ "$repo_head" = "master" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,12 @@ install_mock_broken_plugin() { | |
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_broken_plugin" "$location/plugins/$plugin_name" | ||
} | ||
|
||
install_mock_subdir_plugin() { | ||
local plugin_name=$1 | ||
local location="${2:-$ASDF_DIR}" | ||
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_subdir_plugin" "$location/plugins/$plugin_name" | ||
} | ||
|
||
install_mock_plugin_repo() { | ||
local plugin_name=$1 | ||
local location="${BASE_DIR}/repo-${plugin_name}" | ||
|
@@ -54,6 +60,17 @@ install_mock_plugin_repo() { | |
git -C "${location}" commit -q -m "asdf ${plugin_name} plugin" | ||
} | ||
|
||
install_mock_subdir_plugin_repo() { | ||
local plugin_name=$1 | ||
local location="${BASE_DIR}/repo-${plugin_name}" | ||
cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_subdir_plugin" "${location}" | ||
git -C "${location}" init -q | ||
git -C "${location}" config user.name "Test" | ||
git -C "${location}" config user.email "[email protected]" | ||
git -C "${location}" add -A | ||
git -C "${location}" commit -q -m "asdf ${plugin_name} plugin" | ||
} | ||
|
||
install_mock_plugin_version() { | ||
local plugin_name=$1 | ||
local plugin_version=$2 | ||
|