From 96064e6f1ce100a37680dc8f9509f06b3350e9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 24 Mar 2020 07:39:24 +0100 Subject: Sync rubygems with current master (#2889) --- test/rubygems/test_gem_installer.rb | 64 +++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'test/rubygems/test_gem_installer.rb') diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 29458dbd4e..9f531d4258 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -757,7 +757,7 @@ gem 'other', version installer.install end - plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb' + plugin_path = File.join Gem.plugindir, 'a_plugin.rb' FileUtils.rm plugin_path @@ -766,6 +766,25 @@ gem 'other', version assert File.exist?(plugin_path), 'plugin not written' end + def test_generate_plugins_with_install_dir + spec = quick_gem 'a' do |spec| + write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io| + io.write "puts __FILE__" + end + + spec.files += %w[lib/rubygems_plugin.rb] + end + + util_build_gem spec + + plugin_path = File.join "#{@gemhome}2", 'plugins', 'a_plugin.rb' + installer = util_installer spec, "#{@gemhome}2" + + assert_equal spec, installer.install + + assert File.exist?(plugin_path), 'plugin not written to install_dir' + end + def test_keeps_plugins_up_to_date # NOTE: version a-2 is already installed by setup hooks @@ -779,7 +798,7 @@ gem 'other', version spec.files += %w[lib/rubygems_plugin.rb] end.install - plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb' + plugin_path = File.join Gem.plugindir, 'a_plugin.rb' refute File.exist?(plugin_path), 'old version installed while newer version without plugin also installed, but plugin written' util_setup_installer do |spec| @@ -787,7 +806,7 @@ gem 'other', version spec.files += %w[lib/rubygems_plugin.rb] end.install - plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb' + plugin_path = File.join Gem.plugindir, 'a_plugin.rb' assert File.exist?(plugin_path), 'latest version reinstalled, but plugin not written' assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content' @@ -796,7 +815,7 @@ gem 'other', version spec.files += %w[lib/rubygems_plugin.rb] end.install - plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb' + plugin_path = File.join Gem.plugindir, 'a_plugin.rb' assert File.exist?(plugin_path), 'latest version installed, but plugin removed' assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), 'written plugin has incorrect content' @@ -808,6 +827,17 @@ gem 'other', version end end + def test_generates_plugins_dir_under_install_dir_if_not_there + Gem.use_paths "#{@gemhome}2" # Set GEM_HOME to an uninitialized repo + + @spec = util_spec 'a' + + path = Gem::Package.build @spec + + installer = Gem::Installer.at path, :install_dir => "#{@gemhome}3" + assert_equal @spec, installer.install + end + def test_initialize spec = util_spec 'a' do |s| s.platform = Gem::Platform.new 'mswin32' @@ -1794,9 +1824,9 @@ gem 'other', version shebang = installer.shebang 'executable' - bin_env = get_bin_env + env_shebang = "/usr/bin/env" unless Gem.win_platform? - assert_equal("#!#{bin_env} #{RbConfig::CONFIG['ruby_install_name']}", + assert_equal("#!#{env_shebang} #{RbConfig::CONFIG['ruby_install_name']}", shebang) end @@ -1875,18 +1905,10 @@ gem 'other', version assert_equal "#!test", shebang end - def get_bin_env - if win_platform? - "" - else - %w(/usr/bin/env /bin/env).find {|f| File.executable?(f) } - end - end - def test_shebang_custom_with_expands installer = setup_base_installer - bin_env = get_bin_env + bin_env = win_platform? ? '' : '/usr/bin/env' conf = Gem::ConfigFile.new [] conf[:custom_shebang] = '1 $env 2 $ruby 3 $exec 4 $name' @@ -1902,7 +1924,7 @@ gem 'other', version def test_shebang_custom_with_expands_and_arguments installer = setup_base_installer - bin_env = get_bin_env + bin_env = win_platform? ? '' : '/usr/bin/env' conf = Gem::ConfigFile.new [] conf[:custom_shebang] = '1 $env 2 $ruby 3 $exec' @@ -2130,6 +2152,16 @@ gem 'other', version assert_kind_of(Gem::Package, installer.package) end + def test_gem_attribute + gem = quick_gem 'c' do |spec| + util_make_exec spec, '#!/usr/bin/ruby', 'exe' + end + + installer = util_installer(gem, @gemhome) + assert_respond_to(installer, :gem) + assert_kind_of(String, installer.gem) + end + def old_ruby_required(requirement) spec = util_spec 'old_ruby_required', '1' do |s| s.required_ruby_version = requirement -- cgit v1.2.1