diff --git a/internal/cli/cli.go b/internal/cli/cli.go index c91f02d6c..491522dce 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -1028,10 +1028,18 @@ func pluginTestCommand(l *log.Logger, args []string, toolVersion, ref string) { failTest(l, "list-all did not return any version") } - // grab first version returned by list-all callback if no version provided as - // a CLI argument + // Resolve version: if empty use first from list-all; if "latest" or + // "latest:" resolve via the plugin's latest-stable callback. if toolVersion == "" { toolVersion = allVersions[0] + } else if toolVersion == "latest" || strings.HasPrefix(toolVersion, "latest:") { + query := strings.TrimPrefix(toolVersion, "latest") + query = strings.TrimPrefix(query, ":") + resolved, err := versions.Latest(plugin, query) + if err != nil || resolved == "" { + failTest(l, "could not get latest version") + } + toolVersion = resolved } err = versions.InstallOneVersion(conf, plugin, toolVersion, false, os.Stdout, os.Stderr) diff --git a/test/fixtures/dummy_plugin/bin/install b/test/fixtures/dummy_plugin/bin/install index 1d511dafe..850e2edd3 100755 --- a/test/fixtures/dummy_plugin/bin/install +++ b/test/fixtures/dummy_plugin/bin/install @@ -2,7 +2,7 @@ # We want certain versions to fail installation for various reasons in the tests check_dummy_versions() { - local bad_versions=" other-dummy " + local bad_versions=" other-dummy latest " if [[ "$bad_versions" == *" $ASDF_INSTALL_VERSION "* ]]; then echo "Dummy couldn't install version: $ASDF_INSTALL_VERSION (on purpose)" exit 1 diff --git a/test/plugin_test_command.bats b/test/plugin_test_command.bats index 389f8bb2d..2e66ac74f 100644 --- a/test/plugin_test_command.bats +++ b/test/plugin_test_command.bats @@ -32,3 +32,8 @@ teardown() { run asdf plugin test dummy "${BASE_DIR}/repo-dummy" --asdf-tool-version 1.0.0 --asdf-plugin-gitref master [ "$status" -eq 0 ] } + +@test "plugin_test_command resolves latest version when --asdf-tool-version latest is provided" { + run asdf plugin test dummy "${BASE_DIR}/repo-dummy" --asdf-tool-version latest + [ "$status" -eq 0 ] +}