Skip to content

Commit

Permalink
Sort versions
Browse files Browse the repository at this point in the history
Some tests were failing because our sort order was depending on the
order `mdfind` was returning Xcodes. This uses sort -n to sort versions
by their numeric order.
  • Loading branch information
klaaspieter committed Mar 27, 2021
1 parent 94582be commit d68f58d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions share/chxcode/chxcode
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ system_xcode_version() {

xcode_versions() {
system_version=$(system_xcode_version)
versions=()
for xcode in ${XCODES[*]}; do
version=$(xcode_version "$xcode")
versions+=${version}
done

IFS=$'\n' versions=($(sort -n <<<"${versions[*]}")); unset IFS

for version in ${versions[*]}; do
if [ "$version" = "$system_version" ]; then
echo "* $version"
else
Expand Down
4 changes: 2 additions & 2 deletions test/chxcode_test
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
. ./test/helper

test_exec_with_no_arguments() {
export DEVELOPER_DIR="$search_path/Xcode.app/Contents/Developer"
export DEVELOPER_DIR="$search_path/Xcode.app/Contents/Developer"

xcodes=$(chxcode | tr '\n' ' ' | xargs)

assertEquals "should print installed xcodes" "9.2 * 9.3" "$xcodes"
assertEquals "should print installed xcodes" "* 9.3 9.2" "$xcodes"
}

test_change_unknown_xcode_reports_error() {
Expand Down

0 comments on commit d68f58d

Please sign in to comment.