mirror of
https://github.com/rbenv/ruby-build.git
synced 2026-05-15 00:46:53 -04:00
`resolve_version` strips the leading `ruby-` from its argument and then only looks for the stripped form in the definitions directory. For canonical definitions whose filename retains the `ruby-` prefix (currently `ruby-dev`) the exact-match step searches for `dev`, which does not exist, and the grep fallback's `^dev[-.]` anchor also misses the `ruby-dev` line in the definitions list. Result: `ruby-build ruby-dev` reports "definition not found" even though the file is shipped. Try the original (unstripped) argument first in the exact-match loop, then fall back to the stripped form. Numeric-version inputs (`ruby-3.4.9`, `3.4`, `ruby-3.4`) and other implementations (`mruby-dev`, `jruby-dev`) are unaffected because their existing code paths still match. Regression introduced in #2610.
293 lines
6.7 KiB
Bash
293 lines
6.7 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
NUM_DEFINITIONS="$(ls "$BATS_TEST_DIRNAME"/../share/ruby-build | wc -l)"
|
|
|
|
@test "list all local definitions" {
|
|
run ruby-build --definitions
|
|
assert_success
|
|
assert_output_contains "1.9.3-p194"
|
|
assert_output_contains "jruby-1.7.9"
|
|
assert_output_contains "truffleruby-1.0.0-rc2"
|
|
assert [ "${#lines[*]}" -eq "$NUM_DEFINITIONS" ]
|
|
}
|
|
|
|
@test "custom RUBY_BUILD_ROOT: nonexistent" {
|
|
export RUBY_BUILD_ROOT="$TMP"
|
|
refute [ -e "${RUBY_BUILD_ROOT}/share/ruby-build" ]
|
|
run ruby-build --definitions
|
|
assert_success ""
|
|
}
|
|
|
|
@test "custom RUBY_BUILD_ROOT: single definition" {
|
|
export RUBY_BUILD_ROOT="$TMP"
|
|
mkdir -p "${RUBY_BUILD_ROOT}/share/ruby-build"
|
|
touch "${RUBY_BUILD_ROOT}/share/ruby-build/1.9.3-test"
|
|
run ruby-build --definitions
|
|
assert_success "1.9.3-test"
|
|
}
|
|
|
|
@test "one path via RUBY_BUILD_DEFINITIONS" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "$RUBY_BUILD_DEFINITIONS"
|
|
touch "${RUBY_BUILD_DEFINITIONS}/1.9.3-test"
|
|
run ruby-build --definitions
|
|
assert_success
|
|
assert_output_contains "1.9.3-test"
|
|
assert [ "${#lines[*]}" -eq "$((NUM_DEFINITIONS + 1))" ]
|
|
}
|
|
|
|
@test "multiple paths via RUBY_BUILD_DEFINITIONS" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions:${TMP}/other"
|
|
mkdir -p "${TMP}/definitions"
|
|
touch "${TMP}/definitions/1.9.3-test"
|
|
mkdir -p "${TMP}/other"
|
|
touch "${TMP}/other/2.1.2-test"
|
|
run ruby-build --definitions
|
|
assert_success
|
|
assert_output_contains "1.9.3-test"
|
|
assert_output_contains "2.1.2-test"
|
|
assert [ "${#lines[*]}" -eq "$((NUM_DEFINITIONS + 2))" ]
|
|
}
|
|
|
|
@test "installing definition from RUBY_BUILD_DEFINITIONS by priority" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions:${TMP}/other"
|
|
mkdir -p "${TMP}/definitions"
|
|
echo true > "${TMP}/definitions/1.9.3-test"
|
|
mkdir -p "${TMP}/other"
|
|
echo false > "${TMP}/other/1.9.3-test"
|
|
run bin/ruby-build "1.9.3-test" "${TMP}/install"
|
|
assert_success ""
|
|
}
|
|
|
|
@test "installing definition by prefix" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
echo false > "${TMP}/definitions/1.8.6"
|
|
echo false > "${TMP}/definitions/1.9.3"
|
|
echo true > "${TMP}/definitions/1.9.10"
|
|
echo false > "${TMP}/definitions/1.90.0"
|
|
echo false > "${TMP}/definitions/2.0.0"
|
|
|
|
run bin/ruby-build "1.9" "${TMP}/install"
|
|
assert_success ""
|
|
}
|
|
|
|
@test "resolve failure" {
|
|
run bin/ruby-build --resolve "doesntexist"
|
|
assert_failure ""
|
|
}
|
|
|
|
@test "resolve definition by version prefix" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/1.8.6"
|
|
touch "${TMP}/definitions/1.9.3"
|
|
touch "${TMP}/definitions/1.9.10"
|
|
touch "${TMP}/definitions/1.90.0"
|
|
touch "${TMP}/definitions/2.0.0"
|
|
|
|
run bin/ruby-build --resolve "1.9"
|
|
assert_success "1.9.10"
|
|
}
|
|
|
|
@test "resolve definition by exact match" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/3.2.1"
|
|
|
|
run bin/ruby-build --resolve "3.2.1"
|
|
assert_success "3.2.1"
|
|
}
|
|
|
|
@test "resolve definition by exact match and ruby prefix" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/3.2.1"
|
|
|
|
run bin/ruby-build --resolve "ruby-3.2.1"
|
|
assert_success "3.2.1"
|
|
}
|
|
|
|
@test "resolve definition by exact match for ruby-prefixed name" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/ruby-dev"
|
|
|
|
run bin/ruby-build --resolve "ruby-dev"
|
|
assert_success "ruby-dev"
|
|
}
|
|
|
|
@test "resolve definition with ruby prefix" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/1.8.6"
|
|
touch "${TMP}/definitions/1.9.3"
|
|
touch "${TMP}/definitions/1.9.10"
|
|
touch "${TMP}/definitions/1.90.0"
|
|
touch "${TMP}/definitions/2.0.0"
|
|
|
|
run bin/ruby-build --resolve "ruby-1.9"
|
|
assert_success "1.9.10"
|
|
}
|
|
|
|
@test "resolve definition by implementation name" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/fooruby-1.8.6"
|
|
touch "${TMP}/definitions/fooruby-1.9.3"
|
|
touch "${TMP}/definitions/1.9.10"
|
|
touch "${TMP}/definitions/1.90.0"
|
|
touch "${TMP}/definitions/2.0.0"
|
|
|
|
run bin/ruby-build --resolve "FooRuby"
|
|
assert_success "fooruby-1.9.3"
|
|
}
|
|
|
|
@test "resolve definition by implementation name and version" {
|
|
export RUBY_BUILD_DEFINITIONS="${TMP}/definitions"
|
|
mkdir -p "${TMP}/definitions"
|
|
|
|
touch "${TMP}/definitions/foo-1.8.6"
|
|
touch "${TMP}/definitions/foo-1.9.3"
|
|
touch "${TMP}/definitions/1.9.10"
|
|
touch "${TMP}/definitions/1.90.0"
|
|
touch "${TMP}/definitions/2.0.0"
|
|
|
|
run bin/ruby-build --resolve "foo-1.8"
|
|
assert_success "foo-1.8.6"
|
|
}
|
|
|
|
@test "installing nonexistent definition" {
|
|
run ruby-build "nonexistent" "${TMP}/install"
|
|
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.8.7
|
|
1.8.7-p72
|
|
1.8.7-p375
|
|
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
|
|
truffleruby-1.0.0-rc2
|
|
truffleruby-19.0.0
|
|
truffleruby-19.3.0
|
|
truffleruby+graalvm-20.0.0
|
|
truffleruby+graalvm-20.1.0"
|
|
for ver in $expected; do
|
|
touch "${RUBY_BUILD_ROOT}/share/ruby-build/$ver"
|
|
done
|
|
run ruby-build --definitions
|
|
assert_success "$expected"
|
|
}
|
|
|
|
@test "filtering previous Ruby versions" {
|
|
export RUBY_BUILD_ROOT="$TMP"
|
|
mkdir -p "${RUBY_BUILD_ROOT}/share/ruby-build"
|
|
|
|
all_versions="
|
|
2.4.0
|
|
2.4.1
|
|
2.4.2
|
|
2.4.3
|
|
2.4.4
|
|
2.4.5
|
|
2.4.6
|
|
2.4.7
|
|
2.4.8
|
|
2.4.9
|
|
2.5.0
|
|
2.5.1
|
|
2.5.2
|
|
2.5.3
|
|
2.5.4
|
|
2.5.5
|
|
2.5.6
|
|
2.5.7
|
|
2.6.0
|
|
2.6.1
|
|
2.6.2
|
|
2.6.3
|
|
2.6.4
|
|
2.6.5
|
|
2.7.0
|
|
jruby-1.5.6
|
|
jruby-9.2.7.0
|
|
jruby-9.2.8.0
|
|
jruby-9.2.9.0
|
|
maglev-1.0.0
|
|
mruby-1.4.1
|
|
mruby-2.0.0
|
|
mruby-2.0.1
|
|
mruby-2.1.0
|
|
rbx-3.104
|
|
rbx-3.105
|
|
rbx-3.106
|
|
rbx-3.107
|
|
truffleruby-19.2.0.1
|
|
truffleruby-19.3.0
|
|
truffleruby-19.3.0.2
|
|
truffleruby-19.3.1
|
|
truffleruby+graalvm-20.0.0
|
|
truffleruby+graalvm-20.1.0"
|
|
|
|
expected="2.4.9
|
|
2.5.7
|
|
2.6.5
|
|
2.7.0
|
|
jruby-9.2.9.0
|
|
maglev-1.0.0
|
|
mruby-2.1.0
|
|
rbx-3.107
|
|
truffleruby-19.3.1
|
|
truffleruby+graalvm-20.1.0"
|
|
|
|
for ver in $all_versions; do
|
|
touch "${RUBY_BUILD_ROOT}/share/ruby-build/$ver"
|
|
done
|
|
run ruby-build --list
|
|
assert_success "$expected"
|
|
}
|
|
|
|
@test "removing duplicate Ruby versions" {
|
|
export RUBY_BUILD_ROOT="$TMP"
|
|
export RUBY_BUILD_DEFINITIONS="${RUBY_BUILD_ROOT}/share/ruby-build"
|
|
mkdir -p "$RUBY_BUILD_DEFINITIONS"
|
|
touch "${RUBY_BUILD_DEFINITIONS}/1.9.3"
|
|
touch "${RUBY_BUILD_DEFINITIONS}/2.2.0"
|
|
|
|
run ruby-build --definitions
|
|
assert_success
|
|
assert_output <<OUT
|
|
1.9.3
|
|
2.2.0
|
|
OUT
|
|
}
|