Skip to content

Commit

Permalink
fix: Addresses the pull request comments.
Browse files Browse the repository at this point in the history
- Changes the comparison to be strict rather than partial.
- Prints a list of missing plugins.
- Exists if at least one plugin is not present.
- Adds unit tests.
  • Loading branch information
threkk committed Sep 23, 2021
1 parent d277bbd commit 6ae8dbc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/commands/command-install.bash
Expand Up @@ -71,6 +71,7 @@ install_local_tool_versions() {
search_path=$(pwd)

local some_tools_installed
local some_plugin_not_installed

local tool_versions_path
tool_versions_path=$(find_tool_versions)
Expand All @@ -96,12 +97,17 @@ install_local_tool_versions() {
if [ -f "$tool_versions_path" ]; then
tools_file=$(strip_tool_version_comments "$tool_versions_path" | cut -d ' ' -f 1)
for plugin_name in $tools_file; do
if [[ ! "${plugins_installed[*]}" =~ $plugin_name ]]; then
if ! printf '%s\n' "${plugins_installed[@]}" | grep -P -q "^$plugin_name\$"; then
printf "%s plugin is not installed\n" "$plugin_name"
some_plugin_not_installed='yes'
fi
done
fi

if [ -n "$some_plugin_not_installed" ]; then
exit 1
fi

if [ -n "$plugins_installed" ]; then
for plugin_name in $plugins_installed; do
local plugin_version_and_path
Expand Down
18 changes: 18 additions & 0 deletions test/install_command.bats
Expand Up @@ -133,6 +133,24 @@ teardown() {
[ ! -f $ASDF_DIR/installs/dummy/1.1.0/version ]
}

@test "install_command fails if the plugin is not installed" {
cd $PROJECT_DIR
echo 'other_dummy 1.0.0' > $PROJECT_DIR/.tool-versions

run asdf install
[ "$status" -eq 1 ]
[ "$output" = "other_dummy plugin is not installed" ]
}

@test "install_command fails if the plugin is not installed without collisions" {
cd $PROJECT_DIR
printf "dummy 1.0.0\ndum 1.0.0" > $PROJECT_DIR/.tool-versions

run asdf install
[ "$status" -eq 1 ]
[ "$output" = "dum plugin is not installed" ]
}

@test "install_command fails when tool is specified but no version of the tool is configured in config file" {
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
run asdf install other-dummy
Expand Down

0 comments on commit 6ae8dbc

Please sign in to comment.