summaryrefslogtreecommitdiff
path: root/test/rubygems/gemutilities.rb
diff options
context:
space:
mode:
-rw-r--r--test/rubygems/gemutilities.rb122
1 files changed, 105 insertions, 17 deletions
@@ -8,24 +8,35 @@ at_exit { $SAFE = 1 }
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-require 'rubygems'
require 'fileutils'
begin
require 'minitest/unit'
-rescue LoadError
- warn "Install minitest gem"
raise
end
require 'tmpdir'
require 'uri'
require 'rubygems/package'
require 'rubygems/test_utilities'
require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui')
module Gem
- @ruby = ENV['RUBY']
-
def self.searcher=(searcher)
MUTEX.synchronize do @searcher = searcher end
end
@@ -64,6 +75,8 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
@latest_usrcache = File.join(@gemhome, ".gem", "latest_user_cache")
@userhome = File.join @tempdir, 'userhome'
@orig_ENV_HOME = ENV['HOME']
ENV['HOME'] = @userhome
Gem.instance_variable_set :@user_home, nil
@@ -85,7 +98,7 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::SpecFetcher.fetcher = nil
@orig_BASERUBY = Gem::ConfigMap[:BASERUBY]
- Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME]
@orig_arch = Gem::ConfigMap[:arch]
@@ -160,6 +173,13 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::Installer.new(gem, :wrappers => true).install
end
def prep_cache_files(lc)
@usr_si ||= Gem::SourceIndex.new
@usr_sice ||= Gem::SourceInfoCacheEntry.new @usr_si, 0
@@ -254,10 +274,8 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem::Builder.new(spec).build
end
- cache_dir = File.join(@gemhome, 'cache')
- FileUtils.mkdir_p cache_dir
FileUtils.mv "#{spec.full_name}.gem",
- File.join(cache_dir, "#{spec.original_name}.gem")
end
end
@@ -294,14 +312,30 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
out.string
end
- def util_make_gems
init = proc do |s|
s.files = %w[lib/code.rb]
s.require_paths = %w[lib]
end
- @a1 = quick_gem('a', '1', &init)
@a2 = quick_gem('a', '2', &init)
@a_evil9 = quick_gem('a_evil', '9', &init)
@b2 = quick_gem('b', '2', &init)
@c1_2 = quick_gem('c', '1.2', &init)
@@ -312,13 +346,23 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
s.instance_variable_set :@original_platform, 'i386-linux'
end
write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end
write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end
- [@a1, @a2, @a_evil9, @b2, @c1_2, @pl1].each { |spec| util_build_gem spec }
FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name)
@@ -338,26 +382,28 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
platform
end
- def util_setup_fake_fetcher
require 'zlib'
require 'socket'
require 'rubygems/remote_fetcher'
@fetcher = Gem::FakeFetcher.new
- util_make_gems
- @all_gems = [@a1, @a2, @a_evil9, @b2, @c1_2].sort
@all_gem_names = @all_gems.map { |gem| gem.full_name }
- gem_names = [@a1.full_name, @a2.full_name, @b2.full_name]
@gem_names = gem_names.sort.join("\n")
@source_index = Gem::SourceIndex.new
@source_index.add_spec @a1
@source_index.add_spec @a2
@source_index.add_spec @a_evil9
@source_index.add_spec @c1_2
Gem::RemoteFetcher.fetcher = @fetcher
end
@@ -400,7 +446,13 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
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
@@ -422,6 +474,42 @@ class RubyGemTestCase < MiniTest::Unit::TestCase
Gem.win_platform?
end
# NOTE Allow tests to use a random (but controlled) port number instead of
# a hardcoded one. This helps CI tools when running parallels builds on
# the same builder slave.