aboutsummaryrefslogtreecommitdiffstats
path: root/test/rubygems
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-07 00:53:01 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-07 00:53:01 +0000
commit97f80207d0f0d13f28a419d8c92e96bb9064096a (patch)
treede416fff9bbc978434cb4c1185099151df2ac27c /test/rubygems
parenta0b80a44101708b5d66cdd87f16c98277954a77c (diff)
downloadruby-97f80207d0f0d13f28a419d8c92e96bb9064096a.tar.gz
* lib/rubygems: Update to RubyGems 2.4.5.
* test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem.rb47
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb92
-rw-r--r--test/rubygems/test_gem_package_tar_writer.rb16
-rw-r--r--test/rubygems/test_gem_request_set_lockfile.rb28
-rw-r--r--test/rubygems/test_gem_resolver_api_specification.rb4
-rw-r--r--test/rubygems/test_gem_resolver_installer_set.rb14
-rw-r--r--test/rubygems/test_gem_source.rb14
-rw-r--r--test/rubygems/test_gem_specification.rb51
-rw-r--r--test/rubygems/test_gem_stub_specification.rb10
-rw-r--r--test/rubygems/test_gem_text.rb16
-rw-r--r--test/rubygems/test_kernel.rb24
11 files changed, 274 insertions, 42 deletions
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index 0da28bb9fb..47f57abf81 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -112,6 +112,20 @@ class TestGem < Gem::TestCase
end
end
+ def test_self_bin_path_active
+ a1 = util_spec 'a', '1' do |s|
+ s.executables = ['exec']
+ end
+
+ util_spec 'a', '2' do |s|
+ s.executables = ['exec']
+ end
+
+ a1.activate
+
+ assert_match 'a-1/bin/exec', Gem.bin_path('a', 'exec', '>= 0')
+ end
+
def test_self_bin_path_no_exec_name
e = assert_raises ArgumentError do
Gem.bin_path 'a'
@@ -895,7 +909,7 @@ class TestGem < Gem::TestCase
end
expected = "Ignoring ext-1 because its extensions are not built. " +
- "Try: gem pristine ext-1\n"
+ "Try: gem pristine ext --version 1\n"
assert_equal expected, err
end
@@ -1551,37 +1565,6 @@ You may need to `gem install -g` to install missing gems
@abin_path = File.join spec.full_gem_path, spec.bindir, 'abin'
end
- def util_set_RUBY_VERSION(version, patchlevel = nil, revision = nil)
- if Gem.instance_variables.include? :@ruby_version or
- Gem.instance_variables.include? '@ruby_version' then
- Gem.send :remove_instance_variable, :@ruby_version
- end
-
- @RUBY_VERSION = RUBY_VERSION
- @RUBY_PATCHLEVEL = RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- @RUBY_REVISION = RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, version
- Object.const_set :RUBY_PATCHLEVEL, patchlevel if patchlevel
- Object.const_set :RUBY_REVISION, revision if revision
- end
-
- def util_restore_RUBY_VERSION
- Object.send :remove_const, :RUBY_VERSION
- Object.send :remove_const, :RUBY_PATCHLEVEL if defined?(RUBY_PATCHLEVEL)
- Object.send :remove_const, :RUBY_REVISION if defined?(RUBY_REVISION)
-
- Object.const_set :RUBY_VERSION, @RUBY_VERSION
- Object.const_set :RUBY_PATCHLEVEL, @RUBY_PATCHLEVEL if
- defined?(@RUBY_PATCHLEVEL)
- Object.const_set :RUBY_REVISION, @RUBY_REVISION if
- defined?(@RUBY_REVISION)
- end
-
def util_remove_interrupt_command
Gem::Commands.send :remove_const, :InterruptCommand if
Gem::Commands.const_defined? :InterruptCommand
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index 7ea2b042c9..554d503811 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -287,6 +287,57 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty out, out.inspect
end
+ def test_execute_missing_cache_gem_when_multi_repo
+ specs = spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ fetcher.gem 'b', 1
+ end
+
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'a-1')
+ FileUtils.rm_rf File.join(@gemhome, 'gems', 'b-1')
+
+ install_gem specs["a-1"]
+ FileUtils.rm File.join(@gemhome, 'cache', 'a-1.gem')
+
+ Gem.clear_paths
+ gemhome2 = File.join(@tempdir, 'gemhome2')
+ Gem.paths = { "GEM_PATH" => [gemhome2, @gemhome], "GEM_HOME" => gemhome2 }
+
+ install_gem specs["b-1"]
+ FileUtils.rm File.join(gemhome2, 'cache', 'b-1.gem')
+
+ @cmd.options[:args] = %w[a b]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ out = @ui.output.split "\n"
+
+ [
+ "Restoring gems to pristine condition...",
+ "Cached gem for a-1 not found, attempting to fetch...",
+ "Restored a-1",
+ "Cached gem for b-1 not found, attempting to fetch...",
+ "Restored b-1",
+ ].each do |line|
+ assert_equal line, out.shift
+ end
+
+ assert_empty out, out.inspect
+ assert_empty @ui.error
+
+ assert_path_exists File.join(@gemhome, "cache", 'a-1.gem')
+ refute_path_exists File.join(gemhome2, "cache", 'a-2.gem')
+ assert_path_exists File.join(@gemhome, "gems", 'a-1')
+ refute_path_exists File.join(gemhome2, "gems", 'a-1')
+
+ assert_path_exists File.join(gemhome2, "cache", 'b-1.gem')
+ refute_path_exists File.join(@gemhome, "cache", 'b-2.gem')
+ assert_path_exists File.join(gemhome2, "gems", 'b-1')
+ refute_path_exists File.join(@gemhome, "gems", 'b-1')
+ end
+
def test_execute_no_gem
@cmd.options[:args] = %w[]
@@ -329,6 +380,24 @@ class TestGemCommandsPristineCommand < Gem::TestCase
refute File.exist? gem_lib
end
+ def test_execute_unknown_gem_at_remote_source
+ util_spec 'a'
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal([
+ "Restoring gems to pristine condition...",
+ "Cached gem for a-2 not found, attempting to fetch...",
+ "Skipped a-2, it was not found from cache and remote sources"
+ ], @ui.output.split("\n"))
+
+ assert_empty @ui.error
+ end
+
def test_execute_default_gem
default_gem_spec = new_default_spec("default", "2.0.0.0",
nil, "default/gem.rb")
@@ -348,6 +417,29 @@ class TestGemCommandsPristineCommand < Gem::TestCase
assert_empty(@ui.error)
end
+ def test_execute_bundled_gem_on_old_rubies
+ util_set_RUBY_VERSION '1.9.3', 551
+
+ util_spec 'bigdecimal', '1.1.0' do |s|
+ s.summary = "This bigdecimal is bundled with Ruby"
+ end
+
+ @cmd.options[:args] = %w[bigdecimal]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal([
+ "Restoring gems to pristine condition...",
+ "Skipped bigdecimal-1.1.0, it is bundled with old Ruby"
+ ], @ui.output.split("\n"))
+
+ assert_empty @ui.error
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def test_handle_options
@cmd.handle_options %w[]
diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb
index 96f62b0f5d..f087df3fcf 100644
--- a/test/rubygems/test_gem_package_tar_writer.rb
+++ b/test/rubygems/test_gem_package_tar_writer.rb
@@ -224,26 +224,30 @@ class TestGemPackageTarWriter < Gem::Package::TarTestCase
name = File.join 'a', 'b' * 100
assert_equal ['b' * 100, 'a'], @tar_writer.split_name(name)
- assert_raises Gem::Package::TooLongFileName do
- name = File.join 'a', 'b' * 101
+ name = File.join 'a', 'b' * 101
+ exception = assert_raises Gem::Package::TooLongFileName do
@tar_writer.split_name name
end
+ assert_includes exception.message, name
end
def test_split_name_too_long_prefix
name = File.join 'a' * 155, 'b'
assert_equal ['b', 'a' * 155], @tar_writer.split_name(name)
- assert_raises Gem::Package::TooLongFileName do
- name = File.join 'a' * 156, 'b'
+ name = File.join 'a' * 156, 'b'
+ exception = assert_raises Gem::Package::TooLongFileName do
@tar_writer.split_name name
end
+ assert_includes exception.message, name
end
def test_split_name_too_long_total
- assert_raises Gem::Package::TooLongFileName do
- @tar_writer.split_name 'a' * 257
+ name = 'a' * 257
+ exception = assert_raises Gem::Package::TooLongFileName do
+ @tar_writer.split_name name
end
+ assert_includes exception.message, name
end
end
diff --git a/test/rubygems/test_gem_request_set_lockfile.rb b/test/rubygems/test_gem_request_set_lockfile.rb
index 1022d035fe..7c5cd5a295 100644
--- a/test/rubygems/test_gem_request_set_lockfile.rb
+++ b/test/rubygems/test_gem_request_set_lockfile.rb
@@ -303,6 +303,34 @@ DEPENDENCIES
assert_equal expected, @set.dependencies
end
+ def test_parse_DEPENDENCIES_git_version
+ write_lockfile <<-LOCKFILE
+GIT
+ remote: git://github.com/progrium/ruby-jwt.git
+ revision: 8d74770c6cd92ea234b428b5d0c1f18306a4f41c
+ specs:
+ jwt (1.1)
+
+GEM
+ remote: http://gems.example/
+ specs:
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jwt (= 1.1)!
+ LOCKFILE
+
+ @lockfile.parse
+
+ expected = [
+ dep('jwt', '= 1.1'),
+ ]
+
+ assert_equal expected, @set.dependencies
+ end
+
def test_parse_GEM
write_lockfile <<-LOCKFILE
GEM
diff --git a/test/rubygems/test_gem_resolver_api_specification.rb b/test/rubygems/test_gem_resolver_api_specification.rb
index cfeca43453..dfa61e98a0 100644
--- a/test/rubygems/test_gem_resolver_api_specification.rb
+++ b/test/rubygems/test_gem_resolver_api_specification.rb
@@ -7,7 +7,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
data = {
:name => 'rails',
:number => '3.0.3',
- :platform => 'ruby',
+ :platform => Gem::Platform.local.to_s,
:dependencies => [
['bundler', '~> 1.0'],
['railties', '= 3.0.3'],
@@ -18,7 +18,7 @@ class TestGemResolverAPISpecification < Gem::TestCase
assert_equal 'rails', spec.name
assert_equal Gem::Version.new('3.0.3'), spec.version
- assert_equal Gem::Platform::RUBY, spec.platform
+ assert_equal Gem::Platform.local, spec.platform
expected = [
Gem::Dependency.new('bundler', '~> 1.0'),
diff --git a/test/rubygems/test_gem_resolver_installer_set.rb b/test/rubygems/test_gem_resolver_installer_set.rb
index 3096a23011..d7b917b331 100644
--- a/test/rubygems/test_gem_resolver_installer_set.rb
+++ b/test/rubygems/test_gem_resolver_installer_set.rb
@@ -189,6 +189,20 @@ class TestGemResolverInstallerSet < Gem::TestCase
assert_equal specs["a-2-#{Gem::Platform.local}"].full_name, spec.full_name
end
+ def test_prefetch
+ set = Gem::Resolver::InstallerSet.new :remote
+ def (set.remote_set).prefetch(_)
+ raise "called"
+ end
+ assert_raises(RuntimeError){ set.prefetch(nil) }
+
+ set = Gem::Resolver::InstallerSet.new :local
+ def (set.remote_set).prefetch(_)
+ raise "called"
+ end
+ assert_equal nil, set.prefetch(nil)
+ end
+
def test_prerelease_equals
set = Gem::Resolver::InstallerSet.new :remote
diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb
index 9ded7f7c03..7d23eeea5e 100644
--- a/test/rubygems/test_gem_source.rb
+++ b/test/rubygems/test_gem_source.rb
@@ -21,6 +21,20 @@ class TestGemSource < Gem::TestCase
@source = Gem::Source.new(@gem_repo)
end
+ def test_initialize_invalid_uri
+ assert_raises URI::InvalidURIError do
+ Gem::Source.new 'git@example:a.git'
+ end
+ end
+
+ def test_initialize_git
+ repository = 'git@example:a.git'
+
+ source = Gem::Source::Git.new 'a', repository, 'master', false
+
+ assert_equal repository, source.uri
+ end
+
def test_api_uri
assert_equal @source.api_uri, @source.uri
end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index dd626d9292..3cadc55d5d 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -1353,7 +1353,7 @@ dependencies: []
end
expected = "Ignoring ext-1 because its extensions are not built. " +
- "Try: gem pristine ext-1\n"
+ "Try: gem pristine ext --version 1\n"
assert_equal expected, err
end
@@ -1863,6 +1863,43 @@ dependencies: []
assert_equal expected, @ext.full_require_paths
end
+ def test_to_fullpath
+ ext_spec
+
+ @ext.require_paths = 'lib'
+
+ dir = File.join(@gemhome, 'gems', @ext.original_name, 'lib')
+ expected_rb = File.join(dir, 'code.rb')
+ FileUtils.mkdir_p dir
+ FileUtils.touch expected_rb
+
+ dir = @ext.extension_dir
+ ext = RbConfig::CONFIG["DLEXT"]
+ expected_so = File.join(dir, "ext.#{ext}")
+ FileUtils.mkdir_p dir
+ FileUtils.touch expected_so
+
+ assert_nil @ext.to_fullpath("code")
+ assert_nil @ext.to_fullpath("code.rb")
+ assert_nil @ext.to_fullpath("code.#{ext}")
+
+ assert_nil @ext.to_fullpath("ext")
+ assert_nil @ext.to_fullpath("ext.rb")
+ assert_nil @ext.to_fullpath("ext.#{ext}")
+
+ @ext.activate
+
+ assert_equal expected_rb, @ext.to_fullpath("code")
+ assert_equal expected_rb, @ext.to_fullpath("code.rb")
+ assert_nil @ext.to_fullpath("code.#{ext}")
+
+ assert_equal expected_so, @ext.to_fullpath("ext")
+ assert_nil @ext.to_fullpath("ext.rb")
+ assert_equal expected_so, @ext.to_fullpath("ext.#{ext}")
+
+ assert_nil @ext.to_fullpath("notexist")
+ end
+
def test_require_already_activated
save_loaded_features do
a1 = new_spec "a", "1", nil, "lib/d.rb"
@@ -3010,6 +3047,18 @@ end
assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name)
end
+ def test_detect_bundled_gem_in_old_ruby
+ util_set_RUBY_VERSION '1.9.3', 551
+
+ spec = new_spec 'bigdecimal', '1.1.0' do |s|
+ s.summary = "This bigdecimal is bundled with Ruby"
+ end
+
+ assert spec.bundled_gem_in_old_ruby?
+ ensure
+ util_restore_RUBY_VERSION
+ end
+
def util_setup_deps
@gem = util_spec "awesome", "1.0" do |awesome|
awesome.add_runtime_dependency "bonobo", []
diff --git a/test/rubygems/test_gem_stub_specification.rb b/test/rubygems/test_gem_stub_specification.rb
index d992567a5c..914b06a27a 100644
--- a/test/rubygems/test_gem_stub_specification.rb
+++ b/test/rubygems/test_gem_stub_specification.rb
@@ -55,7 +55,7 @@ class TestStubSpecification < Gem::TestCase
end
expected = "Ignoring stub_e-2 because its extensions are not built. " +
- "Try: gem pristine stub_e-2\n"
+ "Try: gem pristine stub_e --version 2\n"
assert_equal expected, err
end
@@ -122,6 +122,14 @@ class TestStubSpecification < Gem::TestCase
assert_same real_foo, @foo.to_spec
end
+ def test_to_spec_with_other_specs_loaded_does_not_warn
+ real_foo = util_spec @foo.name, @foo.version
+ real_foo.activate
+ bar = Gem::StubSpecification.new BAR
+ refute_predicate Gem.loaded_specs, :empty?
+ assert bar.to_spec
+ end
+
def test_to_spec_activated
assert @foo.to_spec.is_a?(Gem::Specification)
assert_equal "foo", @foo.to_spec.name
diff --git a/test/rubygems/test_gem_text.rb b/test/rubygems/test_gem_text.rb
index 7974bd4e86..e5cfc41e61 100644
--- a/test/rubygems/test_gem_text.rb
+++ b/test/rubygems/test_gem_text.rb
@@ -35,6 +35,22 @@ Without the wrapping, the text might not look good in the RSS feed.
assert_equal expected, format_text(text, 78)
end
+ def test_min3
+ assert_equal 1, min3(1, 1, 1)
+ assert_equal 1, min3(1, 1, 2)
+ assert_equal 1, min3(1, 2, 1)
+ assert_equal 1, min3(2, 1, 1)
+ assert_equal 1, min3(1, 2, 2)
+ assert_equal 1, min3(2, 1, 2)
+ assert_equal 1, min3(2, 2, 1)
+ assert_equal 1, min3(1, 2, 3)
+ assert_equal 1, min3(1, 3, 2)
+ assert_equal 1, min3(2, 1, 3)
+ assert_equal 1, min3(2, 3, 1)
+ assert_equal 1, min3(3, 1, 2)
+ assert_equal 1, min3(3, 2, 1)
+ end
+
def test_levenshtein_distance_add
assert_equal 2, levenshtein_distance("zentest", "zntst")
assert_equal 2, levenshtein_distance("zntst", "zentest")
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index 6d25c48bc1..ee8b248797 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -21,6 +21,30 @@ class TestKernel < Gem::TestCase
assert $:.any? { |p| %r{a-1/lib} =~ p }
end
+ def test_gem_default
+ assert gem('a', '>= 0')
+
+ assert_equal @a2, Gem.loaded_specs['a']
+ end
+
+ def test_gem_default_re_gem
+ assert gem('a', '=1')
+
+ refute gem('a', '>= 0')
+
+ assert_equal @a1, Gem.loaded_specs['a']
+ end
+
+ def test_gem_re_gem_mismatch
+ assert gem('a', '=1')
+
+ assert_raises Gem::LoadError do
+ gem('a', '= 2')
+ end
+
+ assert_equal @a1, Gem.loaded_specs['a']
+ end
+
def test_gem_redundant
assert gem('a', '= 1'), "Should load"
refute gem('a', '= 1'), "Should not load"