From ec84bfc9e3d11a3b1dbebcaf4d1ddf1357307513 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 1 Feb 2011 03:11:34 +0000 Subject: 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 --- test/rubygems/test_gem_format.rb | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'test/rubygems/test_gem_format.rb') 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 -- cgit v1.2.3