Skip to content

Commit

Permalink
Merge pull request #631 from sstephenson/sort-versions
Browse files Browse the repository at this point in the history
Sort Ruby versions when listing available definitions
  • Loading branch information
mislav committed Sep 8, 2014
2 parents 274838b + 323c2b7 commit c2eb5e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -936,9 +936,13 @@ list_definitions() {
{ for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
[ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR"
done
} | sort
} | sort_versions
}

sort_versions() {
sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \
LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
}


unset VERBOSE
Expand Down
30 changes: 30 additions & 0 deletions test/definitions.bats
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,33 @@ NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)"
assert [ "$status" -eq 2 ]
assert_output "ruby-build: definition not found: nonexistent"
}

@test "sorting Ruby versions" {
export RUBY_BUILD_ROOT="$TMP"
mkdir -p "${RUBY_BUILD_ROOT}/share/ruby-build"
expected="1.9.3-dev
1.9.3-preview1
1.9.3-rc1
1.9.3-p0
1.9.3-p125
2.1.0-dev
2.1.0-rc1
2.1.0
2.1.1
2.2.0-dev
jruby-1.6.5
jruby-1.6.5.1
jruby-1.7.0-preview1
jruby-1.7.0-rc1
jruby-1.7.0
jruby-1.7.1
jruby-1.7.9
jruby-1.7.10
jruby-9000-dev
jruby-9000"
for ver in "$expected"; do
touch "${RUBY_BUILD_ROOT}/share/ruby-build/$ver"
done
run ruby-build --definitions
assert_success "$expected"
}

0 comments on commit c2eb5e2

Please sign in to comment.