summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-17 22:04:18 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-17 22:04:18 +0000
commit9d4f37f51fb2ffdef5e318afb3cb81516dcba4f7 (patch)
tree2eb3c16c59259a25f5d9315edacc61dfc8c59d62 /test
parentf98e6b91dec68ddd010ccb3bad651a18e7dca338 (diff)
Update RubyGems to 1.1.1 r1778 (almost 1.2)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17392 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/rubygems/gemutilities.rb149
-rw-r--r--test/rubygems/test_config.rb5
-rw-r--r--test/rubygems/test_gem.rb24
-rw-r--r--test/rubygems/test_gem_command_manager.rb2
-rw-r--r--test/rubygems/test_gem_commands_dependency_command.rb79
-rw-r--r--test/rubygems/test_gem_commands_environment_command.rb1
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb28
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb14
-rw-r--r--test/rubygems/test_gem_commands_outdated_command.rb43
-rw-r--r--test/rubygems/test_gem_commands_pristine_command.rb17
-rw-r--r--test/rubygems/test_gem_commands_query_command.rb150
-rw-r--r--test/rubygems/test_gem_commands_sources_command.rb132
-rw-r--r--test/rubygems/test_gem_commands_specification_command.rb5
-rw-r--r--test/rubygems/test_gem_commands_stale_command.rb39
-rw-r--r--test/rubygems/test_gem_commands_update_command.rb44
-rw-r--r--test/rubygems/test_gem_config_file.rb33
-rw-r--r--test/rubygems/test_gem_dependency.rb51
-rw-r--r--test/rubygems/test_gem_dependency_installer.rb133
-rw-r--r--test/rubygems/test_gem_gem_path_searcher.rb5
-rw-r--r--test/rubygems/test_gem_indexer.rb143
-rw-r--r--test/rubygems/test_gem_installer.rb32
-rw-r--r--test/rubygems/test_gem_local_remote_options.rb11
-rw-r--r--test/rubygems/test_gem_remote_fetcher.rb23
-rw-r--r--test/rubygems/test_gem_server.rb228
-rw-r--r--test/rubygems/test_gem_source_index.rb271
-rw-r--r--test/rubygems/test_gem_source_info_cache.rb12
-rw-r--r--test/rubygems/test_gem_source_info_cache_entry.rb20
-rw-r--r--test/rubygems/test_gem_spec_fetcher.rb303
-rw-r--r--test/rubygems/test_gem_specification.rb83
-rw-r--r--test/rubygems/test_gem_uninstaller.rb21
-rw-r--r--test/rubygems/test_gem_version.rb19
-rw-r--r--test/rubygems/test_kernel.rb2
32 files changed, 1737 insertions, 385 deletions
diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb
index 967e3dc34d..d8818d0b01 100644
--- a/test/rubygems/gemutilities.rb
+++ b/test/rubygems/gemutilities.rb
@@ -10,10 +10,9 @@ at_exit { $SAFE = 1 }
require 'fileutils'
require 'test/unit'
require 'tmpdir'
-require 'tempfile'
require 'uri'
-require 'rubygems/source_info_cache'
require 'rubygems/package'
+require 'rubygems/test_utilities'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
@@ -27,54 +26,6 @@ module Gem
end
end
-class FakeFetcher
-
- attr_reader :data
- attr_accessor :uri
- attr_accessor :paths
-
- def initialize
- @data = {}
- @paths = []
- @uri = nil
- end
-
- def fetch_path(path)
- path = path.to_s
- @paths << path
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
- data = @data[path]
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
- data.respond_to?(:call) ? data.call : data
- end
-
- def fetch_size(path)
- path = path.to_s
- @paths << path
- raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
- data = @data[path]
- raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil?
- data.respond_to?(:call) ? data.call : data.length
- end
-
- def download spec, source_uri, install_dir = Gem.dir
- name = "#{spec.full_name}.gem"
- path = File.join(install_dir, 'cache', name)
-
- Gem.ensure_gem_subdirectories install_dir
-
- if source_uri =~ /^http/ then
- File.open(path, "wb") do |f|
- f.write fetch_path(File.join(source_uri, "gems", name))
- end
- else
- FileUtils.cp source_uri, path
- end
-
- path
- end
-end
-
class RubyGemTestCase < Test::Unit::TestCase
include Gem::DefaultUserInteraction
@@ -94,8 +45,13 @@ class RubyGemTestCase < Test::Unit::TestCase
@gemcache = File.join(@gemhome, "source_cache")
@usrcache = File.join(@gemhome, ".gem", "user_cache")
@latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
+ @userhome = File.join @tempdir, 'userhome'
+
+ ENV['HOME'] = @userhome
+ Gem.instance_variable_set :@user_home, nil
FileUtils.mkdir_p @gemhome
+ FileUtils.mkdir_p @userhome
ENV['GEMCACHE'] = @usrcache
Gem.use_paths(@gemhome)
@@ -104,9 +60,12 @@ class RubyGemTestCase < Test::Unit::TestCase
Gem.configuration.verbose = true
Gem.configuration.update_sources = true
- @gem_repo = "http://gems.example.com"
+ @gem_repo = "http://gems.example.com/"
+ @uri = URI.parse @gem_repo
Gem.sources.replace [@gem_repo]
+ Gem::SpecFetcher.fetcher = nil
+
@orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
@@ -131,7 +90,7 @@ class RubyGemTestCase < Test::Unit::TestCase
Gem::ConfigMap[:arch] = @orig_arch
if defined? Gem::RemoteFetcher then
- Gem::RemoteFetcher.instance_variable_set :@fetcher, nil
+ Gem::RemoteFetcher.fetcher = nil
end
FileUtils.rm_rf @tempdir
@@ -141,7 +100,6 @@ class RubyGemTestCase < Test::Unit::TestCase
ENV.delete 'GEM_PATH'
Gem.clear_paths
- Gem::SourceInfoCache.instance_variable_set :@cache, nil
end
def install_gem gem
@@ -154,7 +112,7 @@ class RubyGemTestCase < Test::Unit::TestCase
end
gem = File.join(@tempdir, "#{gem.full_name}.gem").untaint
- Gem::Installer.new(gem).install
+ Gem::Installer.new(gem, :wrappers => true).install
end
def prep_cache_files(lc)
@@ -231,6 +189,8 @@ class RubyGemTestCase < Test::Unit::TestCase
spec.loaded_from = written_path
+ Gem.source_index.add_spec spec
+
return spec
end
@@ -254,6 +214,12 @@ class RubyGemTestCase < Test::Unit::TestCase
end
end
+ def util_clear_gems
+ FileUtils.rm_r File.join(@gemhome, 'gems')
+ FileUtils.rm_r File.join(@gemhome, 'specifications')
+ Gem.source_index.refresh!
+ end
+
def util_gem(name, version, &block)
spec = quick_gem(name, version, &block)
@@ -271,6 +237,16 @@ class RubyGemTestCase < Test::Unit::TestCase
[spec, cache_file]
end
+ def util_gzip(data)
+ out = StringIO.new
+
+ Zlib::GzipWriter.wrap out do |io|
+ io.write data
+ end
+
+ out.string
+ end
+
def util_make_gems
init = proc do |s|
s.files = %w[lib/code.rb]
@@ -303,7 +279,7 @@ class RubyGemTestCase < Test::Unit::TestCase
end
##
- # Set the platform to +cpu+ and +os+
+ # Set the platform to +arch+
def util_set_arch(arch)
Gem::ConfigMap[:arch] = arch
@@ -320,9 +296,7 @@ class RubyGemTestCase < Test::Unit::TestCase
require 'socket'
require 'rubygems/remote_fetcher'
- @uri = URI.parse @gem_repo
- @fetcher = FakeFetcher.new
- @fetcher.uri = @uri
+ @fetcher = Gem::FakeFetcher.new
util_make_gems
@@ -338,10 +312,11 @@ class RubyGemTestCase < Test::Unit::TestCase
@source_index.add_spec @a_evil9
@source_index.add_spec @c1_2
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
+ Gem::RemoteFetcher.fetcher = @fetcher
end
def util_setup_source_info_cache(*specs)
+ require 'rubygems/source_info_cache'
require 'rubygems/source_info_cache_entry'
specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
@@ -356,6 +331,35 @@ class RubyGemTestCase < Test::Unit::TestCase
sic.reset_cache_data
Gem::SourceInfoCache.instance_variable_set :@cache, sic
+
+ si
+ end
+
+ def util_setup_spec_fetcher(*specs)
+ specs = Hash[*specs.map { |spec| [spec.full_name, spec] }.flatten]
+ si = Gem::SourceIndex.new specs
+
+ spec_fetcher = Gem::SpecFetcher.fetcher
+
+ spec_fetcher.specs[@uri] = []
+ si.gems.sort_by { |_, spec| spec }.each do |_, spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.specs[@uri] << spec_tuple
+ end
+
+ spec_fetcher.latest_specs[@uri] = []
+ si.latest_specs.sort.each do |spec|
+ spec_tuple = [spec.name, spec.version, spec.original_platform]
+ spec_fetcher.latest_specs[@uri] << spec_tuple
+ end
+
+ si.gems.sort_by { |_,spec| spec }.each do |_, spec|
+ path = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{spec.original_name}.gemspec.rz"
+ data = Marshal.dump spec
+ data_deflate = Zlib::Deflate.deflate data
+ @fetcher.data[path] = data_deflate
+ end
+
si
end
@@ -384,30 +388,3 @@ class RubyGemTestCase < Test::Unit::TestCase
end
-class TempIO
-
- @@count = 0
-
- def initialize(string = '')
- @tempfile = Tempfile.new "TempIO-#{@@count ++ 1}"
- @tempfile.binmode
- @tempfile.write string
- @tempfile.rewind
- end
-
- def method_missing(meth, *args, &block)
- @tempfile.send(meth, *args, &block)
- end
-
- def respond_to?(meth)
- @tempfile.respond_to? meth
- end
-
- def string
- @tempfile.flush
-
- Gem.read_binary @tempfile.path
- end
-
-end
-
diff --git a/test/rubygems/test_config.rb b/test/rubygems/test_config.rb
index 89ac0e4462..0568996c4a 100644
--- a/test/rubygems/test_config.rb
+++ b/test/rubygems/test_config.rb
@@ -12,11 +12,6 @@ require 'rubygems'
class TestConfig < RubyGemTestCase
- def test_gem_original_datadir
- datadir = Config::CONFIG['datadir']
- assert_equal "#{datadir}/xyz", Config.gem_original_datadir('xyz')
- end
-
def test_datadir
datadir = Config::CONFIG['datadir']
assert_equal "#{datadir}/xyz", Config.datadir('xyz')
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index ab147abe65..8a9e2c6e61 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -27,6 +27,14 @@ class TestGem < RubyGemTestCase
assert_equal expected, Gem.all_load_paths.sort
end
+
+ def test_self_available?
+ util_make_gems
+ assert(Gem.available?("a"))
+ assert(Gem.available?("a", "1"))
+ assert(Gem.available?("a", ">1"))
+ assert(!Gem.available?("monkeys"))
+ end
def test_self_bindir
assert_equal File.join(@gemhome, 'bin'), Gem.bindir
@@ -129,7 +137,7 @@ class TestGem < RubyGemTestCase
end
def test_self_default_sources
- assert_equal %w[http://gems.rubyforge.org], Gem.default_sources
+ assert_equal %w[http://gems.rubyforge.org/], Gem.default_sources
end
def test_self_dir
@@ -237,6 +245,18 @@ class TestGem < RubyGemTestCase
assert_equal [Gem.dir], Gem.path
end
+ def test_self_path_default
+ if defined? APPLE_GEM_HOME
+ orig_APPLE_GEM_HOME = APPLE_GEM_HOME
+ Object.send :remove_const, :APPLE_GEM_HOME
+ end
+ Gem.instance_variable_set :@gem_path, nil
+
+ assert_equal [Gem.default_path, Gem.dir], Gem.path
+ ensure
+ Object.const_set :APPLE_GEM_HOME, orig_APPLE_GEM_HOME
+ end
+
unless win_platform?
def test_self_path_APPLE_GEM_HOME
Gem.clear_paths
@@ -382,7 +402,7 @@ class TestGem < RubyGemTestCase
end
def test_self_sources
- assert_equal %w[http://gems.example.com], Gem.sources
+ assert_equal %w[http://gems.example.com/], Gem.sources
end
def test_ssl_available_eh
diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb
index b7767f421d..ee58e89844 100644
--- a/test/rubygems/test_gem_command_manager.rb
+++ b/test/rubygems/test_gem_command_manager.rb
@@ -66,7 +66,7 @@ class TestGemCommandManager < RubyGemTestCase
assert_equal :both, check_options[:domain]
assert_equal true, check_options[:wrappers]
assert_equal Gem::Requirement.default, check_options[:version]
- assert_equal Gem.dir, check_options[:install_dir]
+ assert_equal nil, check_options[:install_dir]
assert_equal nil, check_options[:bin_dir]
#check settings
diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb
index 0f0d95695d..93e772c691 100644
--- a/test/rubygems/test_gem_commands_dependency_command.rb
+++ b/test/rubygems/test_gem_commands_dependency_command.rb
@@ -9,6 +9,8 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
@cmd = Gem::Commands::DependencyCommand.new
@cmd.options[:domain] = :local
+
+ util_setup_fake_fetcher
end
def test_execute
@@ -16,13 +18,15 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
gem.add_dependency 'bar', '> 1'
end
+ Gem.source_index = nil
+
@cmd.options[:args] = %w[foo]
use_ui @ui do
@cmd.execute
end
- assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
assert_equal '', @ui.error
end
@@ -35,7 +39,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
end
end
- assert_equal "No match found for foo (>= 0)\n", @ui.output
+ assert_equal "No gems found matching foo (>= 0)\n", @ui.output
assert_equal '', @ui.error
end
@@ -64,6 +68,8 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
gem.add_dependency 'foo'
end
+ Gem.source_index = nil
+
@cmd.options[:args] = %w[foo]
@cmd.options[:reverse_dependencies] = true
@@ -73,9 +79,9 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase
expected = <<-EOF
Gem foo-2
- bar (> 1)
+ bar (> 1, runtime)
Used by
- baz-2 (foo (>= 0))
+ baz-2 (foo (>= 0, runtime))
EOF
@@ -83,12 +89,34 @@ Gem foo-2
assert_equal '', @ui.error
end
+ def test_execute_reverse_remote
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:reverse_dependencies] = true
+ @cmd.options[:domain] = :remote
+
+ assert_raise MockGemUi::TermError do
+ use_ui @ui do
+ @cmd.execute
+ end
+ end
+
+ expected = <<-EOF
+ERROR: Only reverse dependencies for local gems are supported.
+ EOF
+
+ assert_equal '', @ui.output
+ assert_equal expected, @ui.error
+ end
+
def test_execute_remote
foo = quick_gem 'foo' do |gem|
gem.add_dependency 'bar', '> 1'
end
- util_setup_source_info_cache foo
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher foo
FileUtils.rm File.join(@gemhome, 'specifications',
"#{foo.full_name}.gemspec")
@@ -100,9 +128,48 @@ Gem foo-2
@cmd.execute
end
- assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
assert_equal '', @ui.error
end
+ def test_execute_remote_legacy
+ foo = quick_gem 'foo' do |gem|
+ gem.add_dependency 'bar', '> 1'
+ end
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ Gem::SpecFetcher.fetcher = nil
+ si = util_setup_source_info_cache foo
+
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
+ si.dump
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+
+ FileUtils.rm File.join(@gemhome, 'specifications',
+ "#{foo.full_name}.gemspec")
+
+ @cmd.options[:args] = %w[foo]
+ @cmd.options[:domain] = :remote
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@gem_repo}
+
+RubyGems will revert to legacy indexes degrading performance.
+ EOF
+
+ assert_equal expected, @ui.error
+ end
+
end
diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb
index 7cbb53bd88..78246b0301 100644
--- a/test/rubygems/test_gem_commands_environment_command.rb
+++ b/test/rubygems/test_gem_commands_environment_command.rb
@@ -27,6 +27,7 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase
assert_match %r|RUBYGEMS PREFIX: |, @ui.output
assert_match %r|RUBY EXECUTABLE:.*#{Gem::ConfigMap[:RUBY_INSTALL_NAME]}|,
@ui.output
+ assert_match %r|EXECUTABLE DIRECTORY:|, @ui.output
assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output
assert_match %r|- #{Gem::Platform.local}|, @ui.output
assert_match %r|GEM PATHS:|, @ui.output
diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb
index 5a42e4e81e..eaa13595b7 100644
--- a/test/rubygems/test_gem_commands_fetch_command.rb
+++ b/test/rubygems/test_gem_commands_fetch_command.rb
@@ -14,10 +14,9 @@ class TestGemCommandsFetchCommand < RubyGemTestCase
def test_execute
util_setup_fake_fetcher
+ util_setup_spec_fetcher @a2
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
- @source_index.dump
- @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] =
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
File.read(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
@cmd.options[:args] = [@a2.name]
@@ -28,7 +27,28 @@ class TestGemCommandsFetchCommand < RubyGemTestCase
end
end
- assert File.exist?(File.join(@tempdir, "#{@a2.full_name}.gem"))
+ assert File.exist?(File.join(@tempdir, "#{@a2.full_name}.gem")),
+ "#{@a2.full_name} fetched"
+ end
+
+ def test_execute_legacy
+ util_setup_fake_fetcher
+ util_setup_source_info_cache @a2
+
+ @fetcher.data["#{@gem_repo}yaml"] = ''
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ File.read(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
+
+ @cmd.options[:args] = [@a2.name]
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, "#{@a2.full_name}.gem")),
+ "#{@a2.full_name} fetched"
end
end
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 101195a43e..ef04072b93 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -72,7 +72,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
end
# HACK no repository was checked
- assert_equal "ERROR: could not find no_such_gem locally or in a repository\n",
+ assert_equal "ERROR: could not find gem no_such_gem locally or in a repository\n",
@ui.error
end
@@ -86,8 +86,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
def test_execute_nonexistent
util_setup_fake_fetcher
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
- @source_index.dump
+ util_setup_spec_fetcher
@cmd.options[:args] = %w[nonexistent]
@@ -98,18 +97,18 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
assert_equal 2, e.exit_code
end
- assert_equal "ERROR: could not find nonexistent locally or in a repository\n",
+ assert_equal "ERROR: could not find gem nonexistent locally or in a repository\n",
@ui.error
end
def test_execute_remote
@cmd.options[:generate_rdoc] = true
@cmd.options[:generate_ri] = true
+
util_setup_fake_fetcher
+ util_setup_spec_fetcher @a2
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
- @source_index.dump
- @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] =
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
read_binary(File.join(@gemhome, 'cache', "#{@a2.full_name}.gem"))
@cmd.options[:args] = [@a2.name]
@@ -122,7 +121,6 @@ class TestGemCommandsInstallCommand < RubyGemTestCase
end
out = @ui.output.split "\n"
- assert_match %r|Bulk updating|, out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "1 gem installed", out.shift
assert_equal "Installing ri documentation for #{@a2.full_name}...",
diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb
new file mode 100644
index 0000000000..a6668c01fc
--- /dev/null
+++ b/test/rubygems/test_gem_commands_outdated_command.rb
@@ -0,0 +1,43 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/outdated_command'
+
+class TestGemCommandsOutdatedCommand < RubyGemTestCase
+
+ def setup
+ super
+
+ @cmd = Gem::Commands::OutdatedCommand.new
+ end
+
+ def test_initialize
+ assert @cmd.handles?(%W[--platform #{Gem::Platform.local}])
+ end
+
+ def test_execute
+ local_01 = quick_gem 'foo', '0.1'
+ local_02 = quick_gem 'foo', '0.2'
+ remote_10 = quick_gem 'foo', '1.0'
+ remote_20 = quick_gem 'foo', '2.0'
+
+ remote_spec_file = File.join @gemhome, 'specifications',
+ remote_10.full_name + ".gemspec"
+ FileUtils.rm remote_spec_file
+
+ remote_spec_file = File.join @gemhome, 'specifications',
+ remote_20.full_name + ".gemspec"
+ FileUtils.rm remote_spec_file
+
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher remote_10, remote_20
+
+ use_ui @ui do @cmd.execute end
+
+ assert_equal "foo (0.2 < 2.0)\n", @ui.output
+ assert_equal "", @ui.error
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb
index cd1d3500ae..d5d2d7f339 100644
--- a/test/rubygems/test_gem_commands_pristine_command.rb
+++ b/test/rubygems/test_gem_commands_pristine_command.rb
@@ -18,16 +18,24 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
install_gem a
+ foo_path = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
+
+ File.open foo_path, 'w' do |io|
+ io.puts 'I changed it!'
+ end
+
@cmd.options[:args] = %w[a]
use_ui @ui do
@cmd.execute
end
+ assert_equal "#!/usr/bin/ruby\n", File.read(foo_path), foo_path
+
out = @ui.output.split "\n"
assert_equal "Restoring gem(s) to pristine condition...", out.shift
- assert_equal "#{a.full_name} is in pristine condition", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
assert out.empty?, out.inspect
end
@@ -40,7 +48,7 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
install_gem a
- gem_bin = File.join @gemhome, 'gems', "#{a.full_name}", 'bin', 'foo'
+ gem_bin = File.join @gemhome, 'gems', a.full_name, 'bin', 'foo'
FileUtils.rm gem_bin
@@ -50,11 +58,12 @@ class TestGemCommandsPristineCommand < RubyGemTestCase
@cmd.execute
end
+ assert File.exist?(gem_bin)
+
out = @ui.output.split "\n"
assert_equal "Restoring gem(s) to pristine condition...", out.shift
- assert_equal "Restoring 1 file to #{a.full_name}...", out.shift
- assert_equal " #{gem_bin}", out.shift
+ assert_equal "Restored #{a.full_name}", out.shift
assert out.empty?, out.inspect
end
diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb
index 3c86c69a41..1b65fc7633 100644
--- a/test/rubygems/test_gem_commands_query_command.rb
+++ b/test/rubygems/test_gem_commands_query_command.rb
@@ -7,33 +7,18 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
def setup
super
- util_make_gems
-
- @a2.summary = 'This is a lot of text. ' * 4
-
@cmd = Gem::Commands::QueryCommand.new
- @si = util_setup_source_info_cache @a1, @a2, @pl1
util_setup_fake_fetcher
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] = proc do
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1
+
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
end
end
def test_execute
- cache = Gem::SourceInfoCache.cache
- cache.update
- cache.write_cache
- cache.reset_cache_data
- Gem::SourceInfoCache.reset
-
- a2_name = @a2.full_name
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
- Marshal.dump @si
-
@cmd.handle_options %w[-r]
use_ui @ui do
@@ -44,10 +29,8 @@ class TestGemCommandsQueryCommand < RubyGemTestCase
*** REMOTE GEMS ***
-Updating metadata for 1 gems from http://gems.example.com/
-.
-complete
a (2)
+pl (1)
EOF
assert_equal expected, @ui.output
@@ -55,21 +38,8 @@ a (2)
end
def test_execute_all
- cache = Gem::SourceInfoCache.cache
- cache.update
- cache.write_cache
- cache.reset_cache_data
- Gem::SourceInfoCache.reset
-
a1_name = @a1.full_name
a2_name = @a2.full_name
- @fetcher.data["#{@gem_repo}/quick/index.rz"] =
- util_zip [a1_name, a2_name].join("\n")
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
- Marshal.dump @si
@cmd.handle_options %w[-r --all]
@@ -81,10 +51,8 @@ a (2)
*** REMOTE GEMS ***
-Updating metadata for 2 gems from http://gems.example.com/
-..
-complete
a (2, 1)
+pl (1)
EOF
assert_equal expected, @ui.output
@@ -92,6 +60,13 @@ a (2, 1)
end
def test_execute_details
+ @a2.summary = 'This is a lot of text. ' * 4
+ @a2.authors = ['Abraham Lincoln', 'Hirohito']
+ @a2.homepage = 'http://a.example.com/'
+ @a2.rubyforge_project = 'rubygems'
+
+ @si = util_setup_spec_fetcher @a1, @a2, @pl1
+
@cmd.handle_options %w[-r -d]
use_ui @ui do
@@ -103,10 +78,17 @@ a (2, 1)
*** REMOTE GEMS ***
a (2)
+ Authors: Abraham Lincoln, Hirohito
+ Rubyforge: http://rubyforge.org/projects/rubygems
+ Homepage: http://a.example.com/
+
This is a lot of text. This is a lot of text. This is a lot of text.
This is a lot of text.
pl (1)
+ Author: A User
+ Homepage: http://example.com
+
this is a summary
EOF
@@ -126,6 +108,7 @@ pl (1)
assert_equal 0, e.exit_code
assert_equal "true\n", @ui.output
+
assert_equal '', @ui.error
end
@@ -189,6 +172,99 @@ pl (1)
assert_equal 1, e.exit_code
end
+ def test_execute_legacy
+ Gem::SpecFetcher.fetcher = nil
+ si = util_setup_source_info_cache @a1, @a2, @pl1
+
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
+ si.dump
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+
+ @cmd.handle_options %w[-r]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** REMOTE GEMS ***
+
+a (2)
+pl (1)
+ EOF
+
+ assert_equal expected, @ui.output
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@gem_repo}
+
+RubyGems will revert to legacy indexes degrading performance.
+ EOF
+
+ assert_equal expected, @ui.error
+ end
+
+ def test_execute_local_details
+ @a2.summary = 'This is a lot of text. ' * 4
+ @a2.authors = ['Abraham Lincoln', 'Hirohito']
+ @a2.homepage = 'http://a.example.com/'
+ @a2.rubyforge_project = 'rubygems'
+
+ @cmd.handle_options %w[--local --details]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ expected = <<-EOF
+
+*** LOCAL GEMS ***
+
+a (2, 1)
+ Author: A User
+ Homepage: http://example.com
+ Installed at (2): #{@gemhome}
+ (1): #{@gemhome}
+
+ this is a summary
+
+a_evil (9)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+b (2)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+c (1.2)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+
+pl (1)
+ Author: A User
+ Homepage: http://example.com
+ Installed at: #{@gemhome}
+
+ this is a summary
+ EOF
+
+ assert_equal expected, @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_execute_no_versions
@cmd.handle_options %w[-r --no-versions]
diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb
index f15d44dfe8..623c732e50 100644
--- a/test/rubygems/test_gem_commands_sources_command.rb
+++ b/test/rubygems/test_gem_commands_sources_command.rb
@@ -8,10 +8,12 @@ class TestGemCommandsSourcesCommand < RubyGemTestCase
super
@cmd = Gem::Commands::SourcesCommand.new
+
+ @new_repo = "http://beta-gems.example.com"
end
def test_execute
- util_setup_source_info_cache
+ util_setup_spec_fetcher
@cmd.handle_options []
use_ui @ui do
@@ -34,43 +36,49 @@ class TestGemCommandsSourcesCommand < RubyGemTestCase
si = Gem::SourceIndex.new
si.add_spec @a1
- @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
- si.dump
+ specs = si.map do |_, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
- @cmd.handle_options %w[--add http://beta-gems.example.com]
+ specs_dump_gz = StringIO.new
+ Zlib::GzipWriter.wrap specs_dump_gz do |io|
+ Marshal.dump specs, io
+ end
- util_setup_source_info_cache
+ @fetcher.data["#{@new_repo}/specs.#{@marshal_version}.gz"] =
+ specs_dump_gz.string
+
+ @cmd.handle_options %W[--add #{@new_repo}]
+
+ util_setup_spec_fetcher
use_ui @ui do
@cmd.execute
end
+ assert_equal [@gem_repo, @new_repo], Gem.sources
+
expected = <<-EOF
-Bulk updating Gem source index for: http://beta-gems.example.com/
-http://beta-gems.example.com added to sources
+#{@new_repo} added to sources
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
-
- Gem::SourceInfoCache.cache.flush
- assert_equal %W[http://beta-gems.example.com #{@gem_repo}],
- Gem::SourceInfoCache.cache_data.keys.sort
end
def test_execute_add_nonexistent_source
util_setup_fake_fetcher
- @fetcher.data["http://beta-gems.example.com/Marshal.#{@marshal_version}"] =
- proc do
- raise Gem::RemoteFetcher::FetchError, 'it died'
- end
+ uri = "http://beta-gems.example.com/specs.#{@marshal_version}.gz"
+ @fetcher.data[uri] = proc do
+ raise Gem::RemoteFetcher::FetchError.new('it died', uri)
+ end
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
+ Gem::RemoteFetcher.fetcher = @fetcher
@cmd.handle_options %w[--add http://beta-gems.example.com]
- util_setup_source_info_cache
+ util_setup_spec_fetcher
use_ui @ui do
@cmd.execute
@@ -78,7 +86,7 @@ http://beta-gems.example.com added to sources
expected = <<-EOF
Error fetching http://beta-gems.example.com:
-\tit died
+\tit died (#{uri})
EOF
assert_equal expected, @ui.output
@@ -88,12 +96,14 @@ Error fetching http://beta-gems.example.com:
def test_execute_add_bad_uri
@cmd.handle_options %w[--add beta-gems.example.com]
- util_setup_source_info_cache
+ util_setup_spec_fetcher
use_ui @ui do
@cmd.execute
end
+ assert_equal [@gem_repo], Gem.sources
+
expected = <<-EOF
beta-gems.example.com is not a URI
EOF
@@ -102,6 +112,34 @@ beta-gems.example.com is not a URI
assert_equal '', @ui.error
end
+ def test_execute_add_legacy
+ util_setup_fake_fetcher
+ util_setup_source_info_cache
+
+ si = Gem::SourceIndex.new
+ si.add_spec @a1
+
+ @fetcher.data["#{@new_repo}/yaml"] = ''
+
+ @cmd.handle_options %W[--add #{@new_repo}]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal [@gem_repo], Gem.sources
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\t#{@new_repo}
+
+Will cause RubyGems to revert to legacy indexes, degrading performance.
+ EOF
+
+ assert_equal "#{@new_repo} added to sources\n", @ui.output
+ assert_equal expected, @ui.error
+ end
+
def test_execute_clear_all
@cmd.handle_options %w[--clear-all]
@@ -116,11 +154,19 @@ beta-gems.example.com is not a URI
assert File.exist?(cache.latest_system_cache_file),
'latest system cache file'
+ util_setup_spec_fetcher
+
+ fetcher = Gem::SpecFetcher.fetcher
+
+ # HACK figure out how to force directory creation via fetcher
+ #assert File.directory?(fetcher.dir), 'cache dir exists'
+
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
+*** Removed specs cache ***
*** Removed user source cache ***
*** Removed latest user source cache ***
*** Removed system source cache ***
@@ -135,12 +181,13 @@ beta-gems.example.com is not a URI
assert !File.exist?(cache.latest_system_cache_file),
'latest system cache file'
+ assert !File.exist?(fetcher.dir), 'cache dir removed'
end
def test_execute_remove
@cmd.handle_options %W[--remove #{@gem_repo}]
- util_setup_source_info_cache
+ util_setup_spec_fetcher
use_ui @ui do
@cmd.execute
@@ -150,9 +197,6 @@ beta-gems.example.com is not a URI
assert_equal expected, @ui.output
assert_equal '', @ui.error
-
- Gem::SourceInfoCache.cache.flush
- assert_equal [], Gem::SourceInfoCache.cache_data.keys
end
def test_execute_remove_no_network
@@ -160,7 +204,7 @@ beta-gems.example.com is not a URI
util_setup_fake_fetcher
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] = proc do
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do
raise Gem::RemoteFetcher::FetchError
end
@@ -172,34 +216,60 @@ beta-gems.example.com is not a URI
assert_equal expected, @ui.output
assert_equal '', @ui.error
-
- Gem::SourceInfoCache.cache.flush
- assert_equal [], Gem::SourceInfoCache.cache_data.keys
end
def test_execute_update
@cmd.handle_options %w[--update]
+ util_setup_fake_fetcher
+ source_index = util_setup_spec_fetcher @a1
+
+ specs = source_index.map do |name, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
+ util_gzip Marshal.dump(specs)
+
+ latest_specs = source_index.latest_specs.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
+ util_gzip Marshal.dump(latest_specs)
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ assert_equal "source cache successfully updated\n", @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_execute_update_legacy
+ @cmd.handle_options %w[--update]
+
+ util_setup_fake_fetcher
util_setup_source_info_cache
Gem::SourceInfoCache.reset
- util_setup_fake_fetcher
si = Gem::SourceIndex.new
si.add_spec @a1
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
+ @fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
use_ui @ui do
@cmd.execute
end
expected = <<-EOF
-Bulk updating Gem source index for: #{@gem_repo}/
+Bulk updating Gem source index for: #{@gem_repo}
source cache successfully updated
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
-
+
end
diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb
index f66f0c0d49..7ac0429f32 100644
--- a/test/rubygems/test_gem_commands_specification_command.rb
+++ b/test/rubygems/test_gem_commands_specification_command.rb
@@ -74,7 +74,10 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase
def test_execute_remote
foo = quick_gem 'foo'
- util_setup_source_info_cache foo
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ util_setup_spec_fetcher foo
FileUtils.rm File.join(@gemhome, 'specifications',
"#{foo.full_name}.gemspec")
diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb
new file mode 100644
index 0000000000..6f66c854a5
--- /dev/null
+++ b/test/rubygems/test_gem_commands_stale_command.rb
@@ -0,0 +1,39 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/commands/stale_command'
+
+class TestGemCommandsStaleCommand < RubyGemTestCase
+
+ def setup
+ super
+ @cmd = Gem::Commands::StaleCommand.new
+ end
+
+ def test_execute_sorts
+ files = %w[lib/foo_bar.rb Rakefile]
+ foo_bar = quick_gem 'foo_bar' do |gem|
+ gem.files = files
+ end
+ bar_baz = quick_gem 'bar_baz' do |gem|
+ gem.files = files
+ end
+
+ files.each do |file|
+ filename = bar_baz.full_gem_path + "/#{file}"
+ FileUtils.mkdir_p(File.dirname(filename))
+ FileUtils.touch(filename, :mtime => Time.now)
+
+ filename = foo_bar.full_gem_path + "/#{file}"
+ FileUtils.mkdir_p(File.dirname(filename))
+ FileUtils.touch(filename, :mtime => Time.now - 86400)
+ end
+
+ use_ui @ui do
+ @cmd.execute
+ end
+ lines = @ui.output.split("\n")
+ assert_equal("#{foo_bar.name}-#{foo_bar.version}", lines[0].split.first)
+ assert_equal("#{bar_baz.name}-#{bar_baz.version}", lines[1].split.first)
+ end
+
+end
diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb
index 6aeb53d25a..11da1f8a83 100644
--- a/test/rubygems/test_gem_commands_update_command.rb
+++ b/test/rubygems/test_gem_commands_update_command.rb
@@ -14,14 +14,16 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
@a1_path = File.join @gemhome, 'cache', "#{@a1.full_name}.gem"
@a2_path = File.join @gemhome, 'cache', "#{@a2.full_name}.gem"
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
- @source_index.dump
- @fetcher.data["#{@gem_repo}/gems/#{@a1.full_name}.gem"] = read_binary @a1_path
- @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] = read_binary @a2_path
+ util_setup_spec_fetcher @a1, @a2
+
+ @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] =
+ read_binary @a1_path
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
+ read_binary @a2_path
end
def test_execute
- util_remove_gems
+ util_clear_gems
Gem::Installer.new(@a1_path).install
@@ -33,7 +35,6 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Updating #{@a2.name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "Gems updated: #{@a2.name}", out.shift
@@ -73,16 +74,15 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
util_build_gem @a2
util_build_gem @c2
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
- @source_index.dump
- @fetcher.data["#{@gem_repo}/gems/#{@a1.full_name}.gem"] = read_binary @a1_path
- @fetcher.data["#{@gem_repo}/gems/#{@a2.full_name}.gem"] = read_binary @a2_path
- @fetcher.data["#{@gem_repo}/gems/#{@b2.full_name}.gem"] = read_binary @b2_path
- @fetcher.data["#{@gem_repo}/gems/#{@c1_2.full_name}.gem"] =
+ @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] = read_binary @a1_path
+ @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] = read_binary @a2_path
+ @fetcher.data["#{@gem_repo}gems/#{@b2.full_name}.gem"] = read_binary @b2_path
+ @fetcher.data["#{@gem_repo}gems/#{@c1_2.full_name}.gem"] =
read_binary @c1_2_path
- @fetcher.data["#{@gem_repo}/gems/#{@c2.full_name}.gem"] = read_binary @c2_path
+ @fetcher.data["#{@gem_repo}gems/#{@c2.full_name}.gem"] = read_binary @c2_path
- util_remove_gems
+ util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
+ util_clear_gems
Gem::Installer.new(@c1_2_path).install
Gem::Installer.new(@a1_path).install
@@ -95,9 +95,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Updating #{@a2.name}", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Successfully installed #{@c2.full_name}", out.shift
assert_equal "Successfully installed #{@b2.full_name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
@@ -108,7 +106,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
end
def test_execute_named
- util_remove_gems
+ util_clear_gems
Gem::Installer.new(@a1_path).install
@@ -120,7 +118,6 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Updating #{@a2.name}", out.shift
assert_equal "Successfully installed #{@a2.full_name}", out.shift
assert_equal "Gems updated: #{@a2.name}", out.shift
@@ -129,7 +126,7 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
end
def test_execute_named_up_to_date
- util_remove_gems
+ util_clear_gems
Gem::Installer.new(@a2_path).install
@@ -141,14 +138,13 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Nothing to update", out.shift
assert out.empty?, out.inspect
end
def test_execute_up_to_date
- util_remove_gems
+ util_clear_gems
Gem::Installer.new(@a2_path).install
@@ -160,16 +156,10 @@ class TestGemCommandsUpdateCommand < RubyGemTestCase
out = @ui.output.split "\n"
assert_equal "Updating installed gems", out.shift
- assert_match %r|Bulk updating|, out.shift
assert_equal "Nothing to update", out.shift
assert out.empty?, out.inspect
end
- def util_remove_gems
- FileUtils.rm_r File.join(@gemhome, 'gems')
- FileUtils.rm_r File.join(@gemhome, 'specifications')
- end
-
end
diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb
index e0360b0d6b..c7f6b93c7f 100644
--- a/test/rubygems/test_gem_config_file.rb
+++ b/test/rubygems/test_gem_config_file.rb
@@ -17,9 +17,23 @@ class TestGemConfigFile < RubyGemTestCase
@temp_conf = File.join @tempdir, '.gemrc'
@cfg_args = %W[--config-file #{@temp_conf}]
+
+ @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
+ File.join(@tempdir, 'system-gemrc')
+
util_config_file
end
+ def teardown
+ Gem::ConfigFile.send :remove_const, :SYSTEM_WIDE_CONFIG_FILE
+ Gem::ConfigFile.send :const_set, :SYSTEM_WIDE_CONFIG_FILE,
+ @orig_SYSTEM_WIDE_CONFIG_FILE
+
+ super
+ end
+
def test_initialize
assert_equal @temp_conf, @cfg.config_file_name
@@ -28,7 +42,7 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal false, @cfg.benchmark
assert_equal Gem::ConfigFile::DEFAULT_BULK_THRESHOLD, @cfg.bulk_threshold
assert_equal true, @cfg.verbose
- assert_equal %w[http://gems.example.com], Gem.sources
+ assert_equal [@gem_repo], Gem.sources
File.open @temp_conf, 'w' do |fp|
fp.puts ":backtrace: true"
@@ -202,6 +216,23 @@ class TestGemConfigFile < RubyGemTestCase
assert_equal %w[http://even-more-gems.example.com], Gem.sources
end
+ def test_global_config_file
+ File.open(@temp_conf, 'w') do |fp|
+ fp.puts ":backtrace: true"
+ end
+
+ File.open(File.join(Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE),
+ 'w') do |fp|
+ fp.puts ":backtrace: false"
+ fp.puts ":bulk_threshold: 2048"
+ end
+
+ util_config_file
+
+ assert_equal 2048, @cfg.bulk_threshold
+ assert @cfg.backtrace
+ end
+
def util_config_file(args = @cfg_args)
@cfg = Gem::ConfigFile.new args
end
diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb
index f280221a00..315c49d6ce 100644
--- a/test/rubygems/test_gem_dependency.rb
+++ b/test/rubygems/test_gem_dependency.rb
@@ -60,6 +60,21 @@ class TestGemDependency < RubyGemTestCase
assert_equal Gem::Requirement.new('= 2'), dep.version_requirements
end
+ def test_initialize_with_type
+ dep = Gem::Dependency.new("pkg", [], :development)
+ assert_equal(:development, dep.type)
+ end
+
+ def test_type_is_runtime_by_default
+ assert_equal(:runtime, Gem::Dependency.new("pkg", []).type)
+ end
+
+ def test_type_is_restricted
+ assert_raise(ArgumentError) do
+ Gem::Dependency.new("pkg", [:sometimes])
+ end
+ end
+
def test_equals2
assert_equal @pkg1_0, @pkg1_0.dup
assert_equal @pkg1_0.dup, @pkg1_0
@@ -74,6 +89,36 @@ class TestGemDependency < RubyGemTestCase
assert_not_equal Object.new, @pkg1_0
end
+ def test_equals2_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime, development)
+ end
+
+ def test_equals_tilde
+ def dep(name, version)
+ Gem::Dependency.new name, version
+ end
+
+ a0 = dep 'a', '0'
+ a1 = dep 'a', '1'
+ b0 = dep 'b', '0'
+
+ pa0 = dep 'a', '>= 0'
+ pa0r = dep(/a/, '>= 0')
+ pab0r = dep(/a|b/, '>= 0')
+
+ assert((a0 =~ a0), 'match self')
+ assert((pa0 =~ a0), 'match version exact')
+ assert((pa0 =~ a1), 'match version')
+ assert((pa0r =~ a0), 'match regex simple')
+ assert((pab0r =~ a0), 'match regex complex')
+
+ assert(!(pa0r =~ b0), 'fail match regex')
+ assert(!(pa0r =~ Object.new), 'fail match Object')
+ end
+
def test_hash
assert_equal @pkg1_0.hash, @pkg1_0.dup.hash
assert_equal @pkg1_0.dup.hash, @pkg1_0.hash
@@ -85,5 +130,11 @@ class TestGemDependency < RubyGemTestCase
assert_not_equal @oth1_0.hash, @pkg1_0.hash, "names different"
end
+ def test_hash_type
+ runtime = Gem::Dependency.new("pkg", [])
+ development = Gem::Dependency.new("pkg", [], :development)
+
+ assert_not_equal(runtime.hash, development.hash)
+ end
end
diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb
index 914d4aa216..80c446a2ad 100644
--- a/test/rubygems/test_gem_dependency_installer.rb
+++ b/test/rubygems/test_gem_dependency_installer.rb
@@ -15,8 +15,12 @@ class TestGemDependencyInstaller < RubyGemTestCase
fp.puts "#!/usr/bin/ruby"
end
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
+ @aa1, @aa1_gem = util_gem 'aa', '1'
- @b1, @b1_gem = util_gem 'b', '1' do |s| s.add_dependency 'a' end
+ @b1, @b1_gem = util_gem 'b', '1' do |s|
+ s.add_dependency 'a'
+ s.add_development_dependency 'aa'
+ end
@d1, @d1_gem = util_gem 'd', '1'
@d2, @d2_gem = util_gem 'd', '2'
@@ -38,15 +42,13 @@ class TestGemDependencyInstaller < RubyGemTestCase
@z1, @z1_gem = util_gem 'z', '1' do |s| s.add_dependency 'y' end
- si = util_setup_source_info_cache @a1, @b1, @d1, @d2, @x1_m, @x1_o, @w1,
- @y1, @y1_1_p, @z1
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
- @fetcher = FakeFetcher.new
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
- @fetcher.uri = URI.parse 'http://gems.example.com'
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ si = util_setup_spec_fetcher @a1, @b1, @d1, @d2, @x1_m, @x1_o, @w1, @y1,
+ @y1_1_p, @z1
- FileUtils.rm_rf File.join(@gemhome, 'gems')
+ util_clear_gems
end
def test_install
@@ -64,6 +66,52 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal [@a1], inst.installed_gems
end
+ def test_install_cache_dir
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :cache_dir => @tempdir
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
+
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@a1.full_name}.gem"))
+ assert File.exist?(File.join(@tempdir, 'cache', "#{@b1.full_name}.gem"))
+ end
+
+ def test_install_dependencies_satisfied
+ a2, a2_gem = util_gem 'a', '2'
+
+ FileUtils.rm_rf File.join(@gemhome, 'gems')
+ Gem.source_index.refresh!
+
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv a2_gem, @tempdir # not in index
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'a-2'
+ end
+
+ FileUtils.rm File.join(@tempdir, "#{a2.full_name}.gem")
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ installed = Gem::SourceIndex.from_installed_gems.map { |n,s| s.full_name }
+
+ assert_equal %w[a-2 b-1], installed.sort
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
def test_install_dependency
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
@@ -77,6 +125,20 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name }
end
+ def test_install_dependency_development
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @aa1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new(:development => true)
+ inst.install 'b'
+ end
+
+ assert_equal %w[a-1 aa-1 b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
def test_install_dependency_existing
Gem::Installer.new(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
@@ -177,7 +239,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
def test_install_force
FileUtils.mv @b1_gem, @tempdir
- si = util_setup_source_info_cache @b1
+ si = util_setup_spec_fetcher @b1
@fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
inst = nil
@@ -249,8 +311,6 @@ class TestGemDependencyInstaller < RubyGemTestCase
end
def test_install_domain_both_no_network
- Gem::SourceInfoCache.instance_variable_set :@cache, nil
-
@fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] =
proc do
raise Gem::RemoteFetcher::FetchError
@@ -272,12 +332,14 @@ class TestGemDependencyInstaller < RubyGemTestCase
FileUtils.mv @b1_gem, @tempdir
inst = nil
+ Gem.source_index.gems.delete @a1.full_name
+
Dir.chdir @tempdir do
e = assert_raise Gem::InstallError do
inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b'
end
- assert_equal 'b requires a (>= 0)', e.message
+ assert_equal 'b requires a (>= 0, runtime)', e.message
end
assert_equal [], inst.installed_gems.map { |s| s.full_name }
@@ -297,6 +359,30 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name }
end
+ def test_install_dual_repository
+ FileUtils.mv @a1_gem, @tempdir
+ FileUtils.mv @b1_gem, @tempdir
+ inst = nil
+
+ gemhome2 = "#{@gemhome}2"
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new :install_dir => gemhome2
+ inst.install 'a'
+ end
+
+ ENV['GEM_HOME'] = @gemhome
+ ENV['GEM_PATH'] = [@gemhome, gemhome2].join ':'
+ Gem.clear_paths
+
+ Dir.chdir @tempdir do
+ inst = Gem::DependencyInstaller.new
+ inst.install 'b'
+ end
+
+ assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name }
+ end
+
def test_install_remote
a1_data = nil
File.open @a1_gem, 'rb' do |fp|
@@ -337,7 +423,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
s.platform = Gem::Platform.new %w[cpu other_platform 1]
end
- si = util_setup_source_info_cache @a1, a2_o
+ util_clear_gems
+
+ si = util_setup_spec_fetcher @a1, a2_o
@fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
@@ -439,7 +527,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
inst = Gem::DependencyInstaller.new
dep = Gem::Dependency.new 'b', '>= 0'
- assert_equal [[@b1, 'http://gems.example.com']],
+ assert_equal [[@b1, @gem_repo]],
inst.find_gems_with_sources(dep)
end
@@ -456,7 +544,7 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal 2, gems.length
remote = gems.first
assert_equal 'a-1', remote.first.full_name, 'remote spec'
- assert_equal 'http://gems.example.com', remote.last, 'remote path'
+ assert_equal @gem_repo, remote.last, 'remote path'
local = gems.last
assert_equal 'a-1', local.first.full_name, 'local spec'
@@ -476,12 +564,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
b2, = util_gem 'b', '2'
c1, = util_gem 'c', '1' do |s| s.add_dependency 'b' end
- si = util_setup_source_info_cache @a1, @b1, b2, c1
+ util_clear_gems
- @fetcher = FakeFetcher.new
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
- @fetcher.uri = URI.parse 'http://gems.example.com'
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ si = util_setup_spec_fetcher @a1, @b1, b2, c1
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version 'c'
@@ -512,12 +597,9 @@ class TestGemDependencyInstaller < RubyGemTestCase
def test_gather_dependencies_old_required
e1, = util_gem 'e', '1' do |s| s.add_dependency 'd', '= 1' end
- si = util_setup_source_info_cache @d1, @d2, e1
+ util_clear_gems
- @fetcher = FakeFetcher.new
- Gem::RemoteFetcher.instance_variable_set :@fetcher, @fetcher
- @fetcher.uri = URI.parse 'http://gems.example.com'
- @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml
+ si = util_setup_spec_fetcher @d1, @d2, e1
inst = Gem::DependencyInstaller.new
inst.find_spec_by_name_and_version 'e'
@@ -525,5 +607,6 @@ class TestGemDependencyInstaller < RubyGemTestCase
assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name }
end
+
end
diff --git a/test/rubygems/test_gem_gem_path_searcher.rb b/test/rubygems/test_gem_gem_path_searcher.rb
index d35416e867..c9da4d2b05 100644
--- a/test/rubygems/test_gem_gem_path_searcher.rb
+++ b/test/rubygems/test_gem_gem_path_searcher.rb
@@ -28,7 +28,10 @@ class TestGemGemPathSearcher < RubyGemTestCase
@bar1 = quick_gem 'bar', '0.1'
@bar2 = quick_gem 'bar', '0.2'
- Gem.source_index = util_setup_source_info_cache @foo1, @foo2, @bar1, @bar2
+ @fetcher = Gem::FakeFetcher.new
+ Gem::RemoteFetcher.fetcher = @fetcher
+
+ Gem.source_index = util_setup_spec_fetcher @foo1, @foo2, @bar1, @bar2
@gps = Gem::GemPathSearcher.new
end
diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb
index 12469b5d57..5ccaaff01f 100644
--- a/test/rubygems/test_gem_indexer.rb
+++ b/test/rubygems/test_gem_indexer.rb
@@ -20,6 +20,10 @@ class TestGemIndexer < RubyGemTestCase
util_make_gems
+ @d2_0 = quick_gem 'd', '2.0'
+ write_file File.join(*%W[gems #{@d2_0.original_name} lib code.rb]) do end
+ util_build_gem @d2_0
+
gems = File.join(@tempdir, 'gems')
FileUtils.mkdir_p gems
cache_gems = File.join @gemhome, 'cache', '*.gem'
@@ -39,10 +43,10 @@ class TestGemIndexer < RubyGemTestCase
@indexer.generate_index
end
- assert File.exist?(File.join(@tempdir, 'yaml'))
- assert File.exist?(File.join(@tempdir, 'yaml.Z'))
- assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}"))
- assert File.exist?(File.join(@tempdir, "Marshal.#{@marshal_version}.Z"))
+ assert_indexed @tempdir, 'yaml'
+ assert_indexed @tempdir, 'yaml.Z'
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}"
+ assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z"
quickdir = File.join @tempdir, 'quick'
marshal_quickdir = File.join quickdir, "Marshal.#{@marshal_version}"
@@ -53,10 +57,33 @@ class TestGemIndexer < RubyGemTestCase
assert_indexed quickdir, "index"
assert_indexed quickdir, "index.rz"
+ quick_index = File.read File.join(quickdir, 'index')
+ expected = <<-EOF
+a-1
+a-2
+a_evil-9
+b-2
+c-1.2
+d-2.0
+pl-1-i386-linux
+ EOF
+
+ assert_equal expected, quick_index
+
assert_indexed quickdir, "latest_index"
assert_indexed quickdir, "latest_index.rz"
- assert_no_match %r|a-1|, File.read(File.join(quickdir, 'latest_index'))
+ latest_quick_index = File.read File.join(quickdir, 'latest_index')
+ expected = <<-EOF
+a-2
+a_evil-9
+b-2
+c-1.2
+d-2.0
+pl-1-i386-linux
+ EOF
+
+ assert_equal expected, latest_quick_index
assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz"
assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz"
@@ -64,13 +91,19 @@ class TestGemIndexer < RubyGemTestCase
assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz"
assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz"
- deny_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
+ refute_indexed quickdir, "#{@pl1.full_name}.gemspec.rz"
assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz"
assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz"
- deny_indexed quickdir, "#{@c1_2.full_name}.gemspec"
- deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
+ refute_indexed quickdir, "#{@c1_2.full_name}.gemspec"
+ refute_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec"
+
+ assert_indexed @tempdir, "specs.#{@marshal_version}"
+ assert_indexed @tempdir, "specs.#{@marshal_version}.gz"
+
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}"
+ assert_indexed @tempdir, "latest_specs.#{@marshal_version}.gz"
end
def test_generate_index_ui
@@ -79,28 +112,37 @@ class TestGemIndexer < RubyGemTestCase
end
expected = <<-EOF
-Generating index for 6 gems in #{@tempdir}
-......
+Loading 7 gems from #{@tempdir}
+.......
Loaded all gems
-Generating master indexes (this may take a while)
+Generating quick index gemspecs for 7 gems
+.......
+Complete
+Generating specs index
+Generating latest specs index
+Generating quick index
+Generating latest index
+Generating Marshal master index
+Generating YAML master index for 7 gems (this may take a while)
+.......
+Complete
+Compressing indicies
EOF
assert_equal expected, @ui.output
assert_equal '', @ui.error
end
- def test_generate_index_contents
+ def test_generate_index_master
use_ui @ui do
@indexer.generate_index
end
- yaml_path = File.join(@tempdir, 'yaml')
- dump_path = File.join(@tempdir, "Marshal.#{@marshal_version}")
+ yaml_path = File.join @tempdir, 'yaml'
+ dump_path = File.join @tempdir, "Marshal.#{@marshal_version}"
- yaml_index = YAML.load_file(yaml_path)
- dump_str = nil
- File.open dump_path, 'rb' do |fp| dump_str = fp.read end
- dump_index = Marshal.load dump_str
+ yaml_index = YAML.load_file yaml_path
+ dump_index = Marshal.load Gem.read_binary(dump_path)
dump_index.each do |_,gem|
gem.send :remove_instance_variable, :@loaded
@@ -110,12 +152,75 @@ Generating master indexes (this may take a while)
"expected YAML and Marshal to produce identical results"
end
+ def test_generate_index_specs
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ specs_path = File.join @tempdir, "specs.#{@marshal_version}"
+
+ specs_dump = Gem.read_binary specs_path
+ specs = Marshal.load specs_dump
+
+ expected = [
+ ['a', Gem::Version.new(1), 'ruby'],
+ ['a', Gem::Version.new(2), 'ruby'],
+ ['a_evil', Gem::Version.new(9), 'ruby'],
+ ['b', Gem::Version.new(2), 'ruby'],
+ ['c', Gem::Version.new('1.2'), 'ruby'],
+ ['d', Gem::Version.new('2.0'), 'ruby'],
+ ['pl', Gem::Version.new(1), 'i386-linux'],
+ ]
+
+ assert_equal expected, specs
+
+ assert_same specs[0].first, specs[1].first,
+ 'identical names not identical'
+
+ assert_same specs[0][1], specs[-1][1],
+ 'identical versions not identical'
+
+ assert_same specs[0].last, specs[1].last,
+ 'identical platforms not identical'
+
+ assert_not_same specs[1][1], specs[5][1],
+ 'different versions not different'
+ end
+
+ def test_generate_index_latest_specs
+ use_ui @ui do
+ @indexer.generate_index
+ end
+
+ latest_specs_path = File.join @tempdir, "latest_specs.#{@marshal_version}"
+
+ latest_specs_dump = Gem.read_binary latest_specs_path
+ latest_specs = Marshal.load latest_specs_dump
+
+ expected = [
+ ['a', Gem::Version.new(2), 'ruby'],
+ ['a_evil', Gem::Version.new(9), 'ruby'],
+ ['b', Gem::Version.new(2), 'ruby'],
+ ['c', Gem::Version.new('1.2'), 'ruby'],
+ ['d', Gem::Version.new('2.0'), 'ruby'],
+ ['pl', Gem::Version.new(1), 'i386-linux'],
+ ]
+
+ assert_equal expected, latest_specs
+
+ assert_same latest_specs[0][1], latest_specs[2][1],
+ 'identical versions not identical'
+
+ assert_same latest_specs[0].last, latest_specs[1].last,
+ 'identical platforms not identical'
+ end
+
def assert_indexed(dir, name)
file = File.join dir, name
assert File.exist?(file), "#{file} does not exist"
end
- def deny_indexed(dir, name)
+ def refute_indexed(dir, name)
file = File.join dir, name
assert !File.exist?(file), "#{file} exists"
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index f7d36c66ed..edd8b472cd 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -102,7 +102,7 @@ load 'my_exec'
@installer.ensure_dependency @spec, dep
end
- assert_equal 'a requires b (> 2)', e.message
+ assert_equal 'a requires b (> 2, runtime)', e.message
end
def test_expand_and_validate_gem_dir
@@ -128,7 +128,12 @@ load 'my_exec'
@installer.extract_files
- assert_equal 'thefile', File.read(File.join(util_gem_dir, 'thefile'))
+ thefile_path = File.join(util_gem_dir, 'thefile')
+ assert_equal 'thefile', File.read(thefile_path)
+
+ unless Gem.win_platform? then
+ assert_equal 0400, File.stat(thefile_path).mode & 0777
+ end
end
def test_extract_files_bad_dest
@@ -313,6 +318,29 @@ load 'my_exec'
#assert_no_match %r|generated by RubyGems|, wrapper
end
+ def test_generate_bin_script_wrappers
+ @installer.wrappers = true
+ util_make_exec
+ @installer.gem_dir = util_gem_dir
+ installed_exec = File.join(util_inst_bindir, "my_exec")
+
+ real_exec = File.join util_gem_dir, 'bin', 'my_exec'
+
+ # fake --no-wrappers for previous install
+ FileUtils.mkdir_p File.dirname(installed_exec)
+ FileUtils.ln_s real_exec, installed_exec
+
+ @installer.generate_bin
+ assert_equal true, File.directory?(util_inst_bindir)
+ assert_equal true, File.exist?(installed_exec)
+ assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform?
+
+ assert_match %r|generated by RubyGems|, File.read(installed_exec)
+
+ assert_no_match %r|generated by RubyGems|, File.read(real_exec),
+ 'real executable overwritten'
+ end
+
def test_generate_bin_symlink
return if win_platform? #Windows FS do not support symlinks
diff --git a/test/rubygems/test_gem_local_remote_options.rb b/test/rubygems/test_gem_local_remote_options.rb
index d5a6651ade..e676c94f21 100644
--- a/test/rubygems/test_gem_local_remote_options.rb
+++ b/test/rubygems/test_gem_local_remote_options.rb
@@ -46,12 +46,13 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
def test_source_option
@cmd.add_source_option
- s1 = URI.parse 'http://more-gems.example.com'
- s2 = URI.parse 'http://even-more-gems.example.com'
+ s1 = URI.parse 'http://more-gems.example.com/'
+ s2 = URI.parse 'http://even-more-gems.example.com/'
+ s3 = URI.parse 'http://other-gems.example.com/some_subdir'
- @cmd.handle_options %W[--source #{s1} --source #{s2}]
+ @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3}]
- assert_equal [s1, s2], Gem.sources
+ assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources
end
def test_update_sources_option
@@ -77,7 +78,7 @@ class TestGemLocalRemoteOptions < RubyGemTestCase
@cmd.handle_options %W[--source #{s1}]
end
- assert_equal %w[http://gems.example.com], Gem.sources
+ assert_equal [@gem_repo], Gem.sources
end
end
diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb
index ddadeb9fcf..1d2103bd06 100644
--- a/test/rubygems/test_gem_remote_fetcher.rb
+++ b/test/rubygems/test_gem_remote_fetcher.rb
@@ -24,7 +24,7 @@ require 'rubygems/remote_fetcher'
# Note that the proxy server is not a *real* proxy server. But our
# software doesn't really care, as long as we hit the proxy URL when a
# proxy is configured.
-#
+
class TestGemRemoteFetcher < RubyGemTestCase
include Gem::DefaultUserInteraction
@@ -105,7 +105,7 @@ gems:
@a1, @a1_gem = util_gem 'a', '1' do |s| s.executables << 'a_bin' end
- Gem::RemoteFetcher.instance_variable_set :@fetcher, nil
+ Gem::RemoteFetcher.fetcher = nil
end
def test_self_fetcher
@@ -144,7 +144,7 @@ gems:
def test_fetch_size_socket_error
fetcher = Gem::RemoteFetcher.new nil
- def fetcher.connect_to(host, port)
+ def fetcher.connection_for(uri)
raise SocketError
end
@@ -153,7 +153,8 @@ gems:
fetcher.fetch_size uri
end
- assert_equal "SocketError (SocketError)\n\tgetting size of #{uri}", e.message
+ assert_equal "SocketError (SocketError)\n\tfetching size (#{uri})",
+ e.message
end
def test_no_proxy
@@ -182,7 +183,7 @@ gems:
@test_data
end
- raise Gem::RemoteFetcher::FetchError, "haha!"
+ raise Gem::RemoteFetcher::FetchError.new("haha!", nil)
end
end
@@ -371,7 +372,8 @@ gems:
fetcher.fetch_path 'uri'
end
- assert_equal 'EOFError: EOFError reading uri', e.message
+ assert_equal 'EOFError: EOFError (uri)', e.message
+ assert_equal 'uri', e.uri
end
def test_fetch_path_socket_error
@@ -383,7 +385,8 @@ gems:
fetcher.fetch_path 'uri'
end
- assert_equal 'SocketError: SocketError reading uri', e.message
+ assert_equal 'SocketError: SocketError (uri)', e.message
+ assert_equal 'uri', e.uri
end
def test_fetch_path_system_call_error
@@ -397,8 +400,9 @@ gems:
fetcher.fetch_path 'uri'
end
- assert_match %r|ECONNREFUSED:.*connect\(2\) reading uri\z|,
+ assert_match %r|ECONNREFUSED:.*connect\(2\) \(uri\)\z|,
e.message
+ assert_equal 'uri', e.uri
end
def test_get_proxy_from_env_empty
@@ -494,7 +498,8 @@ gems:
fetcher.send :open_uri_or_path, 'http://gems.example.com/redirect'
end
- assert_equal 'too many redirects', e.message
+ assert_equal 'too many redirects (http://gems.example.com/redirect)',
+ e.message
end
def test_zip
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
index 24f88bf59e..dcdc766f0f 100644
--- a/test/rubygems/test_gem_server.rb
+++ b/test/rubygems/test_gem_server.rb
@@ -14,34 +14,69 @@ class TestGemServer < RubyGemTestCase
super
@a1 = quick_gem 'a', '1'
+ @a2 = quick_gem 'a', '2'
@server = Gem::Server.new Gem.dir, process_based_port, false
@req = WEBrick::HTTPRequest.new :Logger => nil
@res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
end
- def test_quick_index
- data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
+ def test_Marshal
+ data = StringIO.new "GET /Marshal.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
@req.parse data
- @server.quick @req, @res
+ @server.Marshal @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
- assert_equal 'text/plain', @res['content-type']
- assert_equal "a-1", @res.body
+ assert_equal 'application/octet-stream', @res['content-type']
+
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
+
+ assert_equal si, Marshal.load(@res.body)
end
- def test_quick_index_rz
- data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
+ def test_Marshal_Z
+ data = StringIO.new "GET /Marshal.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
@req.parse data
- @server.quick @req, @res
+ @server.Marshal @req, @res
assert_equal 200, @res.status, @res.body
assert_match %r| \d\d:\d\d:\d\d |, @res['date']
- assert_equal 'text/plain', @res['content-type']
- assert_equal "a-1", Zlib::Inflate.inflate(@res.body)
+ assert_equal 'application/x-deflate', @res['content-type']
+
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
+
+ assert_equal si, Marshal.load(Gem.inflate(@res.body))
+ end
+
+ def test_latest_specs
+ data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.latest_specs @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/octet-stream', @res['content-type']
+ assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
+ Marshal.load(@res.body)
+ end
+
+ def test_latest_specs_gz
+ data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.latest_specs @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/x-gzip', @res['content-type']
+ assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
+ Marshal.load(Gem.gunzip(@res.body))
end
def test_quick_a_1_gemspec_rz
@@ -52,17 +87,15 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
- assert_equal 'text/plain', @res['content-type']
+ assert_equal 'application/x-deflate', @res['content-type']
- spec = YAML.load Zlib::Inflate.inflate(@res.body)
+ spec = YAML.load Gem.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
end
def test_quick_a_1_mswin32_gemspec_rz
a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
- si = Gem::SourceIndex.new @a1.full_name => @a1, a1_p.full_name => a1_p
- @server.source_index = si
data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
@req.parse data
@@ -71,9 +104,9 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
- assert_equal 'text/plain', @res['content-type']
+ assert_equal 'application/x-deflate', @res['content-type']
- spec = YAML.load Zlib::Inflate.inflate(@res.body)
+ spec = YAML.load Gem.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
assert_equal Gem::Platform.local, spec.platform
@@ -81,8 +114,6 @@ class TestGemServer < RubyGemTestCase
def test_quick_common_substrings
ab1 = quick_gem 'ab', '1'
- si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1
- @server.source_index = si
data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
@req.parse data
@@ -91,14 +122,62 @@ class TestGemServer < RubyGemTestCase
assert_equal 200, @res.status, @res.body
assert @res['date']
- assert_equal 'text/plain', @res['content-type']
+ assert_equal 'application/x-deflate', @res['content-type']
- spec = YAML.load Zlib::Inflate.inflate(@res.body)
+ spec = YAML.load Gem.inflate(@res.body)
assert_equal 'a', spec.name
assert_equal Gem::Version.new(1), spec.version
end
- def test_quick_z_9_gemspec_rz
+ def test_quick_index
+ data = StringIO.new "GET /quick/index HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'text/plain', @res['content-type']
+ assert_equal "a-1\na-2", @res.body
+ end
+
+ def test_quick_index_rz
+ data = StringIO.new "GET /quick/index.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/x-deflate', @res['content-type']
+ assert_equal "a-1\na-2", Gem.inflate(@res.body)
+ end
+
+ def test_quick_latest_index
+ data = StringIO.new "GET /quick/latest_index HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'text/plain', @res['content-type']
+ assert_equal 'a-2', @res.body
+ end
+
+ def test_quick_latest_index_rz
+ data = StringIO.new "GET /quick/latest_index.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/x-deflate', @res['content-type']
+ assert_equal 'a-2', Gem.inflate(@res.body)
+ end
+
+ def test_quick_missing
data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
@req.parse data
@@ -111,5 +190,112 @@ class TestGemServer < RubyGemTestCase
assert_equal 404, @res.status
end
+ def test_quick_marshal_a_1_gemspec_rz
+ data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert @res['date']
+ assert_equal 'application/x-deflate', @res['content-type']
+
+ spec = Marshal.load Gem.inflate(@res.body)
+ assert_equal 'a', spec.name
+ assert_equal Gem::Version.new(1), spec.version
+ end
+
+ def test_quick_marshal_a_1_mswin32_gemspec_rz
+ a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end
+
+ data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.quick @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert @res['date']
+ assert_equal 'application/x-deflate', @res['content-type']
+
+ spec = Marshal.load Gem.inflate(@res.body)
+ assert_equal 'a', spec.name
+ assert_equal Gem::Version.new(1), spec.version
+ assert_equal Gem::Platform.local, spec.platform
+ end
+
+
+ def test_root
+ data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.root @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'text/html', @res['content-type']
+ end
+
+ def test_specs
+ data = StringIO.new "GET /specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.specs @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/octet-stream', @res['content-type']
+
+ assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
+ ['a', Gem::Version.new(2), Gem::Platform::RUBY]],
+ Marshal.load(@res.body)
+ end
+
+ def test_specs_gz
+ data = StringIO.new "GET /specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.specs @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/x-gzip', @res['content-type']
+
+ assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
+ ['a', Gem::Version.new(2), Gem::Platform::RUBY]],
+ Marshal.load(Gem.gunzip(@res.body))
+ end
+
+ def test_yaml
+ data = StringIO.new "GET /yaml.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.yaml @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'text/plain', @res['content-type']
+
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
+
+ assert_equal si, YAML.load(@res.body)
+ end
+
+ def test_yaml_Z
+ data = StringIO.new "GET /yaml.#{Gem.marshal_version}.Z HTTP/1.0\r\n\r\n"
+ @req.parse data
+
+ @server.yaml @req, @res
+
+ assert_equal 200, @res.status, @res.body
+ assert_match %r| \d\d:\d\d:\d\d |, @res['date']
+ assert_equal 'application/x-deflate', @res['content-type']
+
+ si = Gem::SourceIndex.new
+ si.add_specs @a1, @a2
+
+ assert_equal si, YAML.load(Gem.inflate(@res.body))
+ end
+
end
diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb
index 140f3ad067..adb9037caa 100644
--- a/test/rubygems/test_gem_source_index.rb
+++ b/test/rubygems/test_gem_source_index.rb
@@ -23,6 +23,141 @@ class TestGemSourceIndex < RubyGemTestCase
util_setup_fake_fetcher
end
+ def test_self_from_gems_in
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.rm_r spec_dir
+
+ FileUtils.mkdir_p spec_dir
+
+ a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end
+
+ spec_file = File.join spec_dir, "#{a1.full_name}.gemspec"
+
+ File.open spec_file, 'w' do |fp|
+ fp.write a1.to_ruby
+ end
+
+ si = Gem::SourceIndex.from_gems_in spec_dir
+
+ assert_equal [spec_dir], si.spec_dirs
+ assert_equal [a1.full_name], si.gems.keys
+ end
+
+ def test_self_load_specification
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.rm_r spec_dir
+
+ FileUtils.mkdir_p spec_dir
+
+ a1 = quick_gem 'a', '1' do |spec| spec.author = 'author 1' end
+
+ spec_file = File.join spec_dir, "#{a1.full_name}.gemspec"
+
+ File.open spec_file, 'w' do |fp|
+ fp.write a1.to_ruby
+ end
+
+ spec = Gem::SourceIndex.load_specification spec_file
+
+ assert_equal a1.author, spec.author
+ end
+
+ def test_self_load_specification_exception
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.mkdir_p spec_dir
+
+ spec_file = File.join spec_dir, 'a-1.gemspec'
+
+ File.open spec_file, 'w' do |fp|
+ fp.write 'raise Exception, "epic fail"'
+ end
+
+ use_ui @ui do
+ assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
+ end
+
+ assert_equal '', @ui.output
+
+ expected = <<-EOF
+WARNING: #<Exception: epic fail>
+raise Exception, "epic fail"
+WARNING: Invalid .gemspec format in '#{spec_file}'
+ EOF
+
+ assert_equal expected, @ui.error
+ end
+
+ def test_self_load_specification_interrupt
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.mkdir_p spec_dir
+
+ spec_file = File.join spec_dir, 'a-1.gemspec'
+
+ File.open spec_file, 'w' do |fp|
+ fp.write 'raise Interrupt, "^C"'
+ end
+
+ use_ui @ui do
+ assert_raise Interrupt do
+ Gem::SourceIndex.load_specification(spec_file)
+ end
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+ end
+
+ def test_self_load_specification_syntax_error
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.mkdir_p spec_dir
+
+ spec_file = File.join spec_dir, 'a-1.gemspec'
+
+ File.open spec_file, 'w' do |fp|
+ fp.write '1 +'
+ end
+
+ use_ui @ui do
+ assert_equal nil, Gem::SourceIndex.load_specification(spec_file)
+ end
+
+ assert_equal '', @ui.output
+
+ expected = <<-EOF
+WARNING: compile error
+#{spec_file}:1: syntax error, unexpected $end
+WARNING: 1 +
+ EOF
+
+ assert_equal expected, @ui.error
+ end
+
+ def test_self_load_specification_system_exit
+ spec_dir = File.join @gemhome, 'specifications'
+
+ FileUtils.mkdir_p spec_dir
+
+ spec_file = File.join spec_dir, 'a-1.gemspec'
+
+ File.open spec_file, 'w' do |fp|
+ fp.write 'raise SystemExit, "bye-bye"'
+ end
+
+ use_ui @ui do
+ assert_raise SystemExit do
+ Gem::SourceIndex.load_specification(spec_file)
+ end
+ end
+
+ assert_equal '', @ui.output
+ assert_equal '', @ui.error
+ end
+
def test_create_from_directory
# TODO
end
@@ -43,16 +178,16 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
assert paths.empty?, paths.join(', ')
end
def test_fetch_bulk_index_error
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/yaml.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/yaml"] = proc { raise SocketError }
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] = proc { raise SocketError }
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = proc { raise SocketError }
+ @fetcher.data["#{@gem_repo}yaml.Z"] = proc { raise SocketError }
+ @fetcher.data["#{@gem_repo}yaml"] = proc { raise SocketError }
e = assert_raise Gem::RemoteSourceException do
use_ui @ui do
@@ -62,10 +197,10 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}/yaml.Z", paths.shift
- assert_equal "#{@gem_repo}/yaml", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
+ assert_equal "#{@gem_repo}yaml.Z", paths.shift
+ assert_equal "#{@gem_repo}yaml", paths.shift
assert paths.empty?, paths.join(', ')
@@ -74,12 +209,12 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_fetch_bulk_index_fallback
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] =
proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] =
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] =
proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/yaml.Z"] = proc { raise SocketError }
- @fetcher.data["#{@gem_repo}/yaml"] = @source_index.to_yaml
+ @fetcher.data["#{@gem_repo}yaml.Z"] = proc { raise SocketError }
+ @fetcher.data["#{@gem_repo}yaml"] = @source_index.to_yaml
use_ui @ui do
fetched_index = @source_index.fetch_bulk_index @uri
@@ -90,10 +225,10 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}/yaml.Z", paths.shift
- assert_equal "#{@gem_repo}/yaml", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
+ assert_equal "#{@gem_repo}yaml.Z", paths.shift
+ assert_equal "#{@gem_repo}yaml", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -102,8 +237,8 @@ class TestGemSourceIndex < RubyGemTestCase
marshal = @source_index.dump
marshal[0] = (Marshal::MAJOR_VERSION - 1).chr
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = marshal
- @fetcher.data["#{@gem_repo}/yaml"] = @source_index.to_yaml
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = marshal
+ @fetcher.data["#{@gem_repo}yaml"] = @source_index.to_yaml
use_ui @ui do
fetched_index = @source_index.fetch_bulk_index @uri
@@ -114,10 +249,10 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
- assert_equal "#{@gem_repo}/yaml.Z", paths.shift
- assert_equal "#{@gem_repo}/yaml", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
+ assert_equal "#{@gem_repo}yaml.Z", paths.shift
+ assert_equal "#{@gem_repo}yaml", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -133,8 +268,8 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -143,8 +278,8 @@ class TestGemSourceIndex < RubyGemTestCase
index = util_zip @gem_names
latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = index
+ @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
quick_index = @source_index.fetch_quick_index @uri, false
assert_equal [@a2.full_name, @b2.full_name].sort,
@@ -152,7 +287,7 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -161,8 +296,8 @@ class TestGemSourceIndex < RubyGemTestCase
index = util_zip @gem_names
latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = index
+ @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
quick_index = @source_index.fetch_quick_index @uri, true
assert_equal [@a1.full_name, @a2.full_name, @b2.full_name].sort,
@@ -170,13 +305,13 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert paths.empty?, paths.join(', ')
end
def test_fetch_quick_index_error
- @fetcher.data["#{@gem_repo}/quick/index.rz"] =
+ @fetcher.data["#{@gem_repo}quick/index.rz"] =
proc { raise Exception }
e = assert_raise Gem::OperationNotSupportedError do
@@ -187,7 +322,7 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -195,22 +330,22 @@ class TestGemSourceIndex < RubyGemTestCase
def test_fetch_quick_index_fallback
index = util_zip @gem_names
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = index
quick_index = @source_index.fetch_quick_index @uri, false
assert_equal @gem_names.split, quick_index.sort
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert paths.empty?, paths.join(', ')
end
def test_fetch_quick_index_subdir
latest_index = util_zip [@a2.full_name, @b2.full_name].join("\n")
- repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
+ repo = URI.parse "#{@gem_repo}~nobody/mirror/"
@fetcher.data["#{repo}quick/latest_index.rz"] = latest_index
@@ -226,7 +361,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_fetch_single_spec
- a1_spec_url = "#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
+ a1_spec_url = "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
@fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
spec = @source_index.send :fetch_single_spec, URI.parse(@gem_repo),
@@ -242,7 +377,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_fetch_single_spec_subdir
- repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
+ repo = URI.parse "#{@gem_repo}~nobody/mirror/"
a1_spec_url = "#{repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz"
@fetcher.data[a1_spec_url] = util_zip Marshal.dump(@a1)
@@ -259,7 +394,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_fetch_single_spec_yaml
- a1_spec_url = "#{@gem_repo}/quick/#{@a1.full_name}.gemspec.rz"
+ a1_spec_url = "#{@gem_repo}quick/#{@a1.full_name}.gemspec.rz"
@fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
repo = URI.parse @gem_repo
@@ -270,14 +405,14 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{@a1.full_name}.gemspec.rz", paths.shift
assert_equal a1_spec_url, paths.shift
assert paths.empty?, paths.join(', ')
end
def test_fetch_single_spec_yaml_subdir
- repo = URI.parse "#{@gem_repo}/~nobody/mirror/"
+ repo = URI.parse "#{@gem_repo}~nobody/mirror/"
a1_spec_url = "#{repo}quick/#{@a1.full_name}.gemspec.rz"
@fetcher.data[a1_spec_url] = util_zip @a1.to_yaml
@@ -377,12 +512,12 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_outdated
- util_setup_source_info_cache
+ util_setup_spec_fetcher
assert_equal [], @source_index.outdated
updated = quick_gem @a2.name, (@a2.version.bump)
- util_setup_source_info_cache updated
+ util_setup_spec_fetcher updated
assert_equal [updated.name], @source_index.outdated
@@ -390,7 +525,7 @@ class TestGemSourceIndex < RubyGemTestCase
s.platform = Gem::Platform.new 'x86-other_platform1'
end
- util_setup_source_info_cache updated, updated_platform
+ util_setup_spec_fetcher updated, updated_platform
assert_equal [updated_platform.name], @source_index.outdated
end
@@ -411,6 +546,16 @@ class TestGemSourceIndex < RubyGemTestCase
assert source_index.gems.include?(@a1.full_name)
end
+ def test_refresh_bang_not_from_dir
+ source_index = Gem::SourceIndex.new
+
+ e = assert_raise RuntimeError do
+ source_index.refresh!
+ end
+
+ assert_equal 'source index not created from disk', e.message
+ end
+
def test_remove_extra
@source_index.add_spec @a1
@source_index.add_spec @a2
@@ -516,8 +661,8 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -528,7 +673,7 @@ class TestGemSourceIndex < RubyGemTestCase
latest_names = [@a2, @a_evil9, @b2, @c1_2].map { |s| s.full_name }
latest_index = util_zip latest_names.join("\n")
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = latest_index
+ @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = latest_index
marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
"#{@b2.full_name}.gemspec.rz"
@@ -541,7 +686,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/latest_index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/latest_index.rz", paths.shift
assert_equal marshal_uri, paths.shift
assert paths.empty?, paths.join(', ')
@@ -554,7 +699,7 @@ class TestGemSourceIndex < RubyGemTestCase
Gem.configuration = Gem::ConfigFile.new([])
quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
"#{@b2.full_name}.gemspec.rz"
@@ -567,7 +712,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert_equal marshal_uri, paths.shift
assert paths.empty?, paths.join(', ')
@@ -580,12 +725,12 @@ class TestGemSourceIndex < RubyGemTestCase
Gem.configuration = Gem::ConfigFile.new([])
quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
"#{@b2.full_name}.gemspec.rz"
- yaml_uri = "#{@gem_repo}/quick/#{@b2.full_name}.gemspec.rz"
+ yaml_uri = "#{@gem_repo}quick/#{@b2.full_name}.gemspec.rz"
@fetcher.data[yaml_uri] = util_zip @b2.to_yaml
use_ui @ui do
@@ -595,7 +740,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert_equal marshal_uri, paths.shift
assert_equal yaml_uri, paths.shift
@@ -609,7 +754,7 @@ class TestGemSourceIndex < RubyGemTestCase
Gem.configuration = Gem::ConfigFile.new([])
quick_index = util_zip @all_gem_names.join("\n")
- @fetcher.data["#{@gem_repo}/quick/index.rz"] = quick_index
+ @fetcher.data["#{@gem_repo}quick/index.rz"] = quick_index
marshal_uri = File.join @gem_repo, "quick", "Marshal.#{@marshal_version}",
"#{@b2.full_name}.gemspec.rz"
@@ -617,7 +762,7 @@ class TestGemSourceIndex < RubyGemTestCase
marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
@fetcher.data[marshal_uri] = util_zip marshal_data
- yaml_uri = "#{@gem_repo}/quick/#{@b2.full_name}.gemspec.rz"
+ yaml_uri = "#{@gem_repo}quick/#{@b2.full_name}.gemspec.rz"
@fetcher.data[yaml_uri] = util_zip @b2.to_yaml
use_ui @ui do
@@ -627,7 +772,7 @@ class TestGemSourceIndex < RubyGemTestCase
end
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
assert_equal marshal_uri, paths.shift
assert_equal yaml_uri, paths.shift
@@ -637,14 +782,14 @@ class TestGemSourceIndex < RubyGemTestCase
end
def test_update_subdir
- @gem_repo = @gem_repo + "/subdir"
+ @gem_repo = @gem_repo + 'subdir/'
util_setup_bulk_fetch true
@source_index.gems.replace({})
assert_equal [], @source_index.gems.keys.sort
- uri = @uri.to_s + "/subdir"
+ uri = @uri.to_s + 'subdir/'
use_ui @ui do
@source_index.update uri, true
@@ -656,8 +801,8 @@ class TestGemSourceIndex < RubyGemTestCase
paths = @fetcher.paths
- assert_equal "#{@gem_repo}/quick/index.rz", paths.shift
- assert_equal "#{@gem_repo}/Marshal.#{@marshal_version}.Z", paths.shift
+ assert_equal "#{@gem_repo}quick/index.rz", paths.shift
+ assert_equal "#{@gem_repo}Marshal.#{@marshal_version}.Z", paths.shift
assert paths.empty?, paths.join(', ')
end
@@ -684,9 +829,9 @@ class TestGemSourceIndex < RubyGemTestCase
source_index = @source_index.dump
if compressed then
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] = util_zip source_index
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] = util_zip source_index
else
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = source_index
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = source_index
end
end
diff --git a/test/rubygems/test_gem_source_info_cache.rb b/test/rubygems/test_gem_source_info_cache.rb
index 523b404280..83cd100a9d 100644
--- a/test/rubygems/test_gem_source_info_cache.rb
+++ b/test/rubygems/test_gem_source_info_cache.rb
@@ -36,6 +36,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
def teardown
super
Gem.sources.replace @original_sources
+ Gem::SourceInfoCache.instance_variable_set :@cache, nil
end
def test_self_cache_refreshes
@@ -43,7 +44,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
si = Gem::SourceIndex.new
si.add_spec @a1
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
Gem.sources.replace %W[#{@gem_repo}]
@@ -52,8 +53,9 @@ class TestGemSourceInfoCache < RubyGemTestCase
assert_kind_of Gem::SourceInfoCache, Gem::SourceInfoCache.cache
assert_equal Gem::SourceInfoCache.cache.object_id,
Gem::SourceInfoCache.cache.object_id
- assert_match %r|Bulk updating|, @ui.output
end
+
+ assert_match %r|Bulk updating|, @ui.output
end
def test_self_cache_skips_refresh_based_on_configuration
@@ -61,7 +63,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
si = Gem::SourceIndex.new
si.add_spec @a1
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
Gem.sources.replace %w[#{@gem_repo}]
@@ -78,7 +80,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
si = Gem::SourceIndex.new
si.add_spec @a1
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
Gem::SourceInfoCache.instance_variable_set :@cache, nil
sice = Gem::SourceInfoCacheEntry.new si, 0
@@ -106,7 +108,7 @@ class TestGemSourceInfoCache < RubyGemTestCase
end
def test_cache_data_irreparable
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @source_index.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = @source_index.dump
data = { @gem_repo => { 'totally' => 'borked' } }
diff --git a/test/rubygems/test_gem_source_info_cache_entry.rb b/test/rubygems/test_gem_source_info_cache_entry.rb
index c1194e34bc..6986c9cd7f 100644
--- a/test/rubygems/test_gem_source_info_cache_entry.rb
+++ b/test/rubygems/test_gem_source_info_cache_entry.rb
@@ -15,9 +15,9 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
end
def test_refresh
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}.Z"] =
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] =
proc { raise }
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = @si.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = @si.dump
use_ui @ui do
@sic_e.refresh @gem_repo, true
@@ -30,18 +30,20 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
a1_name = @a1.full_name
a2_name = @a2.full_name
- @fetcher.data["#{@gem_repo}/quick/index.rz"] =
+ @fetcher.data["#{@gem_repo}quick/index.rz"] =
util_zip [a1_name, a2_name].join("\n")
- @fetcher.data["#{@gem_repo}/quick/latest_index.rz"] = util_zip a2_name
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
- @fetcher.data["#{@gem_repo}/quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
- @fetcher.data["#{@gem_repo}/Marshal.#{Gem.marshal_version}"] =
+ @fetcher.data["#{@gem_repo}quick/latest_index.rz"] = util_zip a2_name
+ @fetcher.data["#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a1_name}.gemspec.rz"] = util_zip Marshal.dump(@a1)
+ @fetcher.data["#{@gem_repo}quick/Marshal.#{Gem.marshal_version}/#{a2_name}.gemspec.rz"] = util_zip Marshal.dump(@a2)
+ @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
Marshal.dump @si
sic_e = Gem::SourceInfoCacheEntry.new Gem::SourceIndex.new, 0
+ assert_equal [], sic_e.source_index.map { |n,| n }
+
use_ui @ui do
- sic_e.refresh @gem_repo, false
+ assert sic_e.refresh(@gem_repo, false)
end
assert_equal [a2_name], sic_e.source_index.map { |n,| n }.sort
@@ -63,7 +65,7 @@ class TestGemSourceInfoCacheEntry < RubyGemTestCase
si = Gem::SourceIndex.new
si.add_spec @a1
si.add_spec @b2
- @fetcher.data["#{@gem_repo}/Marshal.#{@marshal_version}"] = si.dump
+ @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = si.dump
use_ui @ui do
@sic_e.refresh @gem_repo, true
diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb
new file mode 100644
index 0000000000..7539d0ff4c
--- /dev/null
+++ b/test/rubygems/test_gem_spec_fetcher.rb
@@ -0,0 +1,303 @@
+require 'test/unit'
+require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
+require 'rubygems/spec_fetcher'
+
+class TestGemSpecFetcher < RubyGemTestCase
+
+ def setup
+ super
+
+ @uri = URI.parse @gem_repo
+
+ util_setup_fake_fetcher
+
+ @source_index.add_spec @pl1
+
+ @specs = @source_index.gems.sort.map do |name, spec|
+ [spec.name, spec.version, spec.original_platform]
+ end.sort
+
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] =
+ util_gzip(Marshal.dump(@specs))
+
+ @latest_specs = @source_index.latest_specs.sort.map do |spec|
+ [spec.name, spec.version, spec.original_platform]
+ end
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] =
+ util_gzip(Marshal.dump(@latest_specs))
+
+ @sf = Gem::SpecFetcher.new
+ end
+
+ def test_fetch_all
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a2))
+
+ dep = Gem::Dependency.new 'a', 1
+ specs_and_sources = @sf.fetch dep, true
+
+ spec_names = specs_and_sources.map do |spec, source_uri|
+ [spec.full_name, source_uri]
+ end
+
+ expected = [[@a1.full_name, @gem_repo], [@a2.full_name, @gem_repo]]
+
+ assert_equal expected, spec_names
+
+ assert_same specs_and_sources.first.last, specs_and_sources.last.last
+ end
+
+ def test_fetch_latest
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a1))
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a2.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a2))
+
+ dep = Gem::Dependency.new 'a', 1
+ specs_and_sources = @sf.fetch dep
+
+ spec_names = specs_and_sources.map do |spec, source_uri|
+ [spec.full_name, source_uri]
+ end
+
+ assert_equal [[@a2.full_name, @gem_repo]], spec_names
+ end
+
+ def test_fetch_legacy_repo
+ @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] = nil
+ @fetcher.data["#{@gem_repo}yaml"] = ''
+ util_setup_source_info_cache @a1, @a2
+
+ dep = Gem::Dependency.new 'a', 1
+ specs = nil
+
+ use_ui @ui do
+ specs = @sf.fetch dep, true
+ end
+
+ expected = <<-EOF
+WARNING: RubyGems 1.2+ index not found for:
+\thttp://gems.example.com/
+
+RubyGems will revert to legacy indexes degrading performance.
+ EOF
+
+ assert_equal expected, @ui.error
+
+ specs = specs.map { |spec, source_uri| [spec.full_name, source_uri] }
+
+ expected = [
+ [@a1.full_name, @gem_repo],
+ [@a2.full_name, @gem_repo],
+ ]
+
+ assert_equal expected, specs
+ end
+
+ def test_fetch_platform
+ util_set_arch 'i386-linux'
+
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@pl1))
+
+ dep = Gem::Dependency.new 'pl', 1
+ specs_and_sources = @sf.fetch dep
+
+ spec_names = specs_and_sources.map do |spec, source_uri|
+ [spec.full_name, source_uri]
+ end
+
+ assert_equal [[@pl1.full_name, @gem_repo]], spec_names
+ end
+
+ def test_fetch_spec
+ spec_uri = "#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec"
+ @fetcher.data["#{spec_uri}.rz"] = util_zip(Marshal.dump(@a1))
+
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
+ assert_equal @a1.full_name, spec.full_name
+
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
+
+ cache_file = File.join cache_dir, "#{@a1.full_name}.gemspec"
+
+ assert File.exist?(cache_file)
+ end
+
+ def test_fetch_spec_cached
+ spec_uri = "#{@gem_repo}/#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec"
+ @fetcher.data["#{spec_uri}.rz"] = nil
+
+ cache_dir = @sf.cache_dir URI.parse(spec_uri)
+ FileUtils.mkdir_p cache_dir
+
+ cache_file = File.join cache_dir, "#{@a1.full_name}.gemspec"
+
+ open cache_file, 'wb' do |io|
+ Marshal.dump @a1, io
+ end
+
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), 'ruby'], @uri
+ assert_equal @a1.full_name, spec.full_name
+ end
+
+ def test_fetch_spec_platform
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@pl1.original_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@pl1))
+
+ spec = @sf.fetch_spec ['pl', Gem::Version.new(1), 'i386-linux'], @uri
+
+ assert_equal @pl1.full_name, spec.full_name
+ end
+
+ def test_fetch_spec_platform_ruby
+ @fetcher.data["#{@gem_repo}#{Gem::MARSHAL_SPEC_DIR}#{@a1.full_name}.gemspec.rz"] =
+ util_zip(Marshal.dump(@a1))
+
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), nil], @uri
+ assert_equal @a1.full_name, spec.full_name
+
+ spec = @sf.fetch_spec ['a', Gem::Version.new(1), ''], @uri
+ assert_equal @a1.full_name, spec.full_name
+ end
+
+ def test_find_matching_all
+ dep = Gem::Dependency.new 'a', 1
+ specs = @sf.find_matching dep, true
+
+ expected = [
+ [['a', Gem::Version.new(1), Gem::Platform::RUBY], @gem_repo],
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
+ ]
+
+ assert_equal expected, specs
+ end
+
+ def test_find_matching_latest
+ dep = Gem::Dependency.new 'a', 1
+ specs = @sf.find_matching dep
+
+ expected = [
+ [['a', Gem::Version.new(2), Gem::Platform::RUBY], @gem_repo],
+ ]
+
+ assert_equal expected, specs
+ end
+
+ def test_find_matching_platform
+ util_set_arch 'i386-linux'
+
+ dep = Gem::Dependency.new 'pl', 1
+ specs = @sf.find_matching dep
+
+ expected = [
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
+ ]
+
+ assert_equal expected, specs
+
+ util_set_arch 'i386-freebsd6'
+
+ dep = Gem::Dependency.new 'pl', 1
+ specs = @sf.find_matching dep
+
+ assert_equal [], specs
+ end
+
+ def test_find_all_platforms
+ util_set_arch 'i386-freebsd6'
+
+ dep = Gem::Dependency.new 'pl', 1
+ specs = @sf.find_matching dep, false, false
+
+ expected = [
+ [['pl', Gem::Version.new(1), 'i386-linux'], @gem_repo],
+ ]
+
+ assert_equal expected, specs
+ end
+
+ def test_list
+ specs = @sf.list
+
+ assert_equal [@uri], specs.keys
+ assert_equal @latest_specs, specs[@uri].sort
+ end
+
+ def test_list_all
+ specs = @sf.list true
+
+ assert_equal [@uri], specs.keys
+
+ assert_equal @specs, specs[@uri].sort
+ end
+
+ def test_list_cache
+ specs = @sf.list
+
+ assert !specs[@uri].empty?
+
+ @fetcher.data["#{@gem_repo}/latest_specs.#{Gem.marshal_version}.gz"] = nil
+
+ cached_specs = @sf.list
+
+ assert_equal specs, cached_specs
+ end
+
+ def test_list_cache_all
+ specs = @sf.list true
+
+ assert !specs[@uri].empty?
+
+ @fetcher.data["#{@gem_repo}/specs.#{Gem.marshal_version}.gz"] = nil
+
+ cached_specs = @sf.list true
+
+ assert_equal specs, cached_specs
+ end
+
+ def test_load_specs
+ specs = @sf.load_specs @uri, 'specs'
+
+ expected = [
+ ['a', Gem::Version.new(1), Gem::Platform::RUBY],
+ ['a', Gem::Version.new(2), Gem::Platform::RUBY],
+ ['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
+ ['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
+ ['pl', Gem::Version.new(1), 'i386-linux'],
+ ]
+
+ assert_equal expected, specs
+
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com%80'
+ assert File.exist?(cache_dir), "#{cache_dir} does not exist"
+
+ cache_file = File.join cache_dir, "specs.#{Gem.marshal_version}"
+ assert File.exist?(cache_file)
+ end
+
+ def test_load_specs_cached
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] =
+ ' ' * Marshal.dump(@latest_specs).length
+
+ cache_dir = File.join Gem.user_home, '.gem', 'specs', 'gems.example.com:80'
+
+ FileUtils.mkdir_p cache_dir
+
+ cache_file = File.join cache_dir, "latest_specs.#{Gem.marshal_version}"
+
+ open cache_file, 'wb' do |io|
+ Marshal.dump @latest_specs, io
+ end
+
+ specs = @sf.load_specs @uri, 'specs'
+
+ assert_equal @specs, specs
+ end
+
+end
+
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 20eb12479f..003ded7bc0 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -213,6 +213,15 @@ end
assert_equal 'old_platform', same_spec.original_platform
end
+ def test_add_dependency_with_explicit_type
+ gem = quick_gem "awesome", "1.0" do |awesome|
+ awesome.add_development_dependency "monkey"
+ end
+
+ monkey = gem.dependencies.detect { |d| d.name == "monkey" }
+ assert_equal(:development, monkey.type)
+ end
+
def test_author
assert_equal 'A User', @a1.author
end
@@ -282,6 +291,20 @@ end
assert_equal [rake, jabber, pqa], @a1.dependencies
end
+ def test_dependencies_scoped_by_type
+ gem = quick_gem "awesome", "1.0" do |awesome|
+ awesome.add_runtime_dependency "bonobo", []
+ awesome.add_development_dependency "monkey", []
+ end
+
+ bonobo = Gem::Dependency.new("bonobo", [])
+ monkey = Gem::Dependency.new("monkey", [], :development)
+
+ assert_equal([bonobo, monkey], gem.dependencies)
+ assert_equal([bonobo], gem.runtime_dependencies)
+ assert_equal([monkey], gem.development_dependencies)
+ end
+
def test_description
assert_equal 'This is a test description', @a1.description
end
@@ -423,6 +446,15 @@ end
@a1.full_gem_path
end
+ def test_full_gem_path_double_slash
+ gemhome = @gemhome.sub(/\w\//, '\&/')
+ @a1.loaded_from = File.join gemhome, 'specifications',
+ "#{@a1.full_name}.gemspec"
+
+ assert_equal File.join(@gemhome, 'gems', @a1.full_name),
+ @a1.full_gem_path
+ end
+
def test_full_name
assert_equal 'a-1', @a1.full_name
@@ -531,6 +563,17 @@ end
assert_equal ['A working computer'], @a1.requirements
end
+ def test_runtime_dependencies_legacy
+ # legacy gems don't have a type
+ @a1.runtime_dependencies.each do |dep|
+ dep.instance_variable_set :@type, nil
+ end
+
+ expected = %w[rake jabber4r pqa]
+
+ assert_equal expected, @a1.runtime_dependencies.map { |d| d.name }
+ end
+
def test_spaceship_name
s1 = quick_gem 'a', '1'
s2 = quick_gem 'b', '1'
@@ -570,6 +613,8 @@ end
end
def test_to_ruby
+ @a2.add_runtime_dependency 'b', '1'
+ @a2.dependencies.first.instance_variable_set :@type, nil
@a2.required_rubygems_version = Gem::Requirement.new '> 0'
ruby_code = @a2.to_ruby
@@ -578,8 +623,6 @@ end
s.name = %q{a}
s.version = \"2\"
- s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} if s.respond_to? :specification_version=
-
s.required_rubygems_version = Gem::Requirement.new(\"> 0\") if s.respond_to? :required_rubygems_version=
s.authors = [\"A User\"]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
@@ -591,6 +634,19 @@ end
s.require_paths = [\"lib\"]
s.rubygems_version = %q{#{Gem::RubyGemsVersion}}
s.summary = %q{this is a summary}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
+
+ if current_version >= 3 then
+ s.add_runtime_dependency(%q<b>, [\"= 1\"])
+ else
+ s.add_dependency(%q<b>, [\"= 1\"])
+ end
+ else
+ s.add_dependency(%q<b>, [\"= 1\"])
+ end
end
"
@@ -613,8 +669,6 @@ end
s.version = \"1\"
s.platform = Gem::Platform.new(#{expected_platform})
- s.specification_version = 2 if s.respond_to? :specification_version=
-
s.required_rubygems_version = Gem::Requirement.new(\">= 0\") if s.respond_to? :required_rubygems_version=
s.authors = [\"A User\"]
s.date = %q{#{Gem::Specification::TODAY.strftime "%Y-%m-%d"}}
@@ -633,9 +687,24 @@ end
s.summary = %q{this is a summary}
s.test_files = [\"test/suite.rb\"]
- s.add_dependency(%q<rake>, [\"> 0.4\"])
- s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
- s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if current_version >= 3 then
+ s.add_runtime_dependency(%q<rake>, [\"> 0.4\"])
+ s.add_runtime_dependency(%q<jabber4r>, [\"> 0.0.0\"])
+ s.add_runtime_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
+ else
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
+ end
+ else
+ s.add_dependency(%q<rake>, [\"> 0.4\"])
+ s.add_dependency(%q<jabber4r>, [\"> 0.0.0\"])
+ s.add_dependency(%q<pqa>, [\"> 0.4\", \"<= 0.6\"])
+ end
end
"
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb
index d6e41814ed..aadf0a39c8 100644
--- a/test/rubygems/test_gem_uninstaller.rb
+++ b/test/rubygems/test_gem_uninstaller.rb
@@ -15,6 +15,12 @@ class TestGemUninstaller < GemInstallerTestCase
end
end
+ def test_initialize_expand_path
+ uninstaller = Gem::Uninstaller.new nil, :install_dir => '/foo//bar'
+
+ assert_match %r|/foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
+ end
+
def test_remove_executables_force_keep
uninstaller = Gem::Uninstaller.new nil, :executables => false
@@ -39,5 +45,20 @@ class TestGemUninstaller < GemInstallerTestCase
assert_equal false, File.exist?(File.join(@gemhome, 'bin', 'executable'))
end
+ def test_path_ok_eh
+ uninstaller = Gem::Uninstaller.new nil
+
+ assert_equal true, uninstaller.path_ok?(@spec)
+ end
+
+ def test_path_ok_eh_legacy
+ uninstaller = Gem::Uninstaller.new nil
+
+ @spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
+ @spec.platform = 'legacy'
+
+ assert_equal true, uninstaller.path_ok?(@spec)
+ end
+
end
diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb
index 27c522c3d7..8d10700490 100644
--- a/test/rubygems/test_gem_version.rb
+++ b/test/rubygems/test_gem_version.rb
@@ -71,10 +71,14 @@ class TestGemVersion < RubyGemTestCase
end
def test_eql_eh
- v = Gem::Version.new("1.2")
+ v1_2 = Gem::Version.new '1.2'
+ v1_2_0 = Gem::Version.new '1.2.0'
+
+ assert_equal true, v1_2.eql?(@v1_2)
+ assert_equal true, @v1_2.eql?(v1_2)
- assert_equal true, v.eql?(@v1_2)
- assert_equal true, @v1_2.eql?(v)
+ assert_equal false, v1_2_0.eql?(@v1_2)
+ assert_equal false, @v1_2.eql?(v1_2_0)
assert_equal false, @v1_2.eql?(@v1_3)
assert_equal false, @v1_3.eql?(@v1_2)
@@ -91,8 +95,13 @@ class TestGemVersion < RubyGemTestCase
end
def test_hash
- v = Gem::Version.new("1.2")
- assert_equal v.hash, @v1_2.hash
+ v1_2 = Gem::Version.new "1.2"
+ v1_2_0 = Gem::Version.new "1.2.0"
+
+ assert_equal v1_2.hash, @v1_2.hash
+
+ assert_not_equal v1_2_0.hash, @v1_2.hash
+
assert_not_equal @v1_2.hash, @v1_3.hash
end
diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb
index 3c6448e470..da31d772eb 100644
--- a/test/rubygems/test_kernel.rb
+++ b/test/rubygems/test_kernel.rb
@@ -52,7 +52,7 @@ class TestKernel < RubyGemTestCase
gem 'a', '= 2'
end
- assert_match(/activate a \(= 2\)/, ex.message)
+ assert_match(/activate a \(= 2, runtime\)/, ex.message)
assert_match(/activated a-1/, ex.message)
assert $:.any? { |p| %r{a-1/lib} =~ p }