diff --git a/.travis.yml b/.travis.yml index f0fa7b6e..77b20bfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ install: - sudo apt-get install shunit2 zsh ruby before_script: - - echo yes | rvm implode + - sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh /usr/local/rvm /usr/local/bin/rvm - __rvm_unload script: make test diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh index 1736c79a..b078d665 100644 --- a/share/chruby/chruby.sh +++ b/share/chruby/chruby.sh @@ -1,10 +1,19 @@ CHRUBY_VERSION="0.3.8" -RUBIES=() -for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do - [[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*) -done -unset dir +function chruby_rubies() +{ + local rubies dir ruby version + rubies=() + for dir in "$@"; do + [[ -d "$dir" && -n "$(ls -A "$dir")" ]] && for ruby in "$dir"/*; do + rubies+=("$(basename "$ruby" | tr "-" ".")\t$ruby") + done + done + + printf "%b\n" "${rubies[@]}" | sort -t "." -k "1,1" -k "2,2n" -k "3,3n" -k "4,4n" | cut -f 2 +} + +RUBIES=($(chruby_rubies "$PREFIX/opt/rubies" "$HOME/.rubies")) function chruby_reset() { diff --git a/test/chruby_test.sh b/test/chruby_test.sh index 15b3d7c6..8557b898 100755 --- a/test/chruby_test.sh +++ b/test/chruby_test.sh @@ -12,11 +12,22 @@ function tearDown() RUBIES=(${original_rubies[@]}) } -function test_chruby_default_RUBIES() +function test_chruby_rubies_sort_order() { - assertEquals "did not correctly populate RUBIES" \ - "$test_ruby_root" \ - "${RUBIES[*]}" + actual_order="" + for ruby in "${RUBIES[@]}"; do + actual_order="$actual_order ${ruby##*/}" + done + actual_order="${actual_order##?}" + + assertEquals "did not natural version sort" "$test_rubies_order" "$actual_order" +} + +function test_chruby_rubies_spaces() +{ + detected_ruby=$(chruby_rubies "${test_ruby_dir%/*}/r u b i e s") + + assertEquals "did not work with spaces in RUBIES path" "ruby-2.1.2" "${detected_ruby##*/}" } function test_chruby_2_0() diff --git a/test/helper.sh b/test/helper.sh index b12499c3..5b3cb41b 100644 --- a/test/helper.sh +++ b/test/helper.sh @@ -12,7 +12,9 @@ test_ruby_engine="ruby" test_ruby_version="2.0.0" test_ruby_patchlevel="353" test_ruby_api="2.0.0" -test_ruby_root="$PWD/test/opt/rubies/$test_ruby_engine-$test_ruby_version-p$test_ruby_patchlevel" +test_ruby_dir="$PWD/test/opt/rubies" +test_ruby_root="$test_ruby_dir/$test_ruby_engine-$test_ruby_version-p$test_ruby_patchlevel" +test_rubies_order="jruby-1.7.9 jruby-1.7.10 rbx-2.2.9 rbx-2.2.10 rbx-10.0.0 ruby-1.9.3-p547 ruby-2.0.0-p0 ruby-2.0.0-p195 ruby-2.0.0-p247 ruby-2.0.0-p353 ruby-2.1.0 ruby-2.1.1 ruby-2.1.2" test_path="$PATH" test_gem_home="$HOME/.gem/$test_ruby_engine/$test_ruby_version" diff --git a/test/setup b/test/setup index 64ffd39a..d77d33e7 100755 --- a/test/setup +++ b/test/setup @@ -173,6 +173,12 @@ test_ruby_root="$test_ruby_engine-$test_ruby_version-p$test_ruby_patchlevel" mkdir -p "$PREFIX/opt/rubies" cd "$PREFIX/opt/rubies" +mkdir -p "jruby-1.7.9" "jruby-1.7.10" "rbx-2.2.9" "rbx-2.2.10" "rbx-10.0.0" \ + "ruby-1.9.3-p547" "ruby-2.0.0-p0" "ruby-2.0.0-p195" "ruby-2.0.0-p247" \ + "ruby-2.0.0-p353" "ruby-2.1.0" "ruby-2.1.1" "ruby-2.1.2" + +mkdir -p "$PREFIX/opt/r u b i e s/ruby-2.1.2" + log "Downloading $test_ruby_url ..." download "$test_ruby_url" "$test_ruby_archive" || fail "Download failed"