diff options
Diffstat (limited to 'test/rubygems/test_gem_installer.rb')
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 375 |
1 files changed, 280 insertions, 95 deletions
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 0d0746ec84..61609a26c9 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "installer_test_case" class TestGemInstaller < Gem::InstallerTestCase @@ -83,7 +84,7 @@ end assert_path_exist installed_exec wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_check_executable_overwrite_default_bin_dir @@ -99,8 +100,8 @@ end end conflicted = File.join @gemhome, "bin", "executable" - assert_match %r{\A"executable" from a conflicts with (?:#{Regexp.quote(conflicted)}|installed executable from conflict)\z}, - e.message + assert_match(/\A"executable" from a conflicts with (?:#{Regexp.quote(conflicted)}|installed executable from conflict)\z/, + e.message) end end end @@ -141,7 +142,7 @@ gem 'other', version assert_path_exist installed_exec wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) ensure Gem::Installer.exec_format = nil end @@ -176,7 +177,7 @@ gem 'other', version assert_path_exist installed_exec wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_check_executable_overwrite_other_non_gem @@ -191,7 +192,7 @@ gem 'other', version assert_path_exist installed_exec wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end unless Gem.win_platform? def test_check_that_user_bin_dir_is_in_path @@ -203,8 +204,8 @@ gem 'other', version bin_dir = bin_dir.downcase end - orig_PATH, ENV["PATH"] = - ENV["PATH"], [ENV["PATH"], bin_dir].join(File::PATH_SEPARATOR) + orig_path = ENV["PATH"] + ENV["PATH"] = [ENV["PATH"], bin_dir].join(File::PATH_SEPARATOR) use_ui @ui do installer.check_that_user_bin_dir_is_in_path @@ -212,9 +213,9 @@ gem 'other', version assert_empty @ui.error - return unless win_platform? + return unless Gem.win_platform? - ENV["PATH"] = [orig_PATH, bin_dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)].join(File::PATH_SEPARATOR) + ENV["PATH"] = [orig_path, bin_dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)].join(File::PATH_SEPARATOR) use_ui @ui do installer.check_that_user_bin_dir_is_in_path @@ -222,14 +223,14 @@ gem 'other', version assert_empty @ui.error ensure - ENV["PATH"] = orig_PATH + ENV["PATH"] = orig_path end def test_check_that_user_bin_dir_is_in_path_tilde - pend "Tilde is PATH is not supported under MS Windows" if win_platform? + pend "Tilde is PATH is not supported under MS Windows" if Gem.win_platform? - orig_PATH, ENV["PATH"] = - ENV["PATH"], [ENV["PATH"], "~/bin"].join(File::PATH_SEPARATOR) + orig_path = ENV["PATH"] + ENV["PATH"] = [ENV["PATH"], "~/bin"].join(File::PATH_SEPARATOR) installer = setup_base_installer installer.bin_dir.replace File.join @userhome, "bin" @@ -240,7 +241,7 @@ gem 'other', version assert_empty @ui.error ensure - ENV["PATH"] = orig_PATH unless win_platform? + ENV["PATH"] = orig_path unless Gem.win_platform? end def test_check_that_user_bin_dir_is_in_path_not_in_path @@ -286,7 +287,7 @@ gem 'other', version installer.ensure_loadable_spec end - assert_equal "The specification for #{a.full_name} is corrupt " + + assert_equal "The specification for #{a.full_name} is corrupt " \ "(SyntaxError)", e.message end @@ -298,7 +299,7 @@ gem 'other', version end policy = Gem::Security::HighSecurity - installer = Gem::Installer.at a_gem, :security_policy => policy + installer = Gem::Installer.at a_gem, security_policy: policy assert_raise Gem::Security::Exception do installer.ensure_loadable_spec @@ -334,22 +335,25 @@ gem 'other', version assert_directory_exists util_inst_bindir installed_exec = File.join(util_inst_bindir, "executable") assert_path_exist installed_exec - assert_equal mask, File.stat(installed_exec).mode unless win_platform? + assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform? wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_generate_bin_bindir_with_user_install_warning - bin_dir = Gem.win_platform? ? File.expand_path(ENV["WINDIR"]).upcase : - "/usr/bin" + bin_dir = if Gem.win_platform? + File.expand_path(ENV["WINDIR"]).upcase + else + "/usr/bin" + end old_path = ENV["PATH"] ENV["PATH"] = [ENV["PATH"], bin_dir].compact.join(File::PATH_SEPARATOR) options = { - :bin_dir => bin_dir, - :install_dir => "/non/existent", + bin_dir: bin_dir, + install_dir: "/non/existent", } inst = Gem::Installer.at "", options @@ -361,7 +365,6 @@ gem 'other', version end assert_equal "", @ui.error - ensure ENV["PATH"] = old_path end @@ -377,10 +380,10 @@ gem 'other', version assert_directory_exists util_inst_bindir installed_exec = File.join util_inst_bindir, "executable" assert_path_exist installed_exec - assert_equal mask, File.stat(installed_exec).mode unless win_platform? + assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform? wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_generate_bin_script_format @@ -436,10 +439,10 @@ gem 'other', version installed_exec = File.join("#{@gemhome}2", "bin", "executable") assert_path_exist installed_exec - assert_equal mask, File.stat(installed_exec).mode unless win_platform? + assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform? wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_generate_bin_script_no_execs @@ -461,19 +464,19 @@ gem 'other', version Dir.mkdir util_inst_bindir - if win_platform? + if Gem.win_platform? pend("test_generate_bin_script_no_perms skipped on MS Windows") elsif Process.uid.zero? pend("test_generate_bin_script_no_perms skipped in root privilege") else - FileUtils.chmod 0000, util_inst_bindir + FileUtils.chmod 0o000, util_inst_bindir assert_raise Gem::FilePermissionError do installer.generate_bin end end ensure - FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG || win_platform?) + FileUtils.chmod 0o755, util_inst_bindir unless $DEBUG || Gem.win_platform? end def test_generate_bin_script_no_shebang @@ -493,12 +496,12 @@ gem 'other', version installed_exec = File.join @gemhome, "bin", "executable" assert_path_exist installed_exec - assert_equal mask, File.stat(installed_exec).mode unless win_platform? + assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform? wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper - # HACK some gems don't have #! in their executables, restore 2008/06 - #assert_no_match %r|generated by RubyGems|, wrapper + assert_match(/generated by RubyGems/, wrapper) + # HACK: some gems don't have #! in their executables, restore 2008/06 + # assert_no_match %r|generated by RubyGems|, wrapper end def test_generate_bin_script_wrappers @@ -520,12 +523,12 @@ gem 'other', version installer.generate_bin assert_directory_exists util_inst_bindir assert_path_exist installed_exec - assert_equal mask, File.stat(installed_exec).mode unless win_platform? + assert_equal mask, File.stat(installed_exec).mode unless Gem.win_platform? - assert_match %r{generated by RubyGems}, File.read(installed_exec) + assert_match(/generated by RubyGems/, File.read(installed_exec)) - refute_match %r{generated by RubyGems}, File.read(real_exec), - "real executable overwritten" + refute_match(/generated by RubyGems/, File.read(real_exec), + "real executable overwritten") end def test_generate_bin_symlink @@ -565,19 +568,19 @@ gem 'other', version Dir.mkdir util_inst_bindir - if win_platform? + if Gem.win_platform? pend("test_generate_bin_symlink_no_perms skipped on MS Windows") elsif Process.uid.zero? pend("test_user_install_disabled_read_only test skipped in root privilege") else - FileUtils.chmod 0000, util_inst_bindir + FileUtils.chmod 0o000, util_inst_bindir assert_raise Gem::FilePermissionError do installer.generate_bin end end ensure - FileUtils.chmod 0755, util_inst_bindir unless ($DEBUG || win_platform?) + FileUtils.chmod 0o755, util_inst_bindir unless $DEBUG || Gem.win_platform? end def test_generate_bin_symlink_update_newer @@ -735,9 +738,9 @@ gem 'other', version installer.generate_bin default_shebang = Gem.ruby - shebang_line = File.open("#{@gemhome}/bin/executable") {|f| f.readlines.first } + shebang_line = File.open("#{@gemhome}/bin/executable", &:gets) assert_match(/\A#!/, shebang_line) - assert_match(/#{default_shebang}/, shebang_line) + assert_include(shebang_line, default_shebang) end end @@ -746,8 +749,8 @@ gem 'other', version installer = Gem::Installer.at( gem_with_dangling_symlink, - :user_install => false, - :force => true + user_install: false, + force: true ) build_rake_in do @@ -766,7 +769,7 @@ gem 'other', version def test_generate_plugins installer = util_setup_installer do |spec| write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io| - io.write "puts __FILE__" + io.write "# do nothing" end spec.files += %w[lib/rubygems_plugin.rb] @@ -815,10 +818,10 @@ gem 'other', version util_build_gem spec - File.chmod(0555, Gem.plugindir) + File.chmod(0o555, Gem.plugindir) system_path = File.join(Gem.plugindir, "a_plugin.rb") user_path = File.join(Gem.plugindir(Gem.user_dir), "a_plugin.rb") - installer = util_installer spec, Gem.dir, :user + installer = Gem::Installer.at spec.cache_file, user_install: true, force: true assert_equal spec, installer.install @@ -837,13 +840,13 @@ gem 'other', version util_build_gem spec - File.chmod(0555, Gem.plugindir) + File.chmod(0o555, Gem.plugindir) system_path = File.join(Gem.plugindir, "a_plugin.rb") build_root = File.join(@tempdir, "build_root") build_root_path = File.join(build_root, Gem.plugindir.gsub(/^[a-zA-Z]:/, ""), "a_plugin.rb") - installer = Gem::Installer.at spec.cache_file, :build_root => build_root + installer = Gem::Installer.at spec.cache_file, build_root: build_root assert_equal spec, installer.install @@ -853,11 +856,59 @@ gem 'other', version refute_includes File.read(build_root_path), build_root end + class << self + attr_accessor :plugin_loaded + attr_accessor :post_install_is_called + end + + def test_use_plugin_immediately + self.class.plugin_loaded = false + self.class.post_install_is_called = false + spec_version = nil + plugin_path = nil + installer = util_setup_installer do |spec| + spec_version = spec.version + plugin_path = File.join("lib", "rubygems_plugin.rb") + write_file File.join(@tempdir, plugin_path) do |io| + io.write <<-PLUGIN +#{self.class}.plugin_loaded = true +Gem.post_install do + #{self.class}.post_install_is_called = true +end + PLUGIN + end + spec.files += [plugin_path] + plugin_path = File.join(spec.gem_dir, plugin_path) + end + build_rake_in do + installer.install + end + assert self.class.plugin_loaded, "plugin is not loaded" + assert self.class.post_install_is_called, + "post install hook registered by plugin is not called" + + self.class.plugin_loaded = false + $LOADED_FEATURES.delete(plugin_path) + installer_new = util_setup_installer do |spec_new| + spec_new.version = spec_version.version.succ + plugin_path = File.join("lib", "rubygems_plugin.rb") + write_file File.join(@tempdir, plugin_path) do |io| + io.write "#{self.class}.plugin_loaded = true" + end + spec_new.files += [plugin_path] + end + build_rake_in do + installer_new.install + end + assert !self.class.plugin_loaded, + "plugin is loaded even when old version is already loaded" + end + def test_keeps_plugins_up_to_date # NOTE: version a-2 is already installed by setup hooks write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io| - io.write "puts __FILE__" + io.write "# do nothing" end build_rake_in do @@ -902,7 +953,7 @@ gem 'other', version path = Gem::Package.build @spec - installer = Gem::Installer.at path, :install_dir => "#{@gemhome}3" + installer = Gem::Installer.at path, install_dir: "#{@gemhome}3" assert_equal @spec, installer.install end @@ -926,7 +977,7 @@ gem 'other', version def test_initialize_user_install @gem = setup_base_gem - installer = Gem::Installer.at @gem, :user_install => true + installer = Gem::Installer.at @gem, user_install: true assert_equal File.join(Gem.user_dir, "gems", @spec.full_name), installer.gem_dir @@ -937,13 +988,26 @@ gem 'other', version @gem = setup_base_gem installer = - Gem::Installer.at @gem, :user_install => true, :bin_dir => @tempdir + Gem::Installer.at @gem, user_install: true, bin_dir: @tempdir assert_equal File.join(Gem.user_dir, "gems", @spec.full_name), installer.gem_dir assert_equal @tempdir, installer.bin_dir end + def test_install_dir_takes_precedence_to_user_install + gemhome2 = "#{@gemhome}2" + + @gem = setup_base_gem + + installer = + Gem::Installer.at @gem, install_dir: gemhome2, user_install: true + installer.install + + assert_path_exist File.join(gemhome2, "gems", @spec.full_name) + assert_path_not_exist File.join(Gem.user_dir, "gems", @spec.full_name) + end + def test_install installer = util_setup_installer @@ -983,8 +1047,8 @@ gem 'other', version exe = File.join gemdir, "bin", "executable" assert_path_exist exe - exe_mode = File.stat(exe).mode & 0111 - assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform? + exe_mode = File.stat(exe).mode & 0o111 + assert_equal 0o111, exe_mode, format("0%o", exe_mode) unless Gem.win_platform? assert_path_exist File.join gemdir, "lib", "code.rb" @@ -1025,7 +1089,7 @@ gem 'other', version @gem = setup_base_gem # build old version that has a bin file - installer = util_setup_gem do |spec| + installer = util_setup_gem do |_spec| File.open File.join("bin", "executable"), "w" do |f| f.puts "require 'code'" end @@ -1186,7 +1250,7 @@ gem 'other', version Gem::Package.build @spec end end - installer = Gem::Installer.at @gem, :force => true + installer = Gem::Installer.at @gem, force: true build_rake_in do use_ui @ui do assert_equal @spec, installer.install @@ -1204,7 +1268,7 @@ gem 'other', version end use_ui @ui do - installer = Gem::Installer.at missing_dep_gem, :force => true + installer = Gem::Installer.at missing_dep_gem, force: true installer.install end @@ -1216,11 +1280,31 @@ gem 'other', version build_root = File.join(@tempdir, "build_root") @gem = setup_base_gem - installer = Gem::Installer.at @gem, :build_root => build_root + installer = Gem::Installer.at @gem, build_root: build_root assert_equal @spec, installer.install end + def test_install_build_root_when_gem_home_not_writable_does_not_fallback_to_user_install_inside_build_root + build_root = File.join(@tempdir, "build_root") + + orig_gem_home = ENV.delete("GEM_HOME") + + @gem = setup_base_gem + + FileUtils.chmod "-w", @gemhome + + installer = Gem::Installer.at @gem, build_root: build_root + + assert_equal @spec, installer.install + + build_root_path = File.join(build_root, @gemhome.gsub(/^[a-zA-Z]:/, "")) + assert File.exist?(build_root_path), "gem not written to build_root" + ensure + FileUtils.chmod "+w", @gemhome + ENV["GEM_HOME"] = orig_gem_home + end + def test_install_missing_dirs installer = setup_base_installer @@ -1335,7 +1419,7 @@ gem 'other', version installer.install end - assert_match %r{I am a shiny gem!}, @ui.output + assert_match(/I am a shiny gem!/, @ui.output) end def test_install_with_skipped_message @@ -1345,11 +1429,11 @@ gem 'other', version use_ui @ui do path = Gem::Package.build @spec - installer = Gem::Installer.at path, :post_install_message => false + installer = Gem::Installer.at path, post_install_message: false installer.install end - refute_match %r{I am a shiny gem!}, @ui.output + refute_match(/I am a shiny gem!/, @ui.output) end def test_install_extension_dir @@ -1369,7 +1453,7 @@ gem 'other', version use_ui @ui do path = Gem::Package.build @spec - installer = Gem::Installer.at path, :install_dir => gemhome2 + installer = Gem::Installer.at path, install_dir: gemhome2 installer.install end @@ -1408,7 +1492,7 @@ gem 'other', version # reinstall the gem, this is also the same as pristine use_ui @ui do - installer = Gem::Installer.at path, :force => true + installer = Gem::Installer.at path, force: true installer.install end @@ -1434,7 +1518,7 @@ gem 'other', version use_ui @ui do path = Gem::Package.build @spec - installer = Gem::Installer.at path, :user_install => true + installer = Gem::Installer.at path, user_install: true installer.install end @@ -1493,7 +1577,7 @@ gem 'other', version def test_install_extension_and_script pend "Makefile creation crashes on jruby" if Gem.java_platform? - pend if RUBY_PLATFORM.include?("mswin") && ENV.key?("GITHUB_ACTIONS") # not working from the beginning + pend "terminates on mswin" if vc_windows? && ruby_repo? @spec = setup_base_spec @spec.extensions << "extconf.rb" @@ -1559,7 +1643,7 @@ gem 'other', version write_file File.join(@tempdir, file) end - so = File.join(@spec.gem_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}") + so = File.join(@spec.extension_dir, "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}") assert_path_not_exist so use_ui @ui do path = Gem::Package.build @spec @@ -1568,20 +1652,42 @@ gem 'other', version installer.install end assert_path_exist so - rescue - puts "-" * 78 - puts File.read File.join(@gemhome, "gems", "a-2", "Makefile") - puts "-" * 78 + end + end - path = File.join(@gemhome, "gems", "a-2", "gem_make.out") + def test_install_extension_clean_intermediate_files + pend "extensions don't quite work on jruby" if Gem.java_platform? + @spec = setup_base_spec + @spec.require_paths = ["."] + @spec.extensions << "extconf.rb" - if File.exist?(path) - puts File.read(path) - puts "-" * 78 - end + File.write File.join(@tempdir, "extconf.rb"), <<-RUBY + require "mkmf" + CONFIG['CC'] = '$(TOUCH) $@ ||' + CONFIG['LDSHARED'] = '$(TOUCH) $@ ||' + $ruby = '#{Gem.ruby}' + create_makefile("#{@spec.name}") + RUBY + + # empty depend file for no auto dependencies + @spec.files += %W[depend #{@spec.name}.c].each do |file| + write_file File.join(@tempdir, file) + end + + shared_object = "#{@spec.name}.#{RbConfig::CONFIG["DLEXT"]}" + extension_file = File.join @spec.extension_dir, shared_object + intermediate_file = File.join @spec.gem_dir, shared_object + + assert_path_not_exist extension_file, "no before installing" + use_ui @ui do + path = Gem::Package.build @spec - raise + installer = Gem::Installer.at path + installer.install end + + assert_path_exist extension_file, "installed" + assert_path_not_exist intermediate_file end def test_installation_satisfies_dependency_eh @@ -1651,7 +1757,7 @@ gem 'other', version # that it work everything out on it's own. Gem::Specification.reset - installer = Gem::Installer.at gem, :install_dir => gemhome2 + installer = Gem::Installer.at gem, install_dir: gemhome2 build_rake_in do use_ui @ui do @@ -1665,6 +1771,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(packaging, strict); end util_build_gem spec @@ -1685,6 +1792,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(*args); end util_build_gem spec @@ -1706,6 +1814,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(*args); end spec.require_paths = ["malicious\n``"] @@ -1729,6 +1838,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(*args); end spec.extensions = ["malicious\n``"] @@ -1750,6 +1860,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(*args); end spec.specification_version = "malicious\n``" @@ -1771,6 +1882,7 @@ gem 'other', version def spec.full_name # so the spec is buildable "malicious-1" end + def spec.validate(*args); end spec.add_dependency "b\nfoo", "> 5" @@ -1793,9 +1905,9 @@ gem 'other', version installer = Gem::Installer.at( gem_with_ill_formated_platform, - :install_dir => @gem_home, - :user_install => false, - :force => true + install_dir: @gemhome, + user_install: false, + force: true ) use_ui @ui do @@ -1835,7 +1947,7 @@ gem 'other', version plugins_dir = File.join(build_root, @gemhome.gsub(/^[a-zA-Z]:/, ""), "plugins") @gem = setup_base_gem - installer = use_ui(@ui) { Gem::Installer.at @gem, :build_root => build_root } + installer = use_ui(@ui) { Gem::Installer.at @gem, build_root: build_root } assert_equal build_root, installer.build_root assert_equal bin_dir, installer.bin_dir @@ -1850,6 +1962,48 @@ gem 'other', version assert_equal " Plugins dir: #{plugins_dir}", errors.shift end + def test_process_options_fallback_to_user_install_when_gem_home_not_writable + if Process.uid.zero? + pend("skipped in root privilege") + return + end + + orig_gem_home = ENV.delete("GEM_HOME") + + @gem = setup_base_gem + + FileUtils.chmod 0o000, @gemhome + + installer = use_ui(@ui) { Gem::Installer.at @gem } + + assert_equal Gem.user_dir, installer.gem_home + assert_equal "Defaulting to user installation because default installation directory (#{@gemhome}) is not writable.", @ui.output.strip + ensure + FileUtils.chmod 0o755, @gemhome + ENV["GEM_HOME"] = orig_gem_home + end + + def test_process_options_does_not_fallback_to_user_install_when_gem_home_not_writable_and_no_user_install + if Process.uid.zero? + pend("skipped in root privilege") + return + end + + orig_gem_home = ENV.delete("GEM_HOME") + + @gem = setup_base_gem + + FileUtils.chmod 0o000, @gemhome + + installer = use_ui(@ui) { Gem::Installer.at @gem, user_install: false } + + assert_equal @gemhome, installer.gem_home + assert_empty @ui.output.strip + ensure + FileUtils.chmod 0o755, @gemhome + ENV["GEM_HOME"] = orig_gem_home + end + def test_shebang_arguments load_relative "no" do installer = setup_base_installer @@ -1937,7 +2091,7 @@ gem 'other', version bin_env = get_bin_env - assert_equal("#!#{bin_env} #{RbConfig::CONFIG['ruby_install_name']}", + assert_equal("#!#{bin_env} #{RbConfig::CONFIG["ruby_install_name"]}", shebang) end @@ -2074,7 +2228,7 @@ gem 'other', version end def get_bin_env - if win_platform? + if Gem.win_platform? "" else %w[/usr/bin/env /bin/env].find {|f| File.executable?(f) } @@ -2156,7 +2310,7 @@ gem 'other', version def test_write_build_info_file_install_dir @gem = setup_base_gem - installer = Gem::Installer.at @gem, :install_dir => "#{@gemhome}2" + installer = Gem::Installer.at @gem, install_dir: "#{@gemhome}2" installer.build_args = %w[ --with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4 @@ -2222,6 +2376,37 @@ gem 'other', version assert_equal @spec, eval(File.read(@spec.spec_file)) end + def test_leaves_no_empty_cached_spec_when_no_more_disk_space + @spec = setup_base_spec + FileUtils.rm @spec.spec_file + assert_path_not_exist @spec.spec_file + + @spec.files = %w[a.rb b.rb c.rb] + + installer = Gem::Installer.for_spec @spec + installer.gem_home = @gemhome + + File.class_eval do + alias_method :original_write, :write + + def write(data) + raise Errno::ENOSPC + end + end + + assert_raise Errno::ENOSPC do + installer.write_spec + end + + assert_path_not_exist @spec.spec_file + ensure + File.class_eval do + remove_method :write + alias_method :write, :original_write + remove_method :original_write + end + end + def test_dir installer = setup_base_installer @@ -2230,7 +2415,7 @@ gem 'other', version def test_default_gem_loaded_from spec = util_spec "a" - installer = Gem::Installer.for_spec spec, :install_as_default => true + installer = Gem::Installer.for_spec spec, install_as_default: true installer.install assert_predicate spec, :default_gem? end @@ -2267,10 +2452,10 @@ gem 'other', version wrapper = File.read installed_exec if symlink_supported? - refute_match %r{generated by RubyGems}, wrapper + refute_match(/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 + assert_match(/Unable to use symlinks, installing wrapper/, @ui.error) + assert_match(/generated by RubyGems/, wrapper) end end @@ -2291,7 +2476,7 @@ gem 'other', version assert_path_exist installed_exec wrapper = File.read installed_exec - assert_match %r{generated by RubyGems}, wrapper + assert_match(/generated by RubyGems/, wrapper) end def test_default_gem_with_exe_as_bindir @@ -2383,15 +2568,15 @@ gem 'other', version end def mask - 0100755 + 0o100755 end def load_relative(value) - orig_LIBRUBY_RELATIVE = RbConfig::CONFIG["LIBRUBY_RELATIVE"] + orig_libruby_relative = RbConfig::CONFIG["LIBRUBY_RELATIVE"] RbConfig::CONFIG["LIBRUBY_RELATIVE"] = value yield ensure - RbConfig::CONFIG["LIBRUBY_RELATIVE"] = orig_LIBRUBY_RELATIVE + RbConfig::CONFIG["LIBRUBY_RELATIVE"] = orig_libruby_relative end end |