Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[version-name] Try stripping .0 patch version to find a matching Xcode #19

Merged
merged 1 commit into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions libexec/xcenv-version-name
Expand Up @@ -61,10 +61,24 @@ fi
XCODE_APP="$(find_xcode_app_from_version "$XCENV_VERSION")"
if [ -n "$XCODE_APP" ]; then
return_xcenv_version "${XCODE_APP}"
elif [ -n "$1" ]; then
echo "xcenv: version \`$XCENV_VERSION' is not installed" >&2
exit 1
else
echo "xcenv: version \`$XCENV_VERSION' is not installed (set by $(xcenv-version-origin))" >&2
exit 1
fi
# If the specified version is formatted as X.X.0, strip the final .0 and re-check whether
# an installed Xcode version exists
if [[ "$XCENV_VERSION" =~ ^([1-9][0-9]*\.)([0-9]*)(\.0)$ ]]; then
STRIPPED_XCENV_VERSION=${XCENV_VERSION:0:$((${#XCENV_VERSION} - 2))}
XCODE_APP="$(find_xcode_app_from_version "$STRIPPED_XCENV_VERSION")"

if [ -n "$XCODE_APP" ]; then
return_xcenv_version "${XCODE_APP}"
exit 0
fi
fi

if [ -n "$1" ]; then
echo "xcenv: version \`$XCENV_VERSION' is not installed" >&2
exit 1
else
echo "xcenv: version \`$XCENV_VERSION' is not installed (set by $(xcenv-version-origin))" >&2
exit 1
fi
fi
7 changes: 5 additions & 2 deletions test/stub_helper.bash
Expand Up @@ -65,7 +65,8 @@ stub_list_of_xcodes() {
echo Xcode6.3.app
echo Xcode6.4.app
echo Xcode7.2.app
echo Xcode-beta.app"
echo Xcode-beta.app
echo Xcode11.app"

CODE=`cat <<fi
if [ "\\$1" = "Xcode.app" ]; then
Expand All @@ -78,8 +79,10 @@ stub_list_of_xcodes() {
echo "7.2"
elif [ "\\$1" = "Xcode-beta.app" ]; then
echo "8.0b"
elif [ "\\$1" = "Xcode11.app" ]; then
echo "11.0"
else
echo "Unkown app: \\$1"
echo "Unknown app: \\$1"
fi
`
stub_executable "xcenv-xcode-version" "$CODE"
Expand Down
10 changes: 10 additions & 0 deletions test/version-name.bats
Expand Up @@ -65,6 +65,16 @@ run_command() {
assert_failure "xcenv: version \`5.0' is not installed"
}

@test "version-name strips .0 from a X.X.0 version if corresponding Xcode can't be found" {
run_command 7.2.0
assert_output "Xcode7.2.app"
}

@test "version-name doesn't strip .0 from a X.0 version" {
run_command 11.0
assert_output "Xcode11.app"
}

@test "version-name returns error if not found and set by xcode-version file" {
stub_executable_success "xcenv-version-file" ".xcode-version"
stub_executable_success "xcenv-version-file-read" "5.0"
Expand Down