Skip to content

Commit

Permalink
Fix symlink RubyGems test problems for non-admin user.
Browse files Browse the repository at this point in the history
  • Loading branch information
simi authored and deivid-rodriguez committed Apr 19, 2020
1 parent 2302455 commit 75f672f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
17 changes: 17 additions & 0 deletions lib/rubygems/installer_test_case.rb
Expand Up @@ -230,4 +230,21 @@ def util_installer(spec, gem_home, user=false)
:user_install => user)
end

@@symlink_supported = nil

# This is needed for Windows environment without symlink support enabled (the default
# for non admin) to be able to skip test for features using symlinks.
def symlink_supported?
if @@symlink_supported.nil?
begin
File.symlink("", "")
rescue Errno::ENOENT, Errno::EEXIST
@@symlink_supported = true
rescue NotImplementedError, SystemCallError
@@symlink_supported = false
end
end
@@symlink_supported
end

end
26 changes: 7 additions & 19 deletions test/rubygems/test_gem_installer.rb
Expand Up @@ -3,24 +3,6 @@

class TestGemInstaller < Gem::InstallerTestCase

@@symlink_supported = nil

# Our CI does not currently hit the "symlink not supported" case, but this is
# needed for Windows developers without symlink support enabled (the default
# for non admin) to be able to run the tests successfully
def symlink_supported?
if @@symlink_supported.nil?
begin
File.symlink("", "")
rescue Errno::ENOENT, Errno::EEXIST
@@symlink_supported = true
rescue NotImplementedError, SystemCallError
@@symlink_supported = false
end
end
@@symlink_supported
end

def setup
super
common_installer_setup
Expand Down Expand Up @@ -2097,7 +2079,13 @@ def test_default_gem_without_wrappers
assert_path_exists installed_exec

wrapper = File.read installed_exec
refute_match %r{generated by RubyGems}, wrapper

if symlink_supported?
refute_match %r{generated by RubyGems}, wrapper
else # when symlink not supported, it warns and fallbacks back to installing wrapper
assert_match %r{Unable to use symlinks, installing wrapper}, @ui.error
assert_match %r{generated by RubyGems}, wrapper
end
end

def test_default_gem_with_wrappers
Expand Down
2 changes: 2 additions & 0 deletions test/rubygems/test_gem_uninstaller.rb
Expand Up @@ -154,6 +154,8 @@ def test_remove_not_in_home
end

def test_remove_symlinked_gem_home
skip "Symlinks not supported or not enabled" unless symlink_supported?

Dir.mktmpdir("gem_home") do |dir|
symlinked_gem_home = "#{dir}/#{File.basename(@gemhome)}"

Expand Down

0 comments on commit 75f672f

Please sign in to comment.