~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/rubygems/test_gem_format.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require_relative 'gemutilities'
2
 
require_relative 'simple_gem'
 
1
require 'rubygems/package/tar_test_case'
 
2
require 'rubygems/simple_gem'
3
3
require 'rubygems/format'
4
4
 
5
 
class TestGemFormat < RubyGemTestCase
 
5
class TestGemFormat < Gem::Package::TarTestCase
6
6
 
7
7
  def setup
8
8
    super
10
10
    @simple_gem = SIMPLE_GEM
11
11
  end
12
12
 
 
13
  # HACK this test should do less
13
14
  def test_class_from_file_by_path
14
15
    util_make_gems
15
16
 
16
 
    gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
 
17
    gems = Dir[File.join(@gemhome, "cache", "*.gem")]
17
18
 
18
19
    names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
19
20
      spec.original_name
28
29
    end
29
30
  end
30
31
 
 
32
  def test_class_from_file_by_path_corrupt
 
33
    Tempfile.open 'corrupt' do |io|
 
34
      data = Gem.gzip 'a' * 10
 
35
      io.write tar_file_header('metadata.gz', "\000x", 0644, data.length)
 
36
      io.write data
 
37
      io.rewind
 
38
 
 
39
      e = assert_raises Gem::Package::FormatError do
 
40
        Gem::Format.from_file_by_path io.path
 
41
      end
 
42
 
 
43
      sub_message = 'Gem::Package::TarInvalidError: tar is corrupt, name contains null byte'
 
44
      assert_equal "corrupt gem (#{sub_message}) in #{io.path}", e.message
 
45
      assert_equal io.path, e.path
 
46
    end
 
47
  end
 
48
 
31
49
  def test_class_from_file_by_path_empty
32
50
    util_make_gems
33
51
 
49
67
      Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
50
68
    end
51
69
 
52
 
    assert_equal 'No metadata found!', e.message
 
70
    assert_equal 'no metadata found', e.message
53
71
 
54
72
    e = assert_raises Gem::Package::FormatError do
55
73
      # Totally bogus input
56
74
      Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
57
75
    end
58
76
 
59
 
    assert_equal 'No metadata found!', e.message
 
77
    assert_equal 'no metadata found', e.message
60
78
 
61
79
    e = assert_raises Gem::Package::FormatError do
62
80
      # This was intentionally screws up YAML parsing.
63
81
      Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
64
82
    end
65
83
 
66
 
    assert_equal 'No metadata found!', e.message
 
84
    assert_equal 'no metadata found', e.message
67
85
  end
68
86
 
69
87
end