Skip to content

Commit

Permalink
Use a better detection of bundle install and add a test case
Browse files Browse the repository at this point in the history
Fixes #396
  • Loading branch information
larskanis committed Nov 8, 2024
1 parent 714c8e4 commit e76e68b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion resources/files/operating_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def operating_system_defaults

RubyInstaller::Runtime.enable_msys_apps(for_gem_install: true) unless gem_installer.spec.extensions.empty?

if !gem_installer.options || !gem_installer.options[:ignore_dependencies] || gem_installer.options[:bundler_expected_checksum]
if !gem_installer.options || !gem_installer.options[:ignore_dependencies] || gem_installer.class.to_s.include?("Bundler")
[['msys2_dependencies' , :install_packages ],
['msys2_mingw_dependencies', :install_mingw_packages]].each do |metakey, func|

Expand Down
2 changes: 2 additions & 0 deletions test/helper/testgem/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source "https://dummy-url.nonexit"
gem "testgem", "1.0.0"
36 changes: 29 additions & 7 deletions test/test_gem_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

class TestGemInstall < Minitest::Test
# Remove installed packages per:
# pacman -R mingw-w64-ucrt-x86_64-libmowgli mingw-w64-ucrt-x86_64-libguess ed
# pacman -R %MINGW_PACKAGE_PREFIX%-libmowgli %MINGW_PACKAGE_PREFIX%-libguess ed
def test_gem_install
res = system <<-EOT.gsub("\n", "&")
cd test/helper/testgem
gem build testgem.gemspec
gem install testgem-1.0.0.gem --verbose
cd test/helper/testgem
gem build testgem.gemspec
gem install testgem-1.0.0.gem --verbose
EOT
assert res, "shell commands should succeed"

Expand All @@ -27,6 +27,23 @@ def test_gem_install
FileUtils.rm("test/helper/testgem/testgem-1.0.0.gem")
end

def test_bundle_install
remove_pacman_packages_for_test
FileUtils.mkdir_p "test/helper/testgem/vendor/cache"
res = system <<-EOT.gsub("\n", "&")
cd test/helper/testgem
gem build testgem.gemspec
copy /b testgem-1.0.0.gem "vendor/cache/"
bundle install --local
EOT
assert res, "shell commands should succeed"

out = IO.popen("bundle exec ruby -rtestgem -e \"puts Libguess.determine_encoding('abc', 'Greek')\"", chdir: "test/helper/testgem", &:read)
assert_match(/UTF-8/, out.scrub, "call the ruby API of the testgem")

assert system("gem uninstall testgem --executables --force"), "uninstall testgem"
end

if RUBY_VERSION < "3.0"
TESTUSER = "ritestuser"
else
Expand Down Expand Up @@ -64,6 +81,13 @@ def with_test_user(testname: nil)
end
end

private def remove_pacman_packages_for_test
RubyInstaller::Runtime.msys2_installation.with_msys_apps_enabled do
system("pacman -R --noconfirm %MINGW_PACKAGE_PREFIX%-libmowgli %MINGW_PACKAGE_PREFIX%-libguess ed")
end
end


def test_user_gem_install
unless ENV['USERNAME'] == TESTUSER
RubyInstaller::Runtime.msys2_installation.with_msys_apps_enabled do
Expand All @@ -74,9 +98,7 @@ def test_user_gem_install
test_gem_install
end
unless ENV['USERNAME'] == TESTUSER
RubyInstaller::Runtime.msys2_installation.with_msys_apps_enabled do
system("pacman -R --noconfirm %MINGW_PACKAGE_PREFIX%-libmowgli %MINGW_PACKAGE_PREFIX%-libguess ed")
end
remove_pacman_packages_for_test
end
end

Expand Down

0 comments on commit e76e68b

Please sign in to comment.