summaryrefslogtreecommitdiff
path: root/test/rubygems
diff options
context:
space:
mode:
authorryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-01 03:11:34 +0000
committerryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-01 03:11:34 +0000
commitec84bfc9e3d11a3b1dbebcaf4d1ddf1357307513 (patch)
treecc3b9df7f06f86c52f4d09c03f5c9a3876c87b67 /test/rubygems
parentf4234c9b8f4707c5979d9a3beddc19ceeb417bd8 (diff)
Import rubygems 1.5.0 (released version @ 1fb59d0)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems')
-rw-r--r--test/rubygems/test_gem_commands_unpack_command.rb40
-rw-r--r--test/rubygems/test_gem_format.rb30
-rw-r--r--test/rubygems/test_gem_package_tar_input.rb21
-rw-r--r--test/rubygems/test_gem_package_tar_reader_entry.rb10
-rw-r--r--test/rubygems/test_gem_package_task.rb13
-rw-r--r--test/rubygems/test_gem_security.rb1
6 files changed, 106 insertions, 9 deletions
diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb
index e8d7984c65..0fb4ef3843 100644
--- a/test/rubygems/test_gem_commands_unpack_command.rb
+++ b/test/rubygems/test_gem_commands_unpack_command.rb
@@ -17,6 +17,46 @@ class TestGemCommandsUnpackCommand < Gem::TestCase
end
end
+ def test_find_in_cache
+ util_make_gems
+
+ assert_equal(
+ @cmd.find_in_cache(@a1.file_name),
+ File.join(@gemhome, 'cache', @a1.file_name),
+ 'found a-1.gem in the cache'
+ )
+ end
+
+ def test_get_path
+ util_make_gems
+ util_setup_fake_fetcher
+ util_setup_spec_fetcher @a1
+
+ a1_data = nil
+
+ open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp|
+ a1_data = fp.read
+ end
+
+ Gem::RemoteFetcher.fetcher.data['http://gems.example.com/gems/a-1.gem'] =
+ a1_data
+
+ dep = Gem::Dependency.new(@a1.name, @a1.version)
+ assert_equal(
+ @cmd.get_path(dep),
+ File.join(@gemhome, 'cache', @a1.file_name),
+ 'fetches a-1 and returns the cache path'
+ )
+
+ FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name)
+
+ assert_equal(
+ @cmd.get_path(dep),
+ File.join(@gemhome, 'cache', @a1.file_name),
+ 'when removed from cache, refetches a-1'
+ )
+ end
+
def test_execute
util_make_gems
diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb
index cbf2bc7788..f964cab143 100644
--- a/test/rubygems/test_gem_format.rb
+++ b/test/rubygems/test_gem_format.rb
@@ -4,11 +4,11 @@
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
######################################################################
-require 'rubygems/test_case'
-require "test/rubygems/simple_gem"
+require 'rubygems/package/tar_test_case'
+require 'test/rubygems/simple_gem'
require 'rubygems/format'
-class TestGemFormat < Gem::TestCase
+class TestGemFormat < Gem::Package::TarTestCase
def setup
super
@@ -16,6 +16,7 @@ class TestGemFormat < Gem::TestCase
@simple_gem = SIMPLE_GEM
end
+ # HACK this test should do less
def test_class_from_file_by_path
util_make_gems
@@ -34,6 +35,23 @@ class TestGemFormat < Gem::TestCase
end
end
+ def test_class_from_file_by_path_corrupt
+ Tempfile.open 'corrupt' do |io|
+ data = Gem.gzip 'a' * 10
+ io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
+ io.write data
+ io.rewind
+
+ e = assert_raises Gem::Package::FormatError do
+ Gem::Format.from_file_by_path io.path
+ end
+
+ sub_message = 'Gem::Package::TarInvalidError: tar is corrupt, name contains null byte'
+ assert_equal "corrupt gem (#{sub_message}) in #{io.path}", e.message
+ assert_equal io.path, e.path
+ end
+ end
+
def test_class_from_file_by_path_empty
util_make_gems
@@ -55,21 +73,21 @@ class TestGemFormat < Gem::TestCase
Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
end
- assert_equal 'No metadata found!', e.message
+ assert_equal 'no metadata found', e.message
e = assert_raises Gem::Package::FormatError do
# Totally bogus input
Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
end
- assert_equal 'No metadata found!', e.message
+ assert_equal 'no metadata found', e.message
e = assert_raises Gem::Package::FormatError do
# This was intentionally screws up YAML parsing.
Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
end
- assert_equal 'No metadata found!', e.message
+ assert_equal 'no metadata found', e.message
end
end
diff --git a/test/rubygems/test_gem_package_tar_input.rb b/test/rubygems/test_gem_package_tar_input.rb
index 0d3de45ba4..72c1ce194a 100644
--- a/test/rubygems/test_gem_package_tar_input.rb
+++ b/test/rubygems/test_gem_package_tar_input.rb
@@ -59,7 +59,24 @@ class TestGemPackageTarInput < Gem::Package::TarTestCase
@entry_contents = %w[0123456789 01234]
end
- def test_each_works
+ def test_initialize_no_metadata_file
+ Tempfile.open 'no_meta' do |io|
+ io.write tar_file_header('a', '', 0644, 1)
+ io.write 'a'
+ io.rewind
+
+ e = assert_raises Gem::Package::FormatError do
+ open io.path, Gem.binary_mode do |file|
+ Gem::Package::TarInput.open file do end
+ end
+ end
+
+ assert_equal "no metadata found in #{io.path}", e.message
+ assert_equal io.path, e.path
+ end
+ end
+
+ def test_each
open @file, 'rb' do |io|
Gem::Package::TarInput.open io do |tar_input|
count = 0
@@ -79,7 +96,7 @@ class TestGemPackageTarInput < Gem::Package::TarTestCase
end
end
- def test_extract_entry_works
+ def test_extract_entry
open @file, 'rb' do |io|
Gem::Package::TarInput.open io do |tar_input|
assert_equal @spec, tar_input.metadata
diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb
index a6d06cf00e..46e30466b9 100644
--- a/test/rubygems/test_gem_package_tar_reader_entry.rb
+++ b/test/rubygems/test_gem_package_tar_reader_entry.rb
@@ -67,6 +67,16 @@ class TestGemPackageTarReaderEntry < Gem::Package::TarTestCase
assert_equal 'lib/foo', @entry.full_name
end
+ def test_full_name_null
+ @entry.header.prefix << "\000"
+
+ e = assert_raises Gem::Package::TarInvalidError do
+ @entry.full_name
+ end
+
+ assert_equal 'tar is corrupt, name contains null byte', e.message
+ end
+
def test_getc
assert_equal ?a, @entry.getc
end
diff --git a/test/rubygems/test_gem_package_task.rb b/test/rubygems/test_gem_package_task.rb
index d13c554360..c53bdf4619 100644
--- a/test/rubygems/test_gem_package_task.rb
+++ b/test/rubygems/test_gem_package_task.rb
@@ -48,5 +48,18 @@ class TestGemPackageTask < Gem::TestCase
assert_equal ["x", "y"], pkg.package_files
end
+ def test_package_dir_path
+ gem = Gem::Specification.new do |g|
+ g.name = 'nokogiri'
+ g.version = '1.5.0'
+ g.platform = 'java'
+ end
+
+ pkg = Gem::PackageTask.new gem
+ pkg.define
+
+ assert_equal 'pkg/nokogiri-1.5.0-java', pkg.package_dir_path
+ end
+
end
diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb
index b8ef7fde35..bb579d7927 100644
--- a/test/rubygems/test_gem_security.rb
+++ b/test/rubygems/test_gem_security.rb
@@ -93,4 +93,3 @@ class TestGemSecurity < Gem::TestCase
end
end if defined?(OpenSSL)
-