2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2011-01-18 19:08:49 -05:00
|
|
|
require "test/rubygems/simple_gem"
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/format'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemFormat < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@simple_gem = SIMPLE_GEM
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_class_from_file_by_path
|
2007-11-20 00:56:43 -05:00
|
|
|
util_make_gems
|
|
|
|
|
|
|
|
gems = Dir[File.join(@gemhome, 'cache', '*.gem')]
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
|
2007-11-20 00:56:43 -05:00
|
|
|
spec.original_name
|
|
|
|
end
|
|
|
|
|
|
|
|
gems_n_names = gems.sort.zip names
|
|
|
|
|
|
|
|
gems_n_names.each do |gemfile, name|
|
|
|
|
spec = Gem::Format.from_file_by_path(gemfile).spec
|
|
|
|
|
|
|
|
assert_equal name, spec.original_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_class_from_file_by_path_empty
|
|
|
|
util_make_gems
|
|
|
|
|
|
|
|
empty_gem = File.join @tempdir, 'empty.gem'
|
|
|
|
FileUtils.touch empty_gem
|
|
|
|
|
|
|
|
assert_nil Gem::Format.from_file_by_path(empty_gem)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_from_file_by_path_nonexistent
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises Gem::Exception do
|
2007-11-10 02:48:56 -05:00
|
|
|
Gem::Format.from_file_by_path '/nonexistent'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_class_from_io_garbled
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::Package::FormatError do
|
2007-11-10 02:48:56 -05:00
|
|
|
# subtly bogus input
|
|
|
|
Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'No metadata found!', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::Package::FormatError do
|
2007-11-10 02:48:56 -05:00
|
|
|
# Totally bogus input
|
|
|
|
Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'No metadata found!', e.message
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
e = assert_raises Gem::Package::FormatError do
|
2007-11-10 02:48:56 -05:00
|
|
|
# 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
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|