diff options
85 files changed, 1202 insertions, 713 deletions
@@ -1,3 +1,9 @@ #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. @@ -1,3 +1,9 @@ #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. @@ -0,0 +1,6 @@ @@ -1,3 +1,9 @@ require 'rubygems' require 'minitest/unit' require 'test/insure_session' @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/installer' class Gem::Installer @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/package' class TarTestCase < RubyGemTestCase @@ -120,8 +126,10 @@ class TarTestCase < RubyGemTestCase def util_entry(tar) io = TempIO.new tar header = Gem::Package::TarHeader.from io - entry = Gem::Package::TarReader::Entry.new header, io end def util_dir_entry @@ -1,8 +1,18 @@ at_exit { $SAFE = 1 } -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require 'rubygems' require 'fileutils' require 'minitest/autorun' require 'tmpdir' @@ -11,6 +21,8 @@ require 'rubygems/package' require 'rubygems/test_utilities' require 'pp' require 'yaml' begin YAML::ENGINE.yamler = 'psych' rescue LoadError @@ -23,11 +35,11 @@ end require 'rdoc/rdoc' -require_relative 'mockgemui' module Gem def self.searcher=(searcher) - MUTEX.synchronize do @searcher = searcher end end def self.source_index=(si) @@ -38,6 +50,10 @@ module Gem @@win_platform = val end module DefaultUserInteraction @ui = MockGemUi.new end @@ -53,15 +69,19 @@ class RubyGemTestCase < MiniTest::Unit::TestCase def setup super @ui = MockGemUi.new tmpdir = nil Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp - @tempdir = File.join tmpdir, "test_rubygems_#{$$}" @tempdir.untaint - @gemhome = File.join @tempdir, "gemhome" - @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' Gem.ensure_gem_subdirectories @gemhome @@ -80,7 +100,6 @@ class RubyGemTestCase < MiniTest::Unit::TestCase FileUtils.mkdir_p @gemhome FileUtils.mkdir_p @userhome - ENV['GEMCACHE'] = @usrcache Gem.use_paths(@gemhome) Gem.loaded_specs.clear @@ -131,9 +150,13 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem.pre_uninstall do |uninstaller| @pre_uninstall_hook_arg = uninstaller end end def teardown Gem::ConfigMap[:BASERUBY] = @orig_BASERUBY Gem::ConfigMap[:arch] = @orig_arch @@ -141,15 +164,15 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem::RemoteFetcher.fetcher = nil end - FileUtils.rm_rf @tempdir - ENV.delete 'GEMCACHE' - ENV.delete 'GEM_HOME' - ENV.delete 'GEM_PATH' Gem.clear_paths - Gem.class_eval { @ruby = ruby } if ruby = @orig_ruby if @orig_ENV_HOME then ENV['HOME'] = @orig_ENV_HOME @@ -171,6 +194,14 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem::Installer.new(gem, :wrappers => true).install end def mu_pp(obj) s = '' s = PP.pp obj, s @@ -283,7 +314,15 @@ class RubyGemTestCase < MiniTest::Unit::TestCase Gem.source_index.refresh! end - def util_gem(name, version, &block) spec = quick_gem(name, version, &block) util_build_gem spec @@ -500,13 +539,12 @@ Also, a list: def build_rake_in gem_ruby = Gem.ruby - ruby = @@ruby - Gem.module_eval {@ruby = ruby} env_rake = ENV["rake"] ENV["rake"] = @@rake yield @@rake ensure - Gem.module_eval {@ruby = gem_ruby} if env_rake ENV["rake"] = env_rake else @@ -515,11 +553,11 @@ Also, a list: end def self.rubybin - if ruby = ENV["RUBY"] - return ruby - end ruby = "ruby" - rubyexe = ruby+".exe" 3.times do if File.exist? ruby and File.executable? ruby and !File.directory? ruby return File.expand_path(ruby) @@ -529,12 +567,12 @@ Also, a list: end ruby = File.join("..", ruby) end begin require "rbconfig" - File.join( - RbConfig::CONFIG["bindir"], - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] - ) rescue LoadError "ruby" end @@ -1,3 +1,9 @@ require 'rubygems' def install_session @@ -1,3 +1,9 @@ require 'stringio' require 'rubygems/user_interaction' @@ -1,2 +1,8 @@ TestGem::TEST_PLUGIN_EXCEPTION = :loaded raise Exception.new('boom') \ No newline at end of file @@ -1 +1,7 @@ TestGem::TEST_PLUGIN_LOAD = :loaded \ No newline at end of file @@ -1,2 +1,8 @@ TestGem::TEST_PLUGIN_STANDARDERROR = :loaded raise StandardError.new('boom') \ No newline at end of file @@ -1,3 +1,9 @@ class Gem::Commands::CrashCommand < Gem::Command raise "crash" @@ -1,3 +1,9 @@ require 'rubygems/command_manager' ## @@ -0,0 +1,6 @@ @@ -1,3 +1,9 @@ SIMPLE_GEM = <<-GEMDATA MD5SUM = "b12a4d48febeb2289c539c2574c4b6f8" if $0 == __FILE__ @@ -1,11 +1,21 @@ -require_relative 'gemutilities' require 'rubygems' class TestConfig < RubyGemTestCase def test_datadir - datadir = RbConfig::CONFIG['datadir'] - assert_equal "#{datadir}/xyz", RbConfig.datadir('xyz') end end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems' require 'rubygems/gem_openssl' require 'rubygems/installer' @@ -64,19 +70,19 @@ class TestGem < RubyGemTestCase assert_equal @exec_path, Gem.bin_path('a', nil, '4') end - def test_self_bin_path_no_default_bin quick_gem 'a', '2' do |s| s.executables = ['exec'] end - assert_raises(Gem::Exception) do - Gem.bin_path('a', '2') end end def test_self_bin_path_no_bin_file quick_gem 'a', '1' assert_raises(Gem::Exception) do - Gem.bin_path('a', '1') end end @@ -86,6 +92,16 @@ class TestGem < RubyGemTestCase end end def test_self_bindir assert_equal File.join(@gemhome, 'bin'), Gem.bindir assert_equal File.join(@gemhome, 'bin'), Gem.bindir(Gem.dir) @@ -259,15 +275,15 @@ class TestGem < RubyGemTestCase end def test_self_find_files - discover_path = File.join 'lib', 'foo', 'discover.rb' cwd = File.expand_path '..', __FILE__ $LOAD_PATH.unshift cwd.dup - foo1 = quick_gem 'foo', '1' do |s| s.files << discover_path end - foo2 = quick_gem 'foo', '2' do |s| s.files << discover_path end @@ -285,14 +301,13 @@ class TestGem < RubyGemTestCase Gem.searcher = nil expected = [ - File.expand_path('../foo/discover.rb', __FILE__), File.join(foo2.full_gem_path, discover_path), File.join(foo1.full_gem_path, discover_path), ] - assert_equal expected, Gem.find_files('foo/discover') - bug3701 = '[ruby-core:31730]' - assert_equal expected, Gem.find_files('foo/**.rb'), bug3701 ensure assert_equal cwd, $LOAD_PATH.shift end @@ -321,11 +336,18 @@ class TestGem < RubyGemTestCase assert_equal true, Gem.loaded_specs.keys.include?('foo') end def test_self_path 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 @@ -339,6 +361,8 @@ class TestGem < RubyGemTestCase unless win_platform? def test_self_path_APPLE_GEM_HOME Gem.clear_paths apple_gem_home = File.join @tempdir, 'apple_gem_home' Gem.const_set :APPLE_GEM_HOME, apple_gem_home @@ -599,42 +623,90 @@ class TestGem < RubyGemTestCase end end - def test_self_user_home_user_drive_and_path - Gem.clear_paths - # safe-keep env variables - orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE'] - orig_user_drive, orig_user_path = ENV['HOMEDRIVE'], ENV['HOMEPATH'] - # prepare the environment - ENV.delete('HOME') - ENV.delete('USERPROFILE') - ENV['HOMEDRIVE'] = 'Z:' - ENV['HOMEPATH'] = '\\Users\\RubyUser' - assert_equal "Z:\\Users\\RubyUser", Gem.user_home - ensure - ENV['HOME'] = orig_home - ENV['USERPROFILE'] = orig_user_profile - ENV['USERDRIVE'] = orig_user_drive - ENV['USERPATH'] = orig_user_path - end if '1.9' > RUBY_VERSION def test_load_plugins - with_plugin('load') { Gem.load_plugins } assert_equal :loaded, TEST_PLUGIN_LOAD util_remove_interrupt_command # Should attempt to cause a StandardError - with_plugin('standarderror') { Gem.load_plugins } assert_equal :loaded, TEST_PLUGIN_STANDARDERROR util_remove_interrupt_command # Should attempt to cause an Exception - with_plugin('exception') { Gem.load_plugins } assert_equal :loaded, TEST_PLUGIN_EXCEPTION end @@ -1,20 +0,0 @@ -require_relative '../ruby/envutil' -require 'test/unit' - -class TestGemActivation < Test::Unit::TestCase - def test_activation - bug3140 = '[ruby-core:29486]' - src = %{begin - require 'rubygems-bug-parent' -rescue Gem::LoadError - puts $! -else - puts $bug_3140 -end} - basedir = File.expand_path("../gems/current", __FILE__) - env = {"HOME"=>basedir, "GEM_HOME"=>basedir, "GEM_PATH"=>basedir} - assert_in_out_err([env, "-rrubygems-bug-child", "-e", src], "", - /can't activate rubygems-bug-child.*already activated rubygems-bug-child-1\.1/, [], - bug3140) - end -end if defined?(::Gem) and RUBY_VERSION < "1.9" @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/builder' class TestGemBuilder < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/command' class Gem::Command @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/command_manager' class TestGemCommandManager < RubyGemTestCase @@ -10,7 +16,9 @@ class TestGemCommandManager < RubyGemTestCase end def test_run_interrupt - Gem.load_plugins use_ui @ui do assert_raises MockGemUi::TermError do @@ -19,9 +27,14 @@ class TestGemCommandManager < RubyGemTestCase assert_equal '', ui.output assert_equal "ERROR: Interrupted\n", ui.error end end def test_run_crash_command @command_manager.register_command :crash use_ui @ui do assert_raises MockGemUi::TermError do @@ -31,6 +44,8 @@ class TestGemCommandManager < RubyGemTestCase err = ui.error.split("\n").first assert_equal "ERROR: Loading command: crash (RuntimeError)", err end end def test_process_args_bad_arg @@ -54,7 +69,6 @@ class TestGemCommandManager < RubyGemTestCase #check defaults @command_manager.process_args("install") - assert_equal false, check_options[:test] assert_equal true, check_options[:generate_rdoc] assert_equal false, check_options[:force] assert_equal :both, check_options[:domain] @@ -66,7 +80,7 @@ class TestGemCommandManager < RubyGemTestCase #check settings check_options = nil @command_manager.process_args( - "install --force --test --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ") assert_equal true, check_options[:generate_rdoc] assert_equal true, check_options[:force] assert_equal :local, check_options[:domain] @@ -195,7 +209,7 @@ class TestGemCommandManager < RubyGemTestCase #check settings check_options = nil - @command_manager.process_args("update --force --test --rdoc --install-dir .") assert_equal true, check_options[:generate_rdoc] assert_equal true, check_options[:force] assert_equal Dir.pwd, check_options[:install_dir] @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/build_command' require 'rubygems/format' @@ -1,5 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/cert_command' unless defined? OpenSSL then @@ -73,7 +78,7 @@ class TestGemCommandsCertCommand < RubyGemTestCase assert_equal '', @ui.error assert_equal File.read(@cert_file_name), - Gem::Security::OPT[:issuer_cert].to_s end def test_execute_list @@ -94,7 +99,7 @@ class TestGemCommandsCertCommand < RubyGemTestCase assert_equal '', @ui.error assert_equal File.read(@pkey_file_name), - Gem::Security::OPT[:issuer_key].to_s end def test_execute_remove @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/check_command' class TestGemCommandsCheckCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/contents_command' class TestGemCommandsContentsCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/dependency_command' class TestGemCommandsDependencyCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/environment_command' class TestGemCommandsEnvironmentCommand < RubyGemTestCase @@ -131,5 +137,14 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase assert_equal '', @ui.error end -end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/package' require 'rubygems/security' require 'rubygems/commands/fetch_command' @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/indexer' require 'rubygems/commands/generate_index_command' @@ -16,15 +22,11 @@ class TestGemCommandsGenerateIndexCommand < RubyGemTestCase @cmd.execute end - yaml = File.join @gemhome, 'yaml' - yaml_z = File.join @gemhome, 'yaml.Z' - quick_index = File.join @gemhome, 'quick', 'index' - quick_index_rz = File.join @gemhome, 'quick', 'index.rz' - assert File.exist?(yaml), yaml - assert File.exist?(yaml_z), yaml_z - assert File.exist?(quick_index), quick_index - assert File.exist?(quick_index_rz), quick_index_rz end def test_execute_rss_update @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/install_command' class TestGemCommandsInstallCommand < RubyGemTestCase @@ -172,6 +178,30 @@ class TestGemCommandsInstallCommand < RubyGemTestCase assert_match(/ould not find a valid gem 'nonexistent'/, @ui.error) end def test_execute_prerelease util_setup_fake_fetcher(:prerelease) util_setup_spec_fetcher @a2, @a2_pre @@ -258,5 +288,36 @@ class TestGemCommandsInstallCommand < RubyGemTestCase assert out.empty?, out.inspect end end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/list_command' class TestGemCommandsListCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/lock_command' class TestGemCommandsLockCommand < RubyGemTestCase @@ -1,60 +0,0 @@ -require_relative 'gemutilities' -require 'rubygems/indexer' -require 'rubygems/commands/mirror_command' - -class TestGemCommandsMirrorCommand < RubyGemTestCase - - def setup - super - - @cmd = Gem::Commands::MirrorCommand.new - end - - def test_execute - util_make_gems - - gems_dir = File.join @tempdir, 'gems' - mirror = File.join @tempdir, 'mirror' - - FileUtils.mkdir_p gems_dir - FileUtils.mkdir_p mirror - - Dir[File.join(@gemhome, 'cache', '*.gem')].each do |gem| - FileUtils.mv gem, gems_dir - end - - use_ui @ui do - Gem::Indexer.new(@tempdir).generate_index - end - - orig_HOME = ENV['HOME'] - ENV['HOME'] = @tempdir - Gem.instance_variable_set :@user_home, nil - - File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp| - fp.puts "---" - # tempdir could be a drive+path (under windows) - if @tempdir.match(/[a-z]:/i) - fp.puts "- from: file:///#{@tempdir}" - else - fp.puts "- from: file://#{@tempdir}" - end - fp.puts " to: #{mirror}" - end - - use_ui @ui do - @cmd.execute - end - - assert File.exist?(File.join(mirror, 'gems', @a1.file_name)) - assert File.exist?(File.join(mirror, 'gems', @a2.file_name)) - assert File.exist?(File.join(mirror, 'gems', @b2.file_name)) - assert File.exist?(File.join(mirror, 'gems', @c1_2.file_name)) - assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}")) - ensure - orig_HOME.nil? ? ENV.delete('HOME') : ENV['HOME'] = orig_HOME - Gem.instance_variable_set :@user_home, nil - end - -end if ''.respond_to? :to_xs - @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/outdated_command' class TestGemCommandsOutdatedCommand < RubyGemTestCase @@ -14,8 +20,8 @@ class TestGemCommandsOutdatedCommand < RubyGemTestCase 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' @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/owner_command' class TestGemCommandsOwnerCommand < RubyGemTestCase @@ -20,7 +26,7 @@ class TestGemCommandsOwnerCommand < RubyGemTestCase - email: [email protected] EOF - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK'] use_ui @ui do @cmd.show_owners("freewill") @@ -36,7 +42,7 @@ EOF def test_show_owners_denied response = "You don't have permission to push to this gem" - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners.yaml"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do @@ -49,7 +55,7 @@ EOF def test_add_owners response = "Owner added successfully." - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] use_ui @ui do @cmd.add_owners("freewill", ["[email protected]"]) @@ -64,7 +70,7 @@ EOF def test_add_owners_denied response = "You don't have permission to push to this gem" - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do @@ -77,7 +83,7 @@ EOF def test_remove_owners response = "Owner removed successfully." - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] use_ui @ui do @cmd.remove_owners("freewill", ["[email protected]"]) @@ -92,7 +98,7 @@ EOF def test_remove_owners_denied response = "You don't have permission to push to this gem" - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/pristine_command' class TestGemCommandsPristineCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/push_command' class TestGemCommandsPushCommand < RubyGemTestCase @@ -18,15 +24,12 @@ class TestGemCommandsPushCommand < RubyGemTestCase @cmd = Gem::Commands::PushCommand.new end - def test_sending_gem - response = "Successfully registered gem: freewill (1.0.0)" - @fetcher.data["https://rubygems.org/api/v1/gems"] = [response, 200, 'OK'] - use_ui @ui do @cmd.send_gem(@path) end - assert_match %r{Pushing gem to RubyGems.org...}, @ui.output assert_equal Net::HTTP::Post, @fetcher.last_request.class assert_equal Gem.read_binary(@path), @fetcher.last_request.body @@ -34,7 +37,30 @@ class TestGemCommandsPushCommand < RubyGemTestCase assert_equal "application/octet-stream", @fetcher.last_request["Content-Type"] assert_equal Gem.configuration.rubygems_api_key, @fetcher.last_request["Authorization"] - assert_match response, @ui.output end def test_raises_error_with_no_arguments @@ -46,7 +72,7 @@ class TestGemCommandsPushCommand < RubyGemTestCase def test_sending_gem_denied response = "You don't have permission to push to this gem" - @fetcher.data["https://rubygems.org/api/v1/gems"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/query_command' class TestGemCommandsQueryCommand < RubyGemTestCase @@ -64,9 +70,6 @@ pl (1 i386-linux) end def test_execute_all - a1_name = @a1.full_name - a2_name = @a2.full_name - @cmd.handle_options %w[-r --all] use_ui @ui do @@ -86,9 +89,6 @@ pl (1 i386-linux) end def test_execute_all_prerelease - a1_name = @a1.full_name - a2_name = @a2.full_name - @cmd.handle_options %w[-r --all --prerelease] use_ui @ui do @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/server_command' class TestGemCommandsServerCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/sources_command' class TestGemCommandsSourcesCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/specification_command' class TestGemCommandsSpecificationCommand < RubyGemTestCase @@ -25,8 +31,8 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase end def test_execute_all - foo1 = quick_gem 'foo', '0.0.1' - foo2 = quick_gem 'foo', '0.0.2' @cmd.options[:args] = %w[foo] @cmd.options[:all] = true @@ -56,8 +62,8 @@ class TestGemCommandsSpecificationCommand < RubyGemTestCase end def test_execute_exact_match - foo = quick_gem 'foo' - foo_bar = quick_gem 'foo_bar' @cmd.options[:args] = %w[foo] @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/stale_command' class TestGemCommandsStaleCommand < RubyGemTestCase @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'gem_installer_test_case' require 'rubygems/commands/uninstall_command' class TestGemCommandsUninstallCommand < GemInstallerTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/unpack_command' class TestGemCommandsUnpackCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/update_command' class TestGemCommandsUpdateCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/commands/which_command' class TestGemCommandsWhichCommand < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/config_file' class TestGemConfigFile < RubyGemTestCase @@ -46,7 +52,6 @@ class TestGemConfigFile < RubyGemTestCase fp.puts ":benchmark: true" fp.puts ":bulk_threshold: 10" fp.puts ":verbose: false" - fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" fp.puts ":sources:" fp.puts " - http://more-gems.example.com" fp.puts "install: --wrappers" @@ -62,7 +67,6 @@ class TestGemConfigFile < RubyGemTestCase assert_equal 10, @cfg.bulk_threshold assert_equal false, @cfg.verbose assert_equal false, @cfg.update_sources - assert_equal "701229f217cdf23b1344c7b4b54ca97", @cfg.rubygems_api_key assert_equal %w[http://more-gems.example.com], Gem.sources assert_equal '--wrappers', @cfg[:install] assert_equal(['/usr/ruby/1.8/lib/ruby/gems/1.8', '/var/ruby/1.8/gem_home'], @@ -1,19 +1,13 @@ -require_relative 'gemutilities' require 'rubygems/dependency' class TestGemDependency < RubyGemTestCase - - def test_subclass - sc = Class.new Gem::Dependency - def sc.requirement() bogus; end - - out, err = capture_io do - assert_equal Gem::Requirement.default, sc.new('a').version_requirement - end - - assert_match %r%deprecated%, err - end - def test_initialize d = dep "pkg", "> 1.0" @@ -133,17 +127,5 @@ class TestGemDependency < RubyGemTestCase assert d.prerelease? end - - def test_version_requirements_equals_deprecated - d = dep "pkg", "1.0" - - out, err = capture_io do - d.version_requirements = '2.0' - assert_equal Gem::Requirement.new(%w[2.0]), d.requirement - end - - assert_match %r%deprecated%, err - end - end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/dependency_installer' class TestGemDependencyInstaller < RubyGemTestCase @@ -44,20 +50,20 @@ class TestGemDependencyInstaller < RubyGemTestCase s.platform = Gem::Platform.new %w[cpu other_platform 1] end - @w1, @w1_gem = util_gem 'w', '1' do |s| s.add_dependency 'x' end @y1, @y1_gem = util_gem 'y', '1' @y1_1_p, @y1_1_p_gem = util_gem 'y', '1.1' do |s| s.platform = Gem::Platform.new %w[cpu my_platform 1] end - @z1, @z1_gem = util_gem 'z', '1' do |s| s.add_dependency 'y' end @fetcher = Gem::FakeFetcher.new Gem::RemoteFetcher.fetcher = @fetcher - si = util_setup_spec_fetcher(@a1, @a1_pre, @b1, @b1_pre, @c1_pre, @d1, @d2, - @x1_m, @x1_o, @w1, @y1, @y1_1_p, @z1) util_clear_gems end @@ -78,7 +84,7 @@ class TestGemDependencyInstaller < RubyGemTestCase end def test_install_all_dependencies - e1, e1_gem = util_gem 'e', '1' do |s| s.add_dependency 'b' end @@ -190,9 +196,9 @@ class TestGemDependencyInstaller < RubyGemTestCase end def test_install_dependency_old - e1, e1_gem = util_gem 'e', '1' - f1, f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end - f2, f2_gem = util_gem 'f', '2' FileUtils.mv e1_gem, @tempdir FileUtils.mv f1_gem, @tempdir @@ -607,27 +613,25 @@ class TestGemDependencyInstaller < RubyGemTestCase assert_equal [@a1_pre], prereleases end - def test_gather_dependencies inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'b' inst.gather_dependencies - assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name } end - def test_gather_dependencies_dropped - b2, = util_gem 'b', '2' - c1, = util_gem 'c', '1' do |s| s.add_dependency 'b' end - - util_clear_gems - - si = util_setup_spec_fetcher @a1, @b1, b2, c1 - inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'c' inst.gather_dependencies - assert_equal %w[b-2 c-1], inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_platform_alternate @@ -659,11 +663,11 @@ class TestGemDependencyInstaller < RubyGemTestCase end def test_gather_dependencies_old_required - e1, = util_gem 'e', '1' do |s| s.add_dependency 'd', '= 1' end util_clear_gems - si = util_setup_spec_fetcher @d1, @d2, e1 inst = Gem::DependencyInstaller.new inst.find_spec_by_name_and_version 'e' @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/dependency_list' class TestGemDependencyList < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/doc_manager' class TestGemDocManager < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/ext' class TestGemExtConfigureBuilder < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/ext' class TestGemExtExtConfBuilder < RubyGemTestCase @@ -28,19 +34,60 @@ class TestGemExtExtConfBuilder < RubyGemTestCase Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output end - expected = [ - "ruby extconf.rb", - "creating Makefile\n", - "make", - "make: Nothing to be done for `all'.\n", - "make install", - "make: Nothing to be done for `install'.\n" - ] - assert_match(/^#{Gem.ruby} extconf.rb/, output[0]) assert_equal "creating Makefile\n", output[1] assert_equal make_command, output[2] - assert_equal make_command + " install", output[4] end def test_class_build_extconf_fail @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/ext' class TestGemExtRakeBuilder < RubyGemTestCase @@ -33,13 +39,6 @@ class TestGemExtRakeBuilder < RubyGemTestCase output = output.join "\n" - expected = [ - "#{@@ruby} mkrf_conf.rb", - "", - "#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path}", - "(in #{realdir})\n" - ] - refute_match %r%^rake failed:%, output assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, output assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, output @@ -64,14 +63,6 @@ class TestGemExtRakeBuilder < RubyGemTestCase end end - expected = <<-EOF.strip -rake failed: - -#{@@ruby} mkrf_conf.rb - -#{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path} - EOF - assert_match %r%^rake failed:%, error.message assert_match %r%^#{Regexp.escape @@ruby} mkrf_conf\.rb%, error.message assert_match %r%^#{Regexp.escape @@rake} RUBYARCHDIR=#{Regexp.escape @dest_path} RUBYLIBDIR=#{Regexp.escape @dest_path}%, error.message @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'simple_gem' require 'rubygems/format' class TestGemFormat < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/gem_path_searcher' class Gem::GemPathSearcher @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/gem_runner' class TestGemGemRunner < RubyGemTestCase @@ -1,6 +1,11 @@ -require_relative 'gemutilities' require 'rubygems' -require 'rubygems/command' require 'rubygems/gemcutter_utilities' class TestGemGemcutterUtilities < RubyGemTestCase @@ -86,7 +91,7 @@ class TestGemGemcutterUtilities < RubyGemTestCase if host ENV['RUBYGEMS_HOST'] = host else - host = "https://rubygems.org" end @fetcher = Gem::FakeFetcher.new @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/indexer' unless ''.respond_to? :to_xs then @@ -93,8 +99,6 @@ class TestGemIndexer < RubyGemTestCase @indexer.generate_index end - assert_indexed @tempdir, 'yaml' - assert_indexed @tempdir, 'yaml.Z' assert_indexed @tempdir, "Marshal.#{@marshal_version}" assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" @@ -104,52 +108,9 @@ class TestGemIndexer < RubyGemTestCase assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - assert_indexed quickdir, "index" - assert_indexed quickdir, "index.rz" - - quick_index = File.read File.join(quickdir, 'index') - expected = <<-EOF -a-1 -a-2 -a-3.a -a_evil-9 -b-2 -c-1.2 -d-2.0 -d-2.0.a -d-2.0.b -pl-1-i386-linux - EOF - - assert_equal expected, quick_index - - assert_indexed quickdir, "latest_index" - assert_indexed quickdir, "latest_index.rz" - - 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.spec_name}.rz" - assert_indexed quickdir, "#{@a2.spec_name}.rz" - assert_indexed quickdir, "#{@b2.spec_name}.rz" - assert_indexed quickdir, "#{@c1_2.spec_name}.rz" - - assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" - refute_indexed quickdir, "#{@pl1.spec_name}.rz" - assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz" assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz" - refute_indexed quickdir, @c1_2.spec_name refute_indexed marshal_quickdir, @c1_2.spec_name assert_indexed @tempdir, "specs.#{@marshal_version}" @@ -301,8 +262,6 @@ eighty characters.</pre> @indexer.generate_index end - assert_indexed @tempdir, 'yaml' - assert_indexed @tempdir, 'yaml.Z' assert_indexed @tempdir, "Marshal.#{@marshal_version}" assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" @@ -312,24 +271,9 @@ eighty characters.</pre> assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - assert_indexed quickdir, "index" - assert_indexed quickdir, "index.rz" - - assert_indexed quickdir, "latest_index" - assert_indexed quickdir, "latest_index.rz" - - assert_indexed quickdir, "#{@a1.spec_name}.rz" - assert_indexed quickdir, "#{@a2.spec_name}.rz" - assert_indexed quickdir, "#{@b2.spec_name}.rz" - assert_indexed quickdir, "#{@c1_2.spec_name}.rz" - - assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" - refute_indexed quickdir, "#{@pl1.spec_name}.rz" - assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz" assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz" - refute_indexed quickdir, "#{@c1_2.spec_name}" refute_indexed marshal_quickdir, "#{@c1_2.spec_name}" refute_indexed @tempdir, "specs.#{@marshal_version}" @@ -355,30 +299,14 @@ eighty characters.</pre> @indexer.generate_index end - 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}" - assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - assert_indexed quickdir, "index" - assert_indexed quickdir, "index.rz" - - assert_indexed quickdir, "latest_index" - assert_indexed quickdir, "latest_index.rz" - - assert_indexed quickdir, "#{@a1.spec_name}.rz" - assert_indexed quickdir, "#{@a2.spec_name}.rz" - assert_indexed quickdir, "#{@b2.spec_name}.rz" - assert_indexed quickdir, "#{@c1_2.spec_name}.rz" - - assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" - assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz" assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz" @@ -451,8 +379,6 @@ eighty characters.</pre> @indexer.generate_index end - assert_indexed @tempdir, 'yaml' - assert_indexed @tempdir, 'yaml.Z' assert_indexed @tempdir, "Marshal.#{@marshal_version}" assert_indexed @tempdir, "Marshal.#{@marshal_version}.Z" @@ -462,19 +388,6 @@ eighty characters.</pre> assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - assert_indexed quickdir, "index" - assert_indexed quickdir, "index.rz" - - assert_indexed quickdir, "latest_index" - assert_indexed quickdir, "latest_index.rz" - - assert_indexed quickdir, "#{@a1.spec_name}.rz" - assert_indexed quickdir, "#{@a2.spec_name}.rz" - assert_indexed quickdir, "#{@b2.spec_name}.rz" - assert_indexed quickdir, "#{@c1_2.spec_name}.rz" - - assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" - assert_indexed marshal_quickdir, "#{@a1.spec_name}.rz" assert_indexed marshal_quickdir, "#{@a2.spec_name}.rz" @@ -496,41 +409,17 @@ eighty characters.</pre> assert_match %r%^Loaded all gems$%, @ui.output assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%, @ui.output - assert_match %r%^Generating YAML quick index gemspecs for 10 gems$%, - @ui.output assert_match %r%^Complete$%, @ui.output assert_match %r%^Generating specs index$%, @ui.output assert_match %r%^Generating latest specs index$%, @ui.output - assert_match %r%^Generating quick index$%, @ui.output - assert_match %r%^Generating latest index$%, @ui.output assert_match %r%^Generating prerelease specs index$%, @ui.output assert_match %r%^Generating Marshal master index$%, @ui.output - assert_match %r%^Generating YAML master index for 10 gems \(this may take a while\)$%, @ui.output assert_match %r%^Complete$%, @ui.output assert_match %r%^Compressing indicies$%, @ui.output assert_equal '', @ui.error end - 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_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 - end - - assert_equal yaml_index, dump_index, - "expected YAML and Marshal to produce identical results" - end - def test_generate_index_specs use_ui @ui do @indexer.generate_index @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' require 'rubygems/install_update_options' require 'rubygems/command' @@ -13,7 +19,7 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase end def test_add_install_update_options - args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity --ignore-dependencies --format-exec --include-dependencies] assert @cmd.handles?(args) @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' class TestGemInstaller < GemInstallerTestCase @@ -58,10 +64,6 @@ load Gem.bin_path('a', 'my_exec', version) assert_equal '', @ui.error gem_make_out = File.join @gemhome, 'gems', @spec.full_name, 'gem_make.out' - expected = <<-EOF -#{Gem.ruby} extconf.rb -#{Gem.ruby}: No such file or directory -- extconf.rb (LoadError) - EOF assert_match %r%#{Regexp.escape Gem.ruby} extconf\.rb%, File.read(gem_make_out) @@ -655,7 +657,6 @@ load Gem.bin_path('a', 'my_exec', version) use_ui @ui do Dir.chdir @tempdir do Gem::Builder.new(@spec).build end - gem = File.join @tempdir, @spec.file_name @installer.install end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/local_remote_options' require 'rubygems/command' @@ -30,6 +36,21 @@ class TestGemLocalRemoteOptions < RubyGemTestCase assert_equal true, @cmd.both? end def test_local_eh assert_equal false, @cmd.local? @@ -62,9 +83,11 @@ class TestGemLocalRemoteOptions < RubyGemTestCase s3 = URI.parse 'http://other-gems.example.com/some_subdir' s4 = URI.parse 'http://more-gems.example.com/' # Intentional duplicate @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}] - assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources end def test_update_sources_option @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package' class TestGemPackageTarHeader < TarTestCase @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package/tar_input' class TestGemPackageTarInput < TarTestCase @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package/tar_output' class TestGemPackageTarOutput < TarTestCase @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package' class TestGemPackageTarReader < TarTestCase @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package' class TestGemPackageTarReaderEntry < TarTestCase @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' require 'rubygems/package/tar_writer' class TestTarWriter < TarTestCase @@ -1,8 +1,14 @@ -require_relative 'gemutilities' require 'rubygems' require 'rubygems/package_task' -class TestGemPackageTask < MiniTest::Unit::TestCase def test_gem_package gem = Gem::Specification.new do |g| @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/platform' require 'rbconfig' @@ -117,7 +123,6 @@ class TestGemPlatform < RubyGemTestCase def test_initialize_platform platform = Gem::Platform.new 'cpu-my_platform1' - expected = Gem::Platform.new platform assert_equal 'cpu', platform.cpu assert_equal 'my_platform', platform.os @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'ostruct' require 'webrick' require 'rubygems/remote_fetcher' @@ -372,7 +378,7 @@ gems: uri.user, uri.password = 'domain%5Cuser', 'bar' fetcher = Gem::RemoteFetcher.new uri.to_s proxy = fetcher.instance_variable_get("@proxy_uri") - assert_equal 'domain\user', URI.unescape(proxy.user) assert_equal 'bar', proxy.password assert_data_from_proxy fetcher.fetch_path(@server_uri) end @@ -383,7 +389,7 @@ gems: fetcher = Gem::RemoteFetcher.new uri.to_s proxy = fetcher.instance_variable_get("@proxy_uri") assert_equal 'user', proxy.user - assert_equal 'my pass', URI.unescape(proxy.password) assert_data_from_proxy fetcher.fetch_path(@server_uri) end end @@ -406,8 +412,8 @@ gems: ENV['http_proxy_pass'] = 'my bar' fetcher = Gem::RemoteFetcher.new nil proxy = fetcher.instance_variable_get("@proxy_uri") - assert_equal 'foo\user', URI.unescape(proxy.user) - assert_equal 'my bar', URI.unescape(proxy.password) assert_data_from_proxy fetcher.fetch_path(@server_uri) end end @@ -562,7 +568,7 @@ gems: end end - conn = { 'gems.example.com:80' => conn } fetcher.instance_variable_set :@connections, conn data = fetcher.open_uri_or_path 'http://gems.example.com/redirect' @@ -581,7 +587,7 @@ gems: res end - conn = { 'gems.example.com:80' => conn } fetcher.instance_variable_set :@connections, conn e = assert_raises Gem::RemoteFetcher::FetchError do @@ -646,11 +652,13 @@ gems: def assert_error(exception_class=Exception) got_exception = false begin yield - rescue exception_class => ex got_exception = true end assert got_exception, "Expected exception conforming to #{exception_class}" end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require "rubygems/requirement" class TestGemRequirement < RubyGemTestCase @@ -216,9 +222,9 @@ class TestGemRequirement < RubyGemTestCase refute_satisfied_by "2.0", "~> 1.4.4" refute_satisfied_by "1.1.pre", "~> 1.0.0" - assert_satisfied_by "1.1.pre", "~> 1.1" refute_satisfied_by "2.0.a", "~> 1.0" - assert_satisfied_by "2.0.a", "~> 2.0" end def test_satisfied_by_eh_multiple @@ -0,0 +1,96 @@ @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/server' require 'stringio' @@ -92,7 +98,7 @@ class TestGemServer < RubyGemTestCase def test_listen util_listen - out, err = capture_io do @server.listen end @@ -102,109 +108,11 @@ class TestGemServer < RubyGemTestCase def test_listen_addresses util_listen - out, err = capture_io do @server.listen %w[a b] end - - assert_equal 2, @server.server.listeners.length - end - - def test_quick_a_1_gemspec_rz - data = StringIO.new "GET /quick/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 = 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 - - data = StringIO.new "GET /quick/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 = 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 - end - - def test_quick_common_substrings - ab1 = quick_gem 'ab', '1' - - data = StringIO.new "GET /quick/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 = YAML.load Gem.inflate(@res.body) - assert_equal 'a', spec.name - assert_equal Gem::Version.new(1), spec.version - end - - 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 @@ -236,7 +144,7 @@ class TestGemServer < RubyGemTestCase 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 @@ -305,38 +213,6 @@ class TestGemServer < RubyGemTestCase 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 - def util_listen webrick = Object.new webrick.instance_variable_set :@listeners, [] @@ -1,13 +1,13 @@ -require_relative 'gemutilities' require 'rubygems/source_index' require 'rubygems/config_file' -class Gem::SourceIndex - public :fetcher, :fetch_bulk_index, :fetch_quick_index, - :find_missing, :gems, :remove_extra, - :update_with_missing, :unzip -end - class TestGemSourceIndex < RubyGemTestCase def setup @@ -116,19 +116,14 @@ end 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 @@ -163,14 +158,13 @@ WARNING: Invalid .gemspec format in '#{spec_file}' fp.write '1 +' end - use_ui @ui do assert_equal nil, Gem::SourceIndex.load_specification(spec_file) end - assert_equal '', @ui.output - assert_match(/syntax error/, @ui.error) - assert_match(/1 \+/, @ui.error) end def test_self_load_specification_system_exit @@ -198,23 +192,6 @@ WARNING: Invalid .gemspec format in '#{spec_file}' # TODO end - def test_fetcher - assert_equal @fetcher, @source_index.fetcher - end - - def test_find_missing - missing = @source_index.find_missing [@b2.full_name] - assert_equal [@b2.full_name], missing - end - - def test_find_missing_none_missing - missing = @source_index.find_missing [ - @a1.full_name, @a2.full_name, @c1_2.full_name - ] - - assert_equal [], missing - end - def test_find_name assert_equal [@a1, @a2, @a3a], @source_index.find_name('a') assert_equal [@a2], @source_index.find_name('a', '= 2') @@ -359,27 +336,6 @@ WARNING: Invalid .gemspec format in '#{spec_file}' 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 - @source_index.add_spec @pl1 - - @source_index.remove_extra [@a1.full_name, @pl1.full_name] - - assert_equal [@a1.full_name], - @source_index.gems.map { |n,s| n }.sort - end - - def test_remove_extra_no_changes - gems = [@a1.full_name, @a2.full_name] - @source_index.add_spec @a1 - @source_index.add_spec @a2 - - @source_index.remove_extra gems - - assert_equal gems, @source_index.gems.map { |n,s| n }.sort - end - def test_remove_spec deleted = @source_index.remove_spec 'a-1' @@ -442,20 +398,5 @@ WARNING: Invalid .gemspec format in '#{spec_file}' assert_match(/^[a-f0-9]{64}$/, sig) end - def test_unzip - input = "x\234+\316\317MU(I\255(\001\000\021\350\003\232" - assert_equal 'some text', @source_index.unzip(input) - end - - def util_setup_bulk_fetch(compressed) - source_index = @source_index.dump - - if compressed then - @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}.Z"] = util_zip source_index - else - @fetcher.data["#{@gem_repo}Marshal.#{@marshal_version}"] = source_index - end - end - end @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/spec_fetcher' class TestGemSpecFetcher < RubyGemTestCase @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'stringio' require 'rubygems/specification' @@ -777,7 +783,6 @@ Gem::Specification.new do |s| 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 Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then @@ -832,7 +837,6 @@ Gem::Specification.new do |s| s.test_files = [\"test/suite.rb\"] if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then @@ -1175,21 +1179,6 @@ end end end - def test_validate_rubyforge_project - util_setup_validate - - Dir.chdir @tempdir do - @a1.rubyforge_project = '' - - use_ui @ui do - @a1.validate - end - - assert_equal "WARNING: no rubyforge_project specified\n", - @ui.error, 'error' - end - end - def test_validate_rubygems_version util_setup_validate @@ -1258,7 +1247,9 @@ end specfile.write "raise 'boom'" specfile.close begin - Gem::Specification.load(specfile.path) rescue => e name_rexp = Regexp.new(Regexp.escape(specfile.path)) assert e.backtrace.grep(name_rexp).any? @@ -1,5 +1,12 @@ -require_relative 'gemutilities' require 'rubygems/user_interaction' class TestGemStreamUI < RubyGemTestCase @@ -28,6 +35,7 @@ class TestGemStreamUI < RubyGemTestCase @err = StringIO.new @in.extend IsTty @sui = Gem::StreamUI.new @in, @out, @err end @@ -109,32 +117,94 @@ class TestGemStreamUI < RubyGemTestCase assert_equal "which one?\n 1. foo\n 2. bar\n> ", @out.string end - def test_proress_reporter_silent_nil @cfg.verbose = nil reporter = @sui.progress_reporter 10, 'hi' assert_kind_of Gem::StreamUI::SilentProgressReporter, reporter end - def test_proress_reporter_silent_false @cfg.verbose = false reporter = @sui.progress_reporter 10, 'hi' assert_kind_of Gem::StreamUI::SilentProgressReporter, reporter assert_equal "", @out.string end - def test_proress_reporter_simple @cfg.verbose = true reporter = @sui.progress_reporter 10, 'hi' assert_kind_of Gem::StreamUI::SimpleProgressReporter, reporter assert_equal "hi\n", @out.string end - def test_proress_reporter_verbose @cfg.verbose = 0 reporter = @sui.progress_reporter 10, 'hi' assert_kind_of Gem::StreamUI::VerboseProgressReporter, reporter assert_equal "hi\n", @out.string end -end @@ -0,0 +1,49 @@ @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' require 'rubygems/uninstaller' class TestGemUninstaller < GemInstallerTestCase @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'simple_gem' require 'rubygems/validator' class TestGemValidator < RubyGemTestCase @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require 'rubygems/version' class TestGemVersion < RubyGemTestCase @@ -11,6 +17,10 @@ class TestGemVersion < RubyGemTestCase assert_bumped_version_equal "5.3", "5.2.4.a" end def test_bump_trailing_zeros assert_bumped_version_equal "5.1", "5.0.0" end @@ -32,14 +42,16 @@ class TestGemVersion < RubyGemTestCase end def test_eql_eh - assert_version_eql "1.2", "1.2" - refute_version_eql "1.2", "1.2.0" - refute_version_eql "1.2", "1.3" end - def test_equals - assert_version_equal "1.2", "1.2" - refute_version_equal "1.2", "1.3" end # REVISIT: consider removing as too impl-bound @@ -88,13 +100,16 @@ class TestGemVersion < RubyGemTestCase end def test_spaceship - assert_equal( 0, v("1.0") <=> v("1.0.0")) - assert_equal( 1, v("1.0") <=> v("1.0.a")) - assert_equal( 1, v("1.8.2") <=> v("0.0.0")) - assert_equal( 1, v("1.8.2") <=> v("1.8.2.a")) - assert_equal( 1, v("1.8.2.b") <=> v("1.8.2.a")) - assert_equal(-1, v("1.8.2.a") <=> v("1.8.2")) - assert_equal( 0, v("") <=> v("0")) end def test_spermy_recommendation @@ -1,4 +1,10 @@ -require_relative 'gemutilities' require 'rubygems/command' require 'rubygems/version_option' @@ -1,5 +1,10 @@ -require_relative 'gemutilities' -require 'rubygems/package' class TestKernel < RubyGemTestCase @@ -20,21 +25,18 @@ class TestKernel < RubyGemTestCase def test_gem assert gem('a', '= 1'), "Should load" assert $:.any? { |p| %r{a-1/lib} =~ p } - assert $:.any? { |p| %r{a-1/bin} =~ p } end def test_gem_redundent assert gem('a', '= 1'), "Should load" refute gem('a', '= 1'), "Should not load" assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size - assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size end def test_gem_overlapping assert gem('a', '= 1'), "Should load" refute gem('a', '>= 1'), "Should not load" assert_equal 1, $:.select { |p| %r{a-1/lib} =~ p }.size - assert_equal 1, $:.select { |p| %r{a-1/bin} =~ p }.size end def test_gem_conflicting @@ -47,13 +49,14 @@ class TestKernel < RubyGemTestCase assert_match(/activate a \(= 2, runtime\)/, ex.message) assert_match(/activated a-1/, ex.message) assert_equal 'a', ex.name - assert_equal Gem::Requirement.new('= 2'), ex.version_requirement assert $:.any? { |p| %r{a-1/lib} =~ p } - assert $:.any? { |p| %r{a-1/bin} =~ p } refute $:.any? { |p| %r{a-2/lib} =~ p } - refute $:.any? { |p| %r{a-2/bin} =~ p } end end - |