summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2020-03-24 07:39:24 +0100
committerGitHub <noreply@github.com>2020-03-24 15:39:24 +0900
commit96064e6f1ce100a37680dc8f9509f06b3350e9c8 (patch)
tree798b59f015cb82ee3cd0427f80584032175829ba /test
parent930b012ad96bfb0bd12446b89407120744ef92eb (diff)
Sync rubygems with current master (#2889)
Notes
Notes: Merged-By: hsbt <hsbt@ruby-lang.org>
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/test_gem.rb49
-rw-r--r--test/rubygems/test_gem_bundler_version_finder.rb17
-rw-r--r--test/rubygems/test_gem_commands_contents_command.rb33
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb8
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb28
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb12
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb248
-rw-r--r--test/rubygems/test_gem_doctor.rb4
-rw-r--r--test/rubygems/test_gem_gem_runner.rb2
-rw-r--r--test/rubygems/test_gem_installer.rb64
-rw-r--r--test/rubygems/test_gem_package.rb11
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb5
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb2
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb11
-rw-r--r--test/rubygems/test_gem_specification.rb5
-rw-r--r--test/rubygems/test_gem_uninstaller.rb26
-rw-r--r--test/rubygems/test_require.rb74
17 files changed, 289 insertions, 310 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 2890e13dfb..fd9b3609f2 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -1016,16 +1016,16 @@ class TestGem < Gem::TestCase
end
def test_self_ruby_escaping_spaces_in_path
- with_bindir_and_exeext("C:/Ruby 1.8/bin", ".exe") do
- ruby_install_name "ruby" do
+ with_clean_path_to_ruby do
+ with_rb_config_ruby("C:/Ruby 1.8/bin/ruby.exe") do
assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby
end
end
end
def test_self_ruby_path_without_spaces
- with_bindir_and_exeext("C:/Ruby18/bin", ".exe") do
- ruby_install_name "ruby" do
+ with_clean_path_to_ruby do
+ with_rb_config_ruby("C:/Ruby18/bin/ruby.exe") do
assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby
end
end
@@ -1906,6 +1906,24 @@ You may need to `gem install -g` to install missing gems
assert platform_defaults.is_a? Hash
end
+ # Ensure that `Gem.source_date_epoch` is consistent even if
+ # $SOURCE_DATE_EPOCH has not been set.
+ def test_default_source_date_epoch_doesnt_change
+ old_epoch = ENV['SOURCE_DATE_EPOCH']
+ ENV['SOURCE_DATE_EPOCH'] = nil
+
+ # Unfortunately, there is no real way to test this aside from waiting
+ # enough for `Time.now.to_i` to change -- which is a whole second.
+ #
+ # Fortunately, we only need to do this once.
+ a = Gem.source_date_epoch
+ sleep 1
+ b = Gem.source_date_epoch
+ assert_equal a, b
+ ensure
+ ENV['SOURCE_DATE_EPOCH'] = old_epoch
+ end
+
def ruby_install_name(name)
with_clean_path_to_ruby do
orig_RUBY_INSTALL_NAME = RbConfig::CONFIG['ruby_install_name']
@@ -1923,11 +1941,24 @@ You may need to `gem install -g` to install missing gems
end
end
- def with_bindir_and_exeext(bindir, exeext)
- bindir(bindir) do
- exeext(exeext) do
- yield
- end
+ def with_rb_config_ruby(path)
+ rb_config_singleton_class = class << RbConfig; self; end
+ orig_path = RbConfig.ruby
+
+ redefine_method(rb_config_singleton_class, :ruby, path)
+
+ yield
+ ensure
+ redefine_method(rb_config_singleton_class, :ruby, orig_path)
+ end
+
+ def redefine_method(base, method, new_result)
+ if RUBY_VERSION >= "2.5"
+ base.alias_method(method, method)
+ base.define_method(method) { new_result }
+ else
+ base.send(:alias_method, method, method)
+ base.send(:define_method, method) { new_result }
end
end
diff --git a/test/rubygems/test_gem_bundler_version_finder.rb b/test/rubygems/test_gem_bundler_version_finder.rb
index 34a451b64d..16ff2956f0 100644
--- a/test/rubygems/test_gem_bundler_version_finder.rb
+++ b/test/rubygems/test_gem_bundler_version_finder.rb
@@ -78,6 +78,23 @@ class TestGemBundlerVersionFinder < Gem::TestCase
end
end
+ def test_deleted_directory
+ skip "Cannot perform this test on windows" if win_platform?
+ require "tmpdir"
+
+ orig_dir = Dir.pwd
+
+ begin
+ Dir.mktmpdir("some_dir") do |dir|
+ Dir.chdir(dir)
+ end
+ ensure
+ Dir.chdir(orig_dir)
+ end
+
+ assert_nil bvf.bundler_version_with_reason
+ end
+
def test_compatible
assert bvf.compatible?(util_spec("foo"))
assert bvf.compatible?(util_spec("bundler", 1.1))
diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb
index a8d6efe794..93ebcca5bb 100644
--- a/test/rubygems/test_gem_commands_contents_command.rb
+++ b/test/rubygems/test_gem_commands_contents_command.rb
@@ -105,6 +105,22 @@ class TestGemCommandsContentsCommand < Gem::TestCase
assert_empty @ui.error
end
+ def test_execute_missing_version
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:version] = Gem::Requirement.new '= 2'
+
+ gem 'foo', 1
+
+ assert_raises Gem::MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ assert_match "Unable to find gem 'foo'", @ui.output
+ assert_empty @ui.error
+ end
+
def test_execute_missing_multiple
@cmd.options[:args] = %w[foo bar]
@@ -152,6 +168,23 @@ class TestGemCommandsContentsCommand < Gem::TestCase
assert_equal "", @ui.error
end
+ def test_execute_show_install_dir_latest_version
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:show_install_dir] = true
+
+ gem 'foo', 1
+ gem 'foo', 2
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = File.join @gemhome, 'gems', 'foo-2'
+
+ assert_equal "#{expected}\n", @ui.output
+ assert_equal "", @ui.error
+ end
+
def test_execute_show_install_dir_version
@cmd.options[:args] = %w[foo]
@cmd.options[:show_install_dir] = true
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index c40d32ae61..4ebe1efecb 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -160,9 +160,11 @@ class TestGemCommandsPristineCommand < Gem::TestCase
ruby_exec = sprintf Gem.default_exec_format, 'ruby'
- bin_env = win_platform? ? "" : %w(/usr/bin/env /bin/env).find {|f| File.executable?(f) }
-
- assert_match %r%\A#!\s*#{bin_env} #{ruby_exec}%, File.read(gem_exec)
+ if win_platform?
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(gem_exec)
+ else
+ assert_match %r%\A#!\s*/usr/bin/env #{ruby_exec}%, File.read(gem_exec)
+ end
end
def test_execute_extensions_explicit
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index d2e04d760b..30daa82d61 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -107,7 +107,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
install_gem gem
- File.join Gem.plugins_dir, "#{name}_plugin.rb"
+ File.join Gem.plugindir, "#{name}_plugin.rb"
end
def test_execute_regenerate_binstubs
@@ -160,6 +160,18 @@ class TestGemCommandsSetupCommand < Gem::TestCase
assert_equal "I changed it!\n", File.read(gem_plugin_path)
end
+ def test_execute_regenerate_plugins_creates_plugins_dir_if_not_there
+ gem_plugin_path = gem_install_with_plugin 'a'
+
+ # Simulate gem installed with an older rubygems without a plugins layout
+ FileUtils.rm_rf Gem.plugindir
+
+ @cmd.options[:document] = []
+ @cmd.execute
+
+ assert_match %r{\Arequire}, File.read(gem_plugin_path)
+ end
+
def test_execute_informs_about_installed_executables
use_ui @ui do
@cmd.execute
@@ -184,11 +196,15 @@ class TestGemCommandsSetupCommand < Gem::TestCase
ruby_exec = sprintf Gem.default_exec_format, 'ruby'
- bin_env = win_platform? ? "" : %w(/usr/bin/env /bin/env).find {|f| File.executable?(f) }
-
- assert_match %r%\A#!#{bin_env}\s*#{ruby_exec}%, File.read(default_gem_bin_path)
- assert_match %r%\A#!#{bin_env}\s*#{ruby_exec}%, File.read(default_bundle_bin_path)
- assert_match %r%\A#!#{bin_env}\s*#{ruby_exec}%, File.read(gem_bin_path)
+ if Gem.win_platform?
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_gem_bin_path)
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(default_bundle_bin_path)
+ assert_match %r%\A#!\s*#{ruby_exec}%, File.read(gem_bin_path)
+ else
+ assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_gem_bin_path)
+ assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(default_bundle_bin_path)
+ assert_match %r%\A#!/usr/bin/env #{ruby_exec}%, File.read(gem_bin_path)
+ end
end
def test_pem_files_in
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 340c658b9d..efaa621634 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -169,12 +169,12 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = "3.1"
- FileUtils.mkdir_p Gem.plugins_dir
- write_file File.join(Gem.plugins_dir, 'a_plugin.rb')
+ FileUtils.mkdir_p Gem.plugindir
+ write_file File.join(Gem.plugindir, 'a_plugin.rb')
@cmd.execute
- refute_path_exists Gem.plugins_dir, "Plugins folder not removed when updating rubygems to pre-3.2"
+ refute_path_exists Gem.plugindir, "Plugins folder not removed when updating rubygems to pre-3.2"
end
def test_execute_system_specific_newer_than_or_equal_to_3_2_leaves_plugins_dir_alone
@@ -187,13 +187,13 @@ class TestGemCommandsUpdateCommand < Gem::TestCase
@cmd.options[:args] = []
@cmd.options[:system] = "3.2"
- FileUtils.mkdir_p Gem.plugins_dir
- plugin_file = File.join(Gem.plugins_dir, 'a_plugin.rb')
+ FileUtils.mkdir_p Gem.plugindir
+ plugin_file = File.join(Gem.plugindir, 'a_plugin.rb')
write_file plugin_file
@cmd.execute
- assert_path_exists Gem.plugins_dir, "Plugin folder removed when updating rubygems to post-3.2"
+ assert_path_exists Gem.plugindir, "Plugin folder removed when updating rubygems to post-3.2"
assert_path_exists plugin_file, "Plugin removed when updating rubygems to post-3.2"
end
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 487b8290bb..67fdd6bde6 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -48,69 +48,6 @@ class TestGemDependencyInstaller < Gem::TestCase
util_reset_gems
end
- def test_available_set_for_name
- util_setup_gems
- p1a, = util_gem 'a', '10.a'
- util_setup_spec_fetcher p1a, @a1, @a1_pre
-
- inst = Gem::DependencyInstaller.new
-
- available = Gem::Deprecate.skip_during do
- inst.available_set_for 'a', Gem::Requirement.default
- end
-
- assert_equal %w[a-1], available.set.map { |s| s.spec.full_name }
- end
-
- def test_available_set_for_name_prerelease
- util_setup_gems
- p1a, = util_gem 'a', '10.a'
- util_setup_spec_fetcher p1a, @a1, @a1_pre
-
- inst = Gem::DependencyInstaller.new :prerelease => true
-
- available = Gem::Deprecate.skip_during do
- inst.available_set_for 'a', Gem::Requirement.default
- end
-
- assert_equal %w[a-10.a],
- available.sorted.map { |s| s.spec.full_name }
- end
-
- def test_available_set_for_dep
- util_setup_gems
- p1a, = util_gem 'a', '10.a'
- util_setup_spec_fetcher p1a, @a1, @a1_pre
-
- inst = Gem::DependencyInstaller.new
-
- dep = Gem::Dependency.new 'a', Gem::Requirement.default
-
- available = Gem::Deprecate.skip_during do
- inst.available_set_for dep, Gem::Requirement.default
- end
-
- assert_equal %w[a-1], available.set.map { |s| s.spec.full_name }
- end
-
- def test_available_set_for_dep_prerelease
- util_setup_gems
- p1a, = util_gem 'a', '10.a'
- util_setup_spec_fetcher p1a, @a1, @a1_pre
-
- inst = Gem::DependencyInstaller.new :prerelease => true
-
- dep = Gem::Dependency.new 'a', Gem::Requirement.default
- dep.prerelease = true
-
- available = Gem::Deprecate.skip_during do
- inst.available_set_for dep, Gem::Requirement.default
- end
-
- assert_equal %w[a-10.a],
- available.sorted.map { |s| s.spec.full_name }
- end
-
def test_install
util_setup_gems
@@ -974,191 +911,6 @@ class TestGemDependencyInstaller < Gem::TestCase
assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name }
end
- def test_find_gems_gems_with_sources
- util_setup_gems
-
- inst = Gem::DependencyInstaller.new
- dep = Gem::Dependency.new 'b', '>= 0'
-
- Gem::Specification.reset
-
- set = Gem::Deprecate.skip_during do
- inst.find_gems_with_sources(dep)
- end
-
- assert_kind_of Gem::AvailableSet, set
-
- s = set.set.first
-
- assert_equal @b1, s.spec
- assert_equal Gem::Source.new(@gem_repo), s.source
- end
-
- def test_find_spec_by_name_and_version_wildcard
- util_gem 'a', 1
- FileUtils.mv 'gems/a-1.gem', @tempdir
-
- FileUtils.touch 'rdoc.gem'
-
- inst = Gem::DependencyInstaller.new
-
- available = Gem::Deprecate.skip_during do
- inst.find_spec_by_name_and_version('*.gem')
- end
-
- assert_equal %w[a-1], available.each_spec.map { |spec| spec.full_name }
- end
-
- def test_find_spec_by_name_and_version_wildcard_bad_gem
- FileUtils.touch 'rdoc.gem'
-
- inst = Gem::DependencyInstaller.new
-
- assert_raises Gem::Package::FormatError do
- Gem::Deprecate.skip_during do
- inst.find_spec_by_name_and_version '*.gem'
- end
- end
- end
-
- def test_find_spec_by_name_and_version_bad_gem
- FileUtils.touch 'rdoc.gem'
-
- inst = Gem::DependencyInstaller.new
-
- e = assert_raises Gem::Package::FormatError do
- Gem::Deprecate.skip_during do
- inst.find_spec_by_name_and_version 'rdoc.gem'
- end
- end
-
- full_path = File.join @tempdir, 'rdoc.gem'
- assert_equal "package metadata is missing in #{full_path}", e.message
- end
-
- def test_find_spec_by_name_and_version_directory
- Dir.mkdir 'rdoc'
-
- inst = Gem::DependencyInstaller.new
-
- e = assert_raises Gem::SpecificGemNotFoundException do
- Gem::Deprecate.skip_during do
- inst.find_spec_by_name_and_version 'rdoc'
- end
- end
-
- assert_equal "Could not find a valid gem 'rdoc' (>= 0) " +
- "locally or in a repository",
- e.message
- end
-
- def test_find_spec_by_name_and_version_file
- FileUtils.touch 'rdoc'
-
- inst = Gem::DependencyInstaller.new
-
- e = assert_raises Gem::SpecificGemNotFoundException do
- Gem::Deprecate.skip_during do
- inst.find_spec_by_name_and_version 'rdoc'
- end
- end
-
- assert_equal "Could not find a valid gem 'rdoc' (>= 0) " +
- "locally or in a repository",
- e.message
- end
-
- def test_find_gems_with_sources_local
- util_setup_gems
-
- FileUtils.mv @a1_gem, @tempdir
- inst = Gem::DependencyInstaller.new
- dep = Gem::Dependency.new 'a', '>= 0'
- set = nil
-
- Dir.chdir @tempdir do
- set = Gem::Deprecate.skip_during do
- inst.find_gems_with_sources dep
- end
- end
-
- gems = set.sorted
-
- assert_equal 2, gems.length
-
- remote, local = gems
-
- assert_equal 'a-1', local.spec.full_name, 'local spec'
- assert_equal File.join(@tempdir, @a1.file_name),
- local.source.download(local.spec), 'local path'
-
- assert_equal 'a-1', remote.spec.full_name, 'remote spec'
- assert_equal Gem::Source.new(@gem_repo), remote.source, 'remote path'
- end
-
- def test_find_gems_with_sources_prerelease
- util_setup_gems
-
- installer = Gem::DependencyInstaller.new
-
- dependency = Gem::Dependency.new('a', Gem::Requirement.default)
-
- set = Gem::Deprecate.skip_during do
- installer.find_gems_with_sources(dependency)
- end
-
- releases = set.all_specs
-
- assert releases.any? { |s| s.name == 'a' and s.version.to_s == '1' }
- refute releases.any? { |s| s.name == 'a' and s.version.to_s == '1.a' }
-
- dependency.prerelease = true
-
- set = Gem::Deprecate.skip_during do
- installer.find_gems_with_sources(dependency)
- end
-
- prereleases = set.all_specs
-
- assert_equal [@a1_pre, @a1], prereleases
- end
-
- def test_find_gems_with_sources_with_best_only_and_platform
- util_setup_gems
- a1_x86_mingw32, = util_gem 'a', '1' do |s|
- s.platform = 'x86-mingw32'
- end
- util_setup_spec_fetcher @a1, a1_x86_mingw32
- Gem.platforms << Gem::Platform.new('x86-mingw32')
-
- installer = Gem::DependencyInstaller.new
-
- dependency = Gem::Dependency.new('a', Gem::Requirement.default)
-
- set = Gem::Deprecate.skip_during do
- installer.find_gems_with_sources(dependency, true)
- end
-
- releases = set.all_specs
-
- assert_equal [a1_x86_mingw32], releases
- end
-
- def test_find_gems_with_sources_with_bad_source
- Gem.sources.replace ["http://not-there.nothing"]
-
- installer = Gem::DependencyInstaller.new
-
- dep = Gem::Dependency.new('a')
-
- out = Gem::Deprecate.skip_during do
- installer.find_gems_with_sources(dep)
- end
-
- assert out.empty?
- assert_kind_of Gem::SourceFetchProblem, installer.errors.first
- end
-
def test_resolve_dependencies
util_setup_gems
diff --git a/test/rubygems/test_gem_doctor.rb b/test/rubygems/test_gem_doctor.rb
index 75d406ac88..8ca4798c93 100644
--- a/test/rubygems/test_gem_doctor.rb
+++ b/test/rubygems/test_gem_doctor.rb
@@ -158,8 +158,8 @@ This directory does not appear to be a RubyGems repository, skipping
Gem.use_paths @gemhome.to_s
- FileUtils.mkdir_p Gem.plugins_dir
- bad_plugin = File.join(Gem.plugins_dir, "a_badly_named_file.rb")
+ FileUtils.mkdir_p Gem.plugindir
+ bad_plugin = File.join(Gem.plugindir, "a_badly_named_file.rb")
write_file bad_plugin
doctor = Gem::Doctor.new @gemhome
diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb
index b700a333f4..5e4eda0516 100644
--- a/test/rubygems/test_gem_gem_runner.rb
+++ b/test/rubygems/test_gem_gem_runner.rb
@@ -8,6 +8,7 @@ class TestGemGemRunner < Gem::TestCase
require 'rubygems/command'
@orig_args = Gem::Command.build_args
+ @orig_specific_extra_args = Gem::Command.specific_extra_args_hash.dup
require 'rubygems/gem_runner'
@runner = Gem::GemRunner.new
@@ -17,6 +18,7 @@ class TestGemGemRunner < Gem::TestCase
super
Gem::Command.build_args = @orig_args
+ Gem::Command.specific_extra_args_hash = @orig_specific_extra_args
end
def test_do_configuration
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
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 5da247e141..64ceda39b2 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -106,7 +106,7 @@ class TestGemPackage < Gem::Package::TarTestCase
assert_equal expected, YAML.load(checksums)
end
- def test_build_time_source_date_epoch
+ def test_build_time_uses_source_date_epoch
epoch = ENV["SOURCE_DATE_EPOCH"]
ENV["SOURCE_DATE_EPOCH"] = "123456789"
@@ -124,12 +124,10 @@ class TestGemPackage < Gem::Package::TarTestCase
ENV["SOURCE_DATE_EPOCH"] = epoch
end
- def test_build_time_source_date_epoch_automatically_set
+ def test_build_time_without_source_date_epoch
epoch = ENV["SOURCE_DATE_EPOCH"]
ENV["SOURCE_DATE_EPOCH"] = nil
- start_time = Time.now.utc.to_i
-
spec = Gem::Specification.new 'build', '1'
spec.summary = 'build'
spec.authors = 'build'
@@ -138,14 +136,11 @@ class TestGemPackage < Gem::Package::TarTestCase
package = Gem::Package.new spec.file_name
- end_time = Time.now.utc.to_i
-
assert_kind_of Time, package.build_time
build_time = package.build_time.to_i
- assert_operator(start_time, :<=, build_time)
- assert_operator(build_time, :<=, end_time)
+ assert_equal Gem.source_date_epoch.to_i, build_time
ensure
ENV["SOURCE_DATE_EPOCH"] = epoch
end
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index 81661da45a..903d681c7e 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -8,6 +8,11 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
def setup
super
+ # Setting `@default_source_date_epoch` to `nil` effectively resets the
+ # value used for `Gem.source_date_epoch` whenever `$SOURCE_DATE_EPOCH`
+ # is not set.
+ Gem.instance_variable_set(:'@default_source_date_epoch', nil)
+
@data = 'abcde12345'
@io = TempIO.new
@tar_writer = Gem::Package::TarWriter.new @io
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index 55278afa4e..4df9180944 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -897,8 +897,6 @@ PeIQQkFng2VVot/WAQbv3ePqWq07g1BBcwIBAg==
end
def test_ssl_client_cert_auth_connection
- skip 'openssl in jruby fails' if java_platform?
-
ssl_server = self.class.start_ssl_server({
:SSLVerifyClient =>
OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT})
diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb
index 99862ce871..5259e62ccc 100644
--- a/test/rubygems/test_gem_spec_fetcher.rb
+++ b/test/rubygems/test_gem_spec_fetcher.rb
@@ -173,10 +173,19 @@ class TestGemSpecFetcher < Gem::TestCase
spec_fetcher do|fetcher|
fetcher.spec 'example', 1
fetcher.spec 'other-example', 1
+ fetcher.spec 'examp', 1
end
- suggestions = @sf.suggest_gems_from_name('examplw')
+ suggestions = @sf.suggest_gems_from_name('examplw', type = :latest, num_results = 1)
assert_equal ['example'], suggestions
+
+ suggestions = @sf.suggest_gems_from_name('other')
+ assert_equal ['other-example'], suggestions
+
+ suggestions = @sf.suggest_gems_from_name('exam')
+ assert suggestions.any? { ['examp'] }
+ assert suggestions.any? { ['example'] }
+ assert suggestions.any? { ['other-example'] }
end
def test_suggest_gems_from_name_prerelease
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index b7df8b71fd..e5833ddfa4 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -83,6 +83,11 @@ end
def setup
super
+ # Setting `@default_source_date_epoch` to `nil` effectively resets the
+ # value used for `Gem.source_date_epoch` whenever `$SOURCE_DATE_EPOCH`
+ # is not set.
+ Gem.instance_variable_set(:'@default_source_date_epoch', nil)
+
@a1 = util_spec 'a', '1' do |s|
s.executable = 'exec'
s.test_file = 'test/suite.rb'
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index df8dfd9a95..fc330a6040 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -178,7 +178,7 @@ class TestGemUninstaller < Gem::InstallerTestCase
Gem::Installer.at(Gem::Package.build(@spec)).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), 'plugin not written'
Gem::Uninstaller.new(nil).remove_plugins @spec
@@ -186,6 +186,24 @@ class TestGemUninstaller < Gem::InstallerTestCase
refute File.exist?(plugin_path), 'plugin not removed'
end
+ def test_remove_plugins_with_install_dir
+ write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
+ io.write "puts __FILE__"
+ end
+
+ @spec.files += %w[lib/rubygems_plugin.rb]
+
+ Gem::Installer.at(Gem::Package.build(@spec)).install
+
+ plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
+ assert File.exist?(plugin_path), 'plugin not written'
+
+ Dir.mkdir "#{@gemhome}2"
+ Gem::Uninstaller.new(nil, :install_dir => "#{@gemhome}2").remove_plugins @spec
+
+ assert File.exist?(plugin_path), 'plugin unintentionally removed'
+ end
+
def test_regenerate_plugins_for
write_file File.join(@tempdir, 'lib', 'rubygems_plugin.rb') do |io|
io.write "puts __FILE__"
@@ -195,11 +213,11 @@ class TestGemUninstaller < Gem::InstallerTestCase
Gem::Installer.at(Gem::Package.build(@spec)).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), 'plugin not written'
FileUtils.rm plugin_path
- Gem::Uninstaller.new(nil).regenerate_plugins_for @spec
+ Gem::Uninstaller.new(nil).regenerate_plugins_for @spec, Gem.plugindir
assert File.exist?(plugin_path), 'plugin not regenerated'
end
@@ -611,7 +629,7 @@ create_makefile '#{@spec.name}'
io.write "puts __FILE__"
end
- plugin_path = File.join Gem.plugins_dir, 'a_plugin.rb'
+ plugin_path = File.join Gem.plugindir, 'a_plugin.rb'
@spec.version = '1'
Gem::Installer.at(Gem::Package.build(@spec)).install
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 49fe7f96c6..67c55416d4 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -120,6 +120,24 @@ class TestGemRequire < Gem::TestCase
Object.send :remove_const, :HELLO if Object.const_defined? :HELLO
end
+ def test_dash_i_respects_default_library_extension_priority
+ skip "extensions don't quite work on jruby" if Gem.java_platform?
+
+ dash_i_ext_arg = util_install_extension_file('a')
+ dash_i_lib_arg = util_install_ruby_file('a')
+
+ lp = $LOAD_PATH.dup
+
+ begin
+ $LOAD_PATH.unshift dash_i_lib_arg
+ $LOAD_PATH.unshift dash_i_ext_arg
+ assert_require 'a'
+ assert_match(/a\.rb$/, $LOADED_FEATURES.last)
+ ensure
+ $LOAD_PATH.replace lp
+ end
+ end
+
def test_concurrent_require
Object.const_set :FILE_ENTERED_LATCH, Latch.new(2)
Object.const_set :FILE_EXIT_LATCH, Latch.new(1)
@@ -518,15 +536,15 @@ class TestGemRequire < Gem::TestCase
define_method "test_no_other_behavioral_changes_with_#{prefix.tr(".", "_")}warn" do
lib = File.realpath("../../../lib", __FILE__)
Dir.mktmpdir("warn_test") do |dir|
- File.write(dir + "/main.rb", "warn({x:1}, {y:2}, [])\n")
+ File.write(dir + "/main.rb", "#{prefix}warn({x:1}, {y:2}, [])\n")
_, err = capture_subprocess_io do
- system(@@ruby, "-w", "-rpp", "--disable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
+ system(@@ruby, "-w", "--disable=gems", "-I", lib, "-C", dir, "main.rb")
end
- assert_equal("{:x=>1}\n{:y=>2}\n", err)
+ assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
_, err = capture_subprocess_io do
- system(@@ruby, "-w", "-rpp", "--enable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
+ system(@@ruby, "-w", "--enable=gems", "-I", lib, "-C", dir, "main.rb")
end
- assert_equal("{:x=>1}\n{:y=>2}\n", err)
+ assert_match(/{:x=>1}\n{:y=>2}\n$/, err)
end
end
end
@@ -541,4 +559,50 @@ class TestGemRequire < Gem::TestCase
$VERBOSE = old_verbose
end
+ def util_install_extension_file(name)
+ spec = quick_gem name
+ util_build_gem spec
+
+ spec.extensions << "extconf.rb"
+ write_file File.join(@tempdir, "extconf.rb") do |io|
+ io.write <<-RUBY
+ require "mkmf"
+ CONFIG['LDSHARED'] = '$(TOUCH) $@ ||'
+ create_makefile("#{name}")
+ RUBY
+ end
+
+ write_file File.join(@tempdir, "#{name}.c") do |io|
+ io.write <<-C
+ void Init_#{name}() { }
+ C
+ end
+
+ write_file File.join(@tempdir, "depend")
+
+ spec.files += ["extconf.rb", "depend", "#{name}.c"]
+
+ so = File.join(spec.gem_dir, "#{name}.#{RbConfig::CONFIG["DLEXT"]}")
+ refute_path_exists so
+
+ path = Gem::Package.build spec
+ installer = Gem::Installer.at path
+ installer.install
+ assert_path_exists so
+
+ spec.gem_dir
+ end
+
+ def util_install_ruby_file(name)
+ dir_lib = Dir.mktmpdir("test_require_lib", @tempdir)
+ dash_i_lib_arg = File.join dir_lib
+
+ a_rb = File.join dash_i_lib_arg, "#{name}.rb"
+
+ FileUtils.mkdir_p File.dirname a_rb
+ File.open(a_rb, 'w') { |f| f.write "# #{name}.rb" }
+
+ dash_i_lib_arg
+ end
+
end