Skip to content

Commit

Permalink
Check if the parsed ruby is unknown in parse_ruby (closes #450)
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jun 23, 2023
1 parent 550551a commit 05126d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Fixed an implicit string splitting bug when passing in compiler env variables
via the additional configuration options
(ex: `ruby-install ruby -- CFLAGS="-O3 ..."`).
* Catch unknown ruby implementation names early before attempting to download
version information for them.

#### truffleruby

Expand Down
10 changes: 5 additions & 5 deletions share/ruby-install/ruby-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ function parse_ruby()
ruby="$string"
;;
esac

if [[ ! "${rubies[*]}" == *"$ruby"* ]]; then
echo "ruby-install: unknown ruby: $ruby" >&2
return 1
fi
}

#
Expand Down Expand Up @@ -267,11 +272,6 @@ function list_rubies()
#
function init()
{
if [[ ! "${rubies[*]}" == *"$ruby"* ]]; then
error "Unknown ruby: $ruby"
return 1
fi

local fully_qualified_version="$(lookup_ruby_version "$ruby" "$ruby_version")"

if [[ -n "$fully_qualified_version" ]]; then
Expand Down
10 changes: 10 additions & 0 deletions test/ruby-install-tests/parse_ruby_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ function test_parse_ruby_when_the_ruby_name_contains_multiple_dashes()
"$ruby_version"
}

function test_parse_ruby_with_an_unknown_ruby()
{
local unknown_ruby="foo"
local output="$(parse_ruby "$unknown_ruby" 2>&1)"

assertEquals "did not print an error for an unknwon ruby" \
"ruby-install: unknown ruby: $unknown_ruby" \
"$output"
}

SHUNIT_PARENT=$0 . $SHUNIT2

0 comments on commit 05126d6

Please sign in to comment.