Skip to content

Commit

Permalink
Added support for the RUBY_INSTALL_PKG_MANAGER env variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jan 24, 2023
1 parent cd4eeeb commit 74e1912
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
5 changes: 5 additions & 0 deletions share/ruby-install/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function detect_sudo()
#
function detect_package_manager()
{
if [[ -n "$RUBY_INSTALL_PKG_MANAGER" ]]; then
package_manager="$RUBY_INSTALL_PKG_MANAGER"
return
fi

case "$os_platform" in
Linux)
if [[ -f /etc/redhat-release ]]; then
Expand Down
37 changes: 32 additions & 5 deletions test/system-tests/detect_package_manager_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
. ./test/helper.sh
. ./share/ruby-install/system.sh

function oneTimeSetUp()
{
detect_package_manager
}

function test_detect_package_manager_on_redhat_based_systems_with_dnf()
{
[[ -f /etc/redhat-release ]] && command -v dnf >/dev/null || return 0

detect_package_manager

assertEquals "did not prefer dnf over yum" "dnf" "$package_manager"
}

Expand All @@ -21,6 +18,8 @@ function test_detect_package_manager_on_redhat_based_systems_with_yum()
! command -v dnf >/dev/null &&
command -v yum >/dev/null || return 0

detect_package_manager

assertEquals "did not fallback to yum" "yum" "$package_manager"
}

Expand All @@ -29,20 +28,26 @@ function test_detect_package_manager_on_debian_based_systems_with_apt()
[[ -f /etc/debian_version ]] && command -v apt >/dev/null || \
return 0

detect_package_manager

assertEquals "did not detect apt" "apt" "$package_manager"
}

function test_detect_package_manager_on_open_suse_systems_with_zypper()
{
[[ -f /etc/SuSE-release ]] && command -v zypper >/dev/null || return 0

detect_package_manager

assertEquals "did not detect zypper" "zypper" "$package_manager"
}

function test_detect_package_manager_on_bsd_systems_with_pkg()
{
[[ "$os_platform" == *BSD ]] && command -v pkg >/dev/null || return 0

detect_package_manager

assertEquals "did not detect pkg" "pkg" "$package_manager"
}

Expand All @@ -51,6 +56,8 @@ function test_detect_package_manager_on_macos_systems_with_homebrew()
[[ "$os_platform" == *Darwin ]] && command -v brew >/dev/null || \
return 0

detect_package_manager

assertEquals "did not prefer brew over port" "brew" "$package_manager"
}

Expand All @@ -60,7 +67,27 @@ function test_detect_package_manager_on_macos_systems_with_macports()
! command -v brew >/dev/null &&
command -v port >/dev/null || return 0

detect_package_manager

assertEquals "did not fallback to macports" "port" "$package_manager"
}

function test_detect_package_manager_when_RUBY_INSTALL_PKG_MANAGER_is_set()
{
RUBY_INSTALL_PKG_MANAGER="custom"

detect_package_manager

assertEquals "did not set package_manager to $$RUBY_INSTALL_PKG_MANAGER" \
"$RUBY_INSTALL_PKG_MANAGER" "$package_manager"


unset RUBY_INSTALL_PKG_MANAGER
}

function tearDown()
{
unset package_manager
}

SHUNIT_PARENT=$0 . $SHUNIT2

0 comments on commit 74e1912

Please sign in to comment.