From 74e19122523fba10357bb16ebcc6639701776145 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Mon, 23 Jan 2023 16:22:54 -0800 Subject: [PATCH] Added support for the `RUBY_INSTALL_PKG_MANAGER` env variable. --- share/ruby-install/system.sh | 5 +++ .../detect_package_manager_test.sh | 37 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/share/ruby-install/system.sh b/share/ruby-install/system.sh index 982c7e20..8ac20ade 100644 --- a/share/ruby-install/system.sh +++ b/share/ruby-install/system.sh @@ -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 diff --git a/test/system-tests/detect_package_manager_test.sh b/test/system-tests/detect_package_manager_test.sh index db69d3e2..dc356ed2 100755 --- a/test/system-tests/detect_package_manager_test.sh +++ b/test/system-tests/detect_package_manager_test.sh @@ -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" } @@ -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" } @@ -29,6 +28,8 @@ 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" } @@ -36,6 +37,8 @@ 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" } @@ -43,6 +46,8 @@ 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" } @@ -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" } @@ -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