From e798ccbacf489a3af2201ae30058ff0ae7f79045 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 19 Jan 2011 00:08:49 +0000 Subject: Import rubygems 1.5.0 (release candidate) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/bogussources.rb | 6 + test/rubygems/fake_certlib/openssl.rb | 6 + test/rubygems/foo/discover.rb | 6 + test/rubygems/functional.rb | 6 + test/rubygems/gem_installer_test_case.rb | 8 +- test/rubygems/gem_package_tar_test_case.rb | 12 +- test/rubygems/gemutilities.rb | 92 +++++++++---- test/rubygems/insure_session.rb | 6 + test/rubygems/mockgemui.rb | 6 + test/rubygems/plugin/exception/rubygems_plugin.rb | 6 + test/rubygems/plugin/load/rubygems_plugin.rb | 6 + .../plugin/standarderror/rubygems_plugin.rb | 6 + test/rubygems/rubygems/commands/crash_command.rb | 6 + test/rubygems/rubygems_plugin.rb | 6 + test/rubygems/sff/discover.rb | 6 + test/rubygems/simple_gem.rb | 6 + test/rubygems/test_config.rb | 16 ++- test/rubygems/test_gem.rb | 136 ++++++++++++++----- test/rubygems/test_gem_activation.rb | 20 --- test/rubygems/test_gem_builder.rb | 8 +- test/rubygems/test_gem_command.rb | 8 +- test/rubygems/test_gem_command_manager.rb | 24 +++- test/rubygems/test_gem_commands_build_command.rb | 8 +- test/rubygems/test_gem_commands_cert_command.rb | 11 +- test/rubygems/test_gem_commands_check_command.rb | 8 +- .../rubygems/test_gem_commands_contents_command.rb | 8 +- .../test_gem_commands_dependency_command.rb | 8 +- .../test_gem_commands_environment_command.rb | 19 ++- test/rubygems/test_gem_commands_fetch_command.rb | 8 +- .../test_gem_commands_generate_index_command.rb | 20 +-- test/rubygems/test_gem_commands_install_command.rb | 63 ++++++++- test/rubygems/test_gem_commands_list_command.rb | 8 +- test/rubygems/test_gem_commands_lock_command.rb | 8 +- test/rubygems/test_gem_commands_mirror_command.rb | 60 --------- .../rubygems/test_gem_commands_outdated_command.rb | 12 +- test/rubygems/test_gem_commands_owner_command.rb | 20 ++- .../rubygems/test_gem_commands_pristine_command.rb | 8 +- test/rubygems/test_gem_commands_push_command.rb | 42 ++++-- test/rubygems/test_gem_commands_query_command.rb | 14 +- test/rubygems/test_gem_commands_server_command.rb | 8 +- test/rubygems/test_gem_commands_sources_command.rb | 8 +- .../test_gem_commands_specification_command.rb | 16 ++- test/rubygems/test_gem_commands_stale_command.rb | 8 +- .../test_gem_commands_uninstall_command.rb | 10 +- test/rubygems/test_gem_commands_unpack_command.rb | 8 +- test/rubygems/test_gem_commands_update_command.rb | 8 +- test/rubygems/test_gem_commands_which_command.rb | 8 +- test/rubygems/test_gem_config_file.rb | 10 +- test/rubygems/test_gem_dependency.rb | 32 +---- test/rubygems/test_gem_dependency_installer.rb | 52 ++++---- test/rubygems/test_gem_dependency_list.rb | 8 +- test/rubygems/test_gem_doc_manager.rb | 8 +- test/rubygems/test_gem_ext_configure_builder.rb | 8 +- test/rubygems/test_gem_ext_ext_conf_builder.rb | 69 ++++++++-- test/rubygems/test_gem_ext_rake_builder.rb | 23 +--- test/rubygems/test_gem_format.rb | 10 +- test/rubygems/test_gem_gem_path_searcher.rb | 8 +- test/rubygems/test_gem_gem_runner.rb | 8 +- test/rubygems/test_gem_gemcutter_utilities.rb | 11 +- test/rubygems/test_gem_indexer.rb | 125 +----------------- test/rubygems/test_gem_install_update_options.rb | 10 +- test/rubygems/test_gem_installer.rb | 13 +- test/rubygems/test_gem_local_remote_options.rb | 27 +++- test/rubygems/test_gem_package_tar_header.rb | 8 +- test/rubygems/test_gem_package_tar_input.rb | 8 +- test/rubygems/test_gem_package_tar_output.rb | 8 +- test/rubygems/test_gem_package_tar_reader.rb | 8 +- test/rubygems/test_gem_package_tar_reader_entry.rb | 8 +- test/rubygems/test_gem_package_tar_writer.rb | 8 +- test/rubygems/test_gem_package_task.rb | 10 +- test/rubygems/test_gem_platform.rb | 9 +- test/rubygems/test_gem_remote_fetcher.rb | 24 ++-- test/rubygems/test_gem_requirement.rb | 12 +- test/rubygems/test_gem_security.rb | 96 ++++++++++++++ test/rubygems/test_gem_server.rb | 146 ++------------------- test/rubygems/test_gem_source_index.rb | 87 ++---------- test/rubygems/test_gem_spec_fetcher.rb | 8 +- test/rubygems/test_gem_specification.rb | 29 ++-- test/rubygems/test_gem_stream_ui.rb | 82 +++++++++++- test/rubygems/test_gem_text.rb | 49 +++++++ test/rubygems/test_gem_uninstaller.rb | 8 +- test/rubygems/test_gem_validator.rb | 10 +- test/rubygems/test_gem_version.rb | 45 ++++--- test/rubygems/test_gem_version_option.rb | 8 +- test/rubygems/test_kernel.rb | 21 +-- 85 files changed, 1202 insertions(+), 713 deletions(-) create mode 100644 test/rubygems/sff/discover.rb delete mode 100644 test/rubygems/test_gem_activation.rb delete mode 100644 test/rubygems/test_gem_commands_mirror_command.rb create mode 100644 test/rubygems/test_gem_security.rb create mode 100644 test/rubygems/test_gem_text.rb (limited to 'test/rubygems') diff --git a/test/rubygems/bogussources.rb b/test/rubygems/bogussources.rb index 008e3a1de5..fe12541c3d 100644 --- a/test/rubygems/bogussources.rb +++ b/test/rubygems/bogussources.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. diff --git a/test/rubygems/fake_certlib/openssl.rb b/test/rubygems/fake_certlib/openssl.rb index 9de90c0a10..aaf48735c0 100644 --- a/test/rubygems/fake_certlib/openssl.rb +++ b/test/rubygems/fake_certlib/openssl.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + #-- # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. # All rights reserved. diff --git a/test/rubygems/foo/discover.rb b/test/rubygems/foo/discover.rb index e69de29bb2..284a221bf9 100644 --- a/test/rubygems/foo/discover.rb +++ b/test/rubygems/foo/discover.rb @@ -0,0 +1,6 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + diff --git a/test/rubygems/functional.rb b/test/rubygems/functional.rb index 62f8c64d2d..6b7131f9d6 100644 --- a/test/rubygems/functional.rb +++ b/test/rubygems/functional.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + require 'rubygems' require 'minitest/unit' require 'test/insure_session' diff --git a/test/rubygems/gem_installer_test_case.rb b/test/rubygems/gem_installer_test_case.rb index ac353fbc43..6bf9687e86 100644 --- a/test/rubygems/gem_installer_test_case.rb +++ b/test/rubygems/gem_installer_test_case.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/installer' class Gem::Installer diff --git a/test/rubygems/gem_package_tar_test_case.rb b/test/rubygems/gem_package_tar_test_case.rb index f671693cc0..572c6b8a02 100644 --- a/test/rubygems/gem_package_tar_test_case.rb +++ b/test/rubygems/gem_package_tar_test_case.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 + + Gem::Package::TarReader::Entry.new header, io end def util_dir_entry diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index 66914d0c0e..fc27d6077c 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -1,8 +1,18 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + at_exit { $SAFE = 1 } -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -require 'rubygems' +if defined? Gem::QuickLoader + Gem::QuickLoader.load_full_rubygems_library +else + require 'rubygems' +end require 'fileutils' require 'minitest/autorun' require 'tmpdir' @@ -11,6 +21,8 @@ require 'rubygems/package' require 'rubygems/test_utilities' require 'pp' require 'yaml' +require 'zlib' + begin YAML::ENGINE.yamler = 'psych' rescue LoadError @@ -23,11 +35,11 @@ end require 'rdoc/rdoc' -require_relative 'mockgemui' +require "test/rubygems/mockgemui" module Gem def self.searcher=(searcher) - MUTEX.synchronize do @searcher = searcher end + @searcher = searcher end def self.source_index=(si) @@ -38,6 +50,10 @@ module Gem @@win_platform = val end + def self.ruby= ruby + @ruby = ruby + end + module DefaultUserInteraction @ui = MockGemUi.new end @@ -53,15 +69,19 @@ class RubyGemTestCase < MiniTest::Unit::TestCase def setup super + @orig_gem_home = ENV['GEM_HOME'] + @orig_gem_path = ENV['GEM_PATH'] + @ui = MockGemUi.new tmpdir = nil Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp - @tempdir = File.join tmpdir, "test_rubygems_#{$$}" + if ENV['KEEP_FILES'] then + @tempdir = File.join tmpdir, "test_rubygems_#{$$}.#{Time.now.to_i}" + else + @tempdir = File.join tmpdir, "test_rubygems_#{$$}" + end @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") + @gemhome = File.join @tempdir, 'gemhome' @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 + + @orig_LOAD_PATH = $LOAD_PATH.dup end def teardown + $LOAD_PATH.replace @orig_LOAD_PATH + 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 + FileUtils.rm_rf @tempdir unless ENV['KEEP_FILES'] - ENV.delete 'GEMCACHE' - ENV.delete 'GEM_HOME' - ENV.delete 'GEM_PATH' + ENV['GEM_HOME'] = @orig_gem_home + ENV['GEM_PATH'] = @orig_gem_path Gem.clear_paths - Gem.class_eval { @ruby = ruby } if ruby = @orig_ruby + _ = @orig_ruby + Gem.class_eval { @ruby = _ } if _ 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 uninstall_gem gem + require 'rubygems/uninstaller' + + uninstaller = Gem::Uninstaller.new gem.name, :executables => true, + :user_install => true + uninstaller.uninstall + 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) + def util_gem(name, version, deps = nil, &block) + if deps then # fuck you eric + block = proc do |s| + deps.each do |n, req| + s.add_dependency n, (req || '>= 0') + end + end + end + 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} + Gem.ruby = @@ruby env_rake = ENV["rake"] ENV["rake"] = @@rake yield @@rake ensure - Gem.module_eval {@ruby = gem_ruby} + Gem.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 = ENV["RUBY"] + return ruby if ruby ruby = "ruby" - rubyexe = ruby+".exe" + 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"] - ) + File.join(RbConfig::CONFIG["bindir"], + RbConfig::CONFIG["ruby_install_name"] + + RbConfig::CONFIG["EXEEXT"]) rescue LoadError "ruby" end diff --git a/test/rubygems/insure_session.rb b/test/rubygems/insure_session.rb index 8a6df89246..508450b23b 100644 --- a/test/rubygems/insure_session.rb +++ b/test/rubygems/insure_session.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + require 'rubygems' def install_session diff --git a/test/rubygems/mockgemui.rb b/test/rubygems/mockgemui.rb index 18ca70b821..52b0e7ffdc 100644 --- a/test/rubygems/mockgemui.rb +++ b/test/rubygems/mockgemui.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + require 'stringio' require 'rubygems/user_interaction' diff --git a/test/rubygems/plugin/exception/rubygems_plugin.rb b/test/rubygems/plugin/exception/rubygems_plugin.rb index affa72f09c..ef019a7193 100644 --- a/test/rubygems/plugin/exception/rubygems_plugin.rb +++ b/test/rubygems/plugin/exception/rubygems_plugin.rb @@ -1,2 +1,8 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + TestGem::TEST_PLUGIN_EXCEPTION = :loaded raise Exception.new('boom') \ No newline at end of file diff --git a/test/rubygems/plugin/load/rubygems_plugin.rb b/test/rubygems/plugin/load/rubygems_plugin.rb index bf020b0f6a..32faee7e2b 100644 --- a/test/rubygems/plugin/load/rubygems_plugin.rb +++ b/test/rubygems/plugin/load/rubygems_plugin.rb @@ -1 +1,7 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + TestGem::TEST_PLUGIN_LOAD = :loaded \ No newline at end of file diff --git a/test/rubygems/plugin/standarderror/rubygems_plugin.rb b/test/rubygems/plugin/standarderror/rubygems_plugin.rb index d36849f144..44efaef48a 100644 --- a/test/rubygems/plugin/standarderror/rubygems_plugin.rb +++ b/test/rubygems/plugin/standarderror/rubygems_plugin.rb @@ -1,2 +1,8 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + TestGem::TEST_PLUGIN_STANDARDERROR = :loaded raise StandardError.new('boom') \ No newline at end of file diff --git a/test/rubygems/rubygems/commands/crash_command.rb b/test/rubygems/rubygems/commands/crash_command.rb index e77b3fcd72..b34ac8e2f3 100644 --- a/test/rubygems/rubygems/commands/crash_command.rb +++ b/test/rubygems/rubygems/commands/crash_command.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + class Gem::Commands::CrashCommand < Gem::Command raise "crash" diff --git a/test/rubygems/rubygems_plugin.rb b/test/rubygems/rubygems_plugin.rb index 6c08f97c6d..e8c36a4a3f 100644 --- a/test/rubygems/rubygems_plugin.rb +++ b/test/rubygems/rubygems_plugin.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + require 'rubygems/command_manager' ## diff --git a/test/rubygems/sff/discover.rb b/test/rubygems/sff/discover.rb new file mode 100644 index 0000000000..284a221bf9 --- /dev/null +++ b/test/rubygems/sff/discover.rb @@ -0,0 +1,6 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + diff --git a/test/rubygems/simple_gem.rb b/test/rubygems/simple_gem.rb index e9207f95cc..d2145e6e47 100644 --- a/test/rubygems/simple_gem.rb +++ b/test/rubygems/simple_gem.rb @@ -1,3 +1,9 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + SIMPLE_GEM = <<-GEMDATA MD5SUM = "b12a4d48febeb2289c539c2574c4b6f8" if $0 == __FILE__ diff --git a/test/rubygems/test_config.rb b/test/rubygems/test_config.rb index 3458a1a682..da1998390b 100644 --- a/test/rubygems/test_config.rb +++ b/test/rubygems/test_config.rb @@ -1,11 +1,21 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems' class TestConfig < RubyGemTestCase def test_datadir - datadir = RbConfig::CONFIG['datadir'] - assert_equal "#{datadir}/xyz", RbConfig.datadir('xyz') + _, err = capture_io do + datadir = RbConfig::CONFIG['datadir'] + assert_equal "#{datadir}/xyz", RbConfig.datadir('xyz') + end + + assert_match(/deprecate/, err) end end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 91dbe226b5..6d17d65789 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 + def test_self_bin_path_nonexistent_binfile quick_gem 'a', '2' do |s| s.executables = ['exec'] end - assert_raises(Gem::Exception) do - Gem.bin_path('a', '2') + assert_raises(Gem::GemNotFoundException) do + Gem.bin_path('a', 'other', '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') + Gem.bin_path('a', nil, '1') end end @@ -86,6 +92,16 @@ class TestGem < RubyGemTestCase end end + def test_self_bin_path_bin_file_gone_in_latest + util_exec_gem + quick_gem 'a', '10' do |s| + s.executables = [] + s.default_executable = nil + end + # Should not find a-10's non-abin (bug) + assert_equal @abin_path, Gem.bin_path('a', 'abin') + 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' + discover_path = File.join 'lib', 'sff', 'discover.rb' cwd = File.expand_path '..', __FILE__ $LOAD_PATH.unshift cwd.dup - foo1 = quick_gem 'foo', '1' do |s| + foo1 = quick_gem 'sff', '1' do |s| s.files << discover_path end - foo2 = quick_gem 'foo', '2' do |s| + foo2 = quick_gem 'sff', '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.expand_path('../sff/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 + assert_equal expected, Gem.find_files('sff/discover') + assert_equal expected, Gem.find_files('sff/**.rb'), '[ruby-core:31730]' 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 util_path + ENV.delete "GEM_HOME" + ENV.delete "GEM_PATH" + end + def test_self_path assert_equal [Gem.dir], Gem.path end def test_self_path_default + util_path + 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 + util_path + 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 + if Gem.win_platform? then + def test_self_user_home_userprofile + skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION + + 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'] + # safe-keep env variables + orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE'] - # prepare the environment - ENV.delete('HOME') - ENV.delete('USERPROFILE') - ENV['HOMEDRIVE'] = 'Z:' - ENV['HOMEPATH'] = '\\Users\\RubyUser' + # prepare for the test + ENV.delete('HOME') + ENV['USERPROFILE'] = "W:\\Users\\RubyUser" - assert_equal "Z:\\Users\\RubyUser", Gem.user_home + assert_equal 'W:/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 + ensure + ENV['HOME'] = orig_home + ENV['USERPROFILE'] = orig_user_profile + end + + def test_self_user_home_user_drive_and_path + skip 'Ruby 1.9 properly handles ~ path expansion' unless '1.9' > RUBY_VERSION + + Gem.clear_paths + + # safe-keep env variables + orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE'] + orig_home_drive, orig_home_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['HOMEDRIVE'] = orig_home_drive + ENV['HOMEPATH'] = orig_home_path + end + end def test_load_plugins - with_plugin('load') { Gem.load_plugins } + plugin_path = File.join "lib", "rubygems_plugin.rb" + + Dir.chdir @tempdir do + FileUtils.mkdir_p 'lib' + File.open plugin_path, "w" do |fp| + fp.puts "TestGem::TEST_SPEC_PLUGIN_LOAD = :loaded" + end + + foo = quick_gem 'foo', '1' do |s| + s.files << plugin_path + end + + install_gem foo + end + + Gem.source_index = nil + + gem 'foo' + + Gem.load_plugins + + assert_equal :loaded, TEST_SPEC_PLUGIN_LOAD + end + + def test_load_env_plugins + with_plugin('load') { Gem.load_env_plugins } assert_equal :loaded, TEST_PLUGIN_LOAD util_remove_interrupt_command # Should attempt to cause a StandardError - with_plugin('standarderror') { Gem.load_plugins } + with_plugin('standarderror') { Gem.load_env_plugins } assert_equal :loaded, TEST_PLUGIN_STANDARDERROR util_remove_interrupt_command # Should attempt to cause an Exception - with_plugin('exception') { Gem.load_plugins } + with_plugin('exception') { Gem.load_env_plugins } assert_equal :loaded, TEST_PLUGIN_EXCEPTION end diff --git a/test/rubygems/test_gem_activation.rb b/test/rubygems/test_gem_activation.rb deleted file mode 100644 index 2d1cd4832d..0000000000 --- a/test/rubygems/test_gem_activation.rb +++ /dev/null @@ -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" diff --git a/test/rubygems/test_gem_builder.rb b/test/rubygems/test_gem_builder.rb index e5493ffc13..c007548ae5 100644 --- a/test/rubygems/test_gem_builder.rb +++ b/test/rubygems/test_gem_builder.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/builder' class TestGemBuilder < RubyGemTestCase diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb index 7897979d8f..e1db011d44 100644 --- a/test/rubygems/test_gem_command.rb +++ b/test/rubygems/test_gem_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/command' class Gem::Command diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index 815798ae06..66168f0fd5 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/command_manager' class TestGemCommandManager < RubyGemTestCase @@ -10,7 +16,9 @@ class TestGemCommandManager < RubyGemTestCase end def test_run_interrupt - Gem.load_plugins + old_load_path = $:.dup + $: << "test/rubygems" + Gem.load_env_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 + ensure + $:.replace old_load_path end def test_run_crash_command + old_load_path = $:.dup + $: << "test/rubygems" + @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 + ensure + $:.replace old_load_path 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 . ") + "install --force --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 .") + @command_manager.process_args("update --force --rdoc --install-dir .") assert_equal true, check_options[:generate_rdoc] assert_equal true, check_options[:force] assert_equal Dir.pwd, check_options[:install_dir] diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index db29226b71..9064974551 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/build_command' require 'rubygems/format' diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index 23c48439fc..6afd938861 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -1,5 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### +require "test/rubygems/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 + @cmd.options[: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 + @cmd.options[:issuer_key].to_s end def test_execute_remove diff --git a/test/rubygems/test_gem_commands_check_command.rb b/test/rubygems/test_gem_commands_check_command.rb index 83065cf218..14418148f0 100644 --- a/test/rubygems/test_gem_commands_check_command.rb +++ b/test/rubygems/test_gem_commands_check_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/check_command' class TestGemCommandsCheckCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_contents_command.rb b/test/rubygems/test_gem_commands_contents_command.rb index 2085947afa..e865e29af0 100644 --- a/test/rubygems/test_gem_commands_contents_command.rb +++ b/test/rubygems/test_gem_commands_contents_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/contents_command' class TestGemCommandsContentsCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb index 8463017d50..2f044dce16 100644 --- a/test/rubygems/test_gem_commands_dependency_command.rb +++ b/test/rubygems/test_gem_commands_dependency_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/dependency_command' class TestGemCommandsDependencyCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb index 6d694c3372..809e05327b 100644 --- a/test/rubygems/test_gem_commands_environment_command.rb +++ b/test/rubygems/test_gem_commands_environment_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/environment_command' class TestGemCommandsEnvironmentCommand < RubyGemTestCase @@ -131,5 +137,14 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase assert_equal '', @ui.error end -end + def test_execute_platform + @cmd.send :handle_options, %w[platform] + use_ui @ui do + @cmd.execute + end + + assert_equal "#{Gem.platforms.join File::PATH_SEPARATOR}\n", @ui.output + assert_equal '', @ui.error + end +end diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb index 909bcf89de..9a995a0e8e 100644 --- a/test/rubygems/test_gem_commands_fetch_command.rb +++ b/test/rubygems/test_gem_commands_fetch_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/package' require 'rubygems/security' require 'rubygems/commands/fetch_command' diff --git a/test/rubygems/test_gem_commands_generate_index_command.rb b/test/rubygems/test_gem_commands_generate_index_command.rb index 0952530e7f..21320bd721 100644 --- a/test/rubygems/test_gem_commands_generate_index_command.rb +++ b/test/rubygems/test_gem_commands_generate_index_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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' + marshal = File.join @gemhome, 'Marshal.4.8' + marshal_z = File.join @gemhome, 'Marshal.4.8.Z' - 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 + assert File.exist?(marshal), marshal + assert File.exist?(marshal_z), marshal_z end def test_execute_rss_update diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index ccdce787af..91e5a9ea0e 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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_nonexistent_with_hint + misspelled = "nonexistent_with_hint" + correctly_spelled = "non_existent_with_hint" + + util_setup_fake_fetcher + util_setup_spec_fetcher quick_gem(correctly_spelled, '2') + + @cmd.options[:args] = [misspelled] + + use_ui @ui do + e = assert_raises Gem::SystemExitException do + @cmd.execute + end + + assert_equal 2, e.exit_code + end + + expected = "ERROR: Could not find a valid gem 'nonexistent_with_hint' (>= 0) in any repository +ERROR: Possible alternatives: non_existent_with_hint +" + + assert_equal expected, @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 + def test_execute_conservative + util_setup_fake_fetcher + util_setup_spec_fetcher @b2 + + @fetcher.data["#{@gem_repo}gems/#{@b2.file_name}"] = + read_binary(File.join(@gemhome, 'cache', @b2.file_name)) + + uninstall_gem(@b2) + + @cmd.options[:conservative] = true + + @cmd.options[:args] = [@a2.name, @b2.name] + + use_ui @ui do + orig_dir = Dir.pwd + begin + Dir.chdir @tempdir + e = assert_raises Gem::SystemExitException do + @cmd.execute + end + assert_equal 0, e.exit_code + ensure + Dir.chdir orig_dir + end + end + + out = @ui.output.split "\n" + assert_equal "Successfully installed #{@b2.full_name}", out.shift + assert_equal "1 gem installed", out.shift + assert out.empty?, out.inspect + end end diff --git a/test/rubygems/test_gem_commands_list_command.rb b/test/rubygems/test_gem_commands_list_command.rb index e9de62f3d0..d4cfadda49 100644 --- a/test/rubygems/test_gem_commands_list_command.rb +++ b/test/rubygems/test_gem_commands_list_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/list_command' class TestGemCommandsListCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb index 11d1c4fe8a..7696bd8b0f 100644 --- a/test/rubygems/test_gem_commands_lock_command.rb +++ b/test/rubygems/test_gem_commands_lock_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/lock_command' class TestGemCommandsLockCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_mirror_command.rb b/test/rubygems/test_gem_commands_mirror_command.rb deleted file mode 100644 index 0c790ac24e..0000000000 --- a/test/rubygems/test_gem_commands_mirror_command.rb +++ /dev/null @@ -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 - diff --git a/test/rubygems/test_gem_commands_outdated_command.rb b/test/rubygems/test_gem_commands_outdated_command.rb index 1abfe0f984..10862dedf7 100644 --- a/test/rubygems/test_gem_commands_outdated_command.rb +++ b/test/rubygems/test_gem_commands_outdated_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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' + quick_gem 'foo', '0.1' + quick_gem 'foo', '0.2' remote_10 = quick_gem 'foo', '1.0' remote_20 = quick_gem 'foo', '2.0' diff --git a/test/rubygems/test_gem_commands_owner_command.rb b/test/rubygems/test_gem_commands_owner_command.rb index fa4281c6a7..f95061f0eb 100644 --- a/test/rubygems/test_gem_commands_owner_command.rb +++ b/test/rubygems/test_gem_commands_owner_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/owner_command' class TestGemCommandsOwnerCommand < RubyGemTestCase @@ -20,7 +26,7 @@ class TestGemCommandsOwnerCommand < RubyGemTestCase - email: user2@example.com EOF - @fetcher.data["https://rubygems.org/api/v1/gems/freewill/owners.yaml"] = [response, 200, 'OK'] + @fetcher.data["#{Gem.host}/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'] + @fetcher.data["#{Gem.host}/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'] + @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] use_ui @ui do @cmd.add_owners("freewill", ["user-new1@example.com"]) @@ -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'] + @fetcher.data["#{Gem.host}/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'] + @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 200, 'OK'] use_ui @ui do @cmd.remove_owners("freewill", ["user-remove1@example.com"]) @@ -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'] + @fetcher.data["#{Gem.host}/api/v1/gems/freewill/owners"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do diff --git a/test/rubygems/test_gem_commands_pristine_command.rb b/test/rubygems/test_gem_commands_pristine_command.rb index 06f43aa2b6..47df2e4a44 100644 --- a/test/rubygems/test_gem_commands_pristine_command.rb +++ b/test/rubygems/test_gem_commands_pristine_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/pristine_command' class TestGemCommandsPristineCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_push_command.rb b/test/rubygems/test_gem_commands_push_command.rb index d461bd8af6..7d7d89166f 100644 --- a/test/rubygems/test_gem_commands_push_command.rb +++ b/test/rubygems/test_gem_commands_push_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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'] - + def send_battery use_ui @ui do @cmd.send_gem(@path) end - assert_match %r{Pushing gem to RubyGems.org...}, @ui.output + assert_match %r{Pushing gem to #{Gem.host}...}, @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 + assert_match @response, @ui.output + end + + def test_sending_gem_default + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK'] + + send_battery + end + + def test_sending_gem_host + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK'] + @cmd.options[:host] = "#{Gem.host}" + + send_battery + end + + def test_sending_gem_ENV + @response = "Successfully registered gem: freewill (1.0.0)" + @fetcher.data["#{Gem.host}/api/v1/gems"] = [@response, 200, 'OK'] + ENV["RUBYGEMS_HOST"] = "#{Gem.host}" + + send_battery 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'] + @fetcher.data["#{Gem.host}/api/v1/gems"] = [response, 403, 'Forbidden'] assert_raises MockGemUi::TermError do use_ui @ui do diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index aa54e9f545..1a4a3e0b75 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb index 780e542036..8cdcb8b24b 100644 --- a/test/rubygems/test_gem_commands_server_command.rb +++ b/test/rubygems/test_gem_commands_server_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/server_command' class TestGemCommandsServerCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_sources_command.rb b/test/rubygems/test_gem_commands_sources_command.rb index 34632ea5f1..5930e2a9b7 100644 --- a/test/rubygems/test_gem_commands_sources_command.rb +++ b/test/rubygems/test_gem_commands_sources_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/sources_command' class TestGemCommandsSourcesCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_specification_command.rb b/test/rubygems/test_gem_commands_specification_command.rb index 6a43439969..abdbd733a3 100644 --- a/test/rubygems/test_gem_commands_specification_command.rb +++ b/test/rubygems/test_gem_commands_specification_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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' + quick_gem 'foo', '0.0.1' + 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' + quick_gem 'foo' + quick_gem 'foo_bar' @cmd.options[:args] = %w[foo] diff --git a/test/rubygems/test_gem_commands_stale_command.rb b/test/rubygems/test_gem_commands_stale_command.rb index 0bc7fc2734..4f72d13e81 100644 --- a/test/rubygems/test_gem_commands_stale_command.rb +++ b/test/rubygems/test_gem_commands_stale_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/stale_command' class TestGemCommandsStaleCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 6113ed61b2..cb995cd941 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'gem_installer_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" +require "test/rubygems/gem_installer_test_case" require 'rubygems/commands/uninstall_command' class TestGemCommandsUninstallCommand < GemInstallerTestCase diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb index f81a84e3ac..f8585d1265 100644 --- a/test/rubygems/test_gem_commands_unpack_command.rb +++ b/test/rubygems/test_gem_commands_unpack_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/unpack_command' class TestGemCommandsUnpackCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_update_command.rb b/test/rubygems/test_gem_commands_update_command.rb index 5264cd3955..7da4607151 100644 --- a/test/rubygems/test_gem_commands_update_command.rb +++ b/test/rubygems/test_gem_commands_update_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/update_command' class TestGemCommandsUpdateCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_commands_which_command.rb b/test/rubygems/test_gem_commands_which_command.rb index 137f598378..4a86067079 100644 --- a/test/rubygems/test_gem_commands_which_command.rb +++ b/test/rubygems/test_gem_commands_which_command.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/commands/which_command' class TestGemCommandsWhichCommand < RubyGemTestCase diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index b76ff7b180..ad0d65038f 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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'], diff --git a/test/rubygems/test_gem_dependency.rb b/test/rubygems/test_gem_dependency.rb index fb88735a03..723364be41 100644 --- a/test/rubygems/test_gem_dependency.rb +++ b/test/rubygems/test_gem_dependency.rb @@ -1,19 +1,13 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 237c0a02a4..80f6cd21fd 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 + @w1, @w1_gem = util_gem 'w', '1', 'x' => nil @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 + @z1, @z1_gem = util_gem 'z', '1', 'y' => nil @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_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| + _, 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' + _, e1_gem = util_gem 'e', '1' + _, f1_gem = util_gem 'f', '1', 'e' => nil + _, 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 + def assert_resolve expected, *specs + util_clear_gems + + util_setup_spec_fetcher(*specs) + inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'b' + inst.find_spec_by_name_and_version 'a' inst.gather_dependencies - assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name } + actual = inst.gems_to_install.map { |s| s.full_name } + assert_equal expected, actual 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 - + def test_gather_dependencies inst = Gem::DependencyInstaller.new - inst.find_spec_by_name_and_version 'c' + inst.find_spec_by_name_and_version 'b' inst.gather_dependencies - assert_equal %w[b-2 c-1], inst.gems_to_install.map { |s| s.full_name } + assert_equal %w[a-1 b-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 + e1, = util_gem 'e', '1', 'd' => '= 1' util_clear_gems - si = util_setup_spec_fetcher @d1, @d2, e1 + util_setup_spec_fetcher @d1, @d2, e1 inst = Gem::DependencyInstaller.new inst.find_spec_by_name_and_version 'e' diff --git a/test/rubygems/test_gem_dependency_list.rb b/test/rubygems/test_gem_dependency_list.rb index eacd912f7a..394676b6ab 100644 --- a/test/rubygems/test_gem_dependency_list.rb +++ b/test/rubygems/test_gem_dependency_list.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/dependency_list' class TestGemDependencyList < RubyGemTestCase diff --git a/test/rubygems/test_gem_doc_manager.rb b/test/rubygems/test_gem_doc_manager.rb index 46f425b9ba..7732df2608 100644 --- a/test/rubygems/test_gem_doc_manager.rb +++ b/test/rubygems/test_gem_doc_manager.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/doc_manager' class TestGemDocManager < RubyGemTestCase diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb index c4842034e9..2f2bac351d 100644 --- a/test/rubygems/test_gem_ext_configure_builder.rb +++ b/test/rubygems/test_gem_ext_configure_builder.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/ext' class TestGemExtConfigureBuilder < RubyGemTestCase diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb index d9483df2de..4b03858a2a 100644 --- a/test/rubygems/test_gem_ext_ext_conf_builder.rb +++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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] + case RUBY_PLATFORM + when /mswin/ then + assert_equal "nmake", output[2] + assert_equal "nmake install", output[4] + else + assert_equal "make", output[2] + assert_equal "make install", output[4] + end + end + + def test_class_build_rbconfig_make_prog + configure_args = RbConfig::CONFIG['configure_args'] + + File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf| + extconf.puts "require 'mkmf'\ncreate_makefile 'foo'" + end + + output = [] + + Dir.chdir @ext do + Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output + end + assert_equal "creating Makefile\n", output[1] assert_equal make_command, output[2] - assert_equal make_command + " install", output[4] + assert_equal "#{make_command} install", output[4] + ensure + RbConfig::CONFIG['configure_args'] = configure_args + end + + def test_class_build_env_make + configure_args, env_make = RbConfig::CONFIG['configure_args'], ENV.delete('make') + RbConfig::CONFIG['configure_args'] = '' + ENV['make'] = 'anothermake' + + File.open File.join(@ext, 'extconf.rb'), 'w' do |extconf| + extconf.puts "require 'mkmf'\ncreate_makefile 'foo'" + end + + output = [] + + assert_raises Gem::InstallError do + Dir.chdir @ext do + Gem::Ext::ExtConfBuilder.build 'extconf.rb', nil, @dest_path, output + end + end + + assert_equal "creating Makefile\n", output[1] + assert_equal "anothermake", output[2] + ensure + RbConfig::CONFIG['configure_args'] = configure_args + ENV['make'] = env_make end def test_class_build_extconf_fail diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb index 243852b86f..d2e7de4cda 100644 --- a/test/rubygems/test_gem_ext_rake_builder.rb +++ b/test/rubygems/test_gem_ext_rake_builder.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index 555f98d77c..0fa0bba4bf 100644 --- a/test/rubygems/test_gem_format.rb +++ b/test/rubygems/test_gem_format.rb @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'simple_gem' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" +require "test/rubygems/simple_gem" require 'rubygems/format' class TestGemFormat < RubyGemTestCase diff --git a/test/rubygems/test_gem_gem_path_searcher.rb b/test/rubygems/test_gem_gem_path_searcher.rb index 3fb54d08f2..c9f49681c7 100644 --- a/test/rubygems/test_gem_gem_path_searcher.rb +++ b/test/rubygems/test_gem_gem_path_searcher.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/gem_path_searcher' class Gem::GemPathSearcher diff --git a/test/rubygems/test_gem_gem_runner.rb b/test/rubygems/test_gem_gem_runner.rb index 5c3b03d473..78af8d9a4d 100644 --- a/test/rubygems/test_gem_gem_runner.rb +++ b/test/rubygems/test_gem_gem_runner.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/gem_runner' class TestGemGemRunner < RubyGemTestCase diff --git a/test/rubygems/test_gem_gemcutter_utilities.rb b/test/rubygems/test_gem_gemcutter_utilities.rb index f6495cbc74..c4d804bd43 100644 --- a/test/rubygems/test_gem_gemcutter_utilities.rb +++ b/test/rubygems/test_gem_gemcutter_utilities.rb @@ -1,6 +1,11 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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" + host = Gem.host end @fetcher = Gem::FakeFetcher.new diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 9474f3fd36..ebfe9c8105 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 385fd9d544..9000c4f873 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 + args = %w[-i /install_to --rdoc --ri -E -f -w -P HighSecurity --ignore-dependencies --format-exec --include-dependencies] assert @cmd.handles?(args) diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 3fcfa4fedc..3e329a2967 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_local_remote_options.rb b/test/rubygems/test_gem_local_remote_options.rb index 05083f5d07..7f122d29a6 100644 --- a/test/rubygems/test_gem_local_remote_options.rb +++ b/test/rubygems/test_gem_local_remote_options.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/local_remote_options' require 'rubygems/command' @@ -30,6 +36,21 @@ class TestGemLocalRemoteOptions < RubyGemTestCase assert_equal true, @cmd.both? end + def test_clear_sources_option + @cmd.add_local_remote_options + + s = URI.parse "http://only-gems.example.com/" + + @cmd.handle_options %W[--clear-sources --source #{s}] + assert_equal [s.to_s], Gem.sources + end + + def test_clear_sources_option_idiot_proof + @cmd.add_local_remote_options + @cmd.handle_options %W[--clear-sources] + assert_equal Gem.default_sources, Gem.sources + 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 + original_sources = Gem.sources.dup @cmd.handle_options %W[--source #{s1} --source #{s2} --source #{s3} --source #{s4}] - assert_equal [s1.to_s, s2.to_s, "#{s3}/"], Gem.sources + assert_equal [original_sources, s1.to_s, s2.to_s, "#{s3}/"].flatten, + Gem.sources end def test_update_sources_option diff --git a/test/rubygems/test_gem_package_tar_header.rb b/test/rubygems/test_gem_package_tar_header.rb index cda3a0d663..2f499a3e0d 100644 --- a/test/rubygems/test_gem_package_tar_header.rb +++ b/test/rubygems/test_gem_package_tar_header.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package' class TestGemPackageTarHeader < TarTestCase diff --git a/test/rubygems/test_gem_package_tar_input.rb b/test/rubygems/test_gem_package_tar_input.rb index 6938e97eba..377c4e452f 100644 --- a/test/rubygems/test_gem_package_tar_input.rb +++ b/test/rubygems/test_gem_package_tar_input.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package/tar_input' class TestGemPackageTarInput < TarTestCase diff --git a/test/rubygems/test_gem_package_tar_output.rb b/test/rubygems/test_gem_package_tar_output.rb index 0f2c0901ef..090f09284a 100644 --- a/test/rubygems/test_gem_package_tar_output.rb +++ b/test/rubygems/test_gem_package_tar_output.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package/tar_output' class TestGemPackageTarOutput < TarTestCase diff --git a/test/rubygems/test_gem_package_tar_reader.rb b/test/rubygems/test_gem_package_tar_reader.rb index 38ad48a94d..a57f5355fa 100644 --- a/test/rubygems/test_gem_package_tar_reader.rb +++ b/test/rubygems/test_gem_package_tar_reader.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package' class TestGemPackageTarReader < TarTestCase diff --git a/test/rubygems/test_gem_package_tar_reader_entry.rb b/test/rubygems/test_gem_package_tar_reader_entry.rb index 5323474541..1b39b2fd2d 100644 --- a/test/rubygems/test_gem_package_tar_reader_entry.rb +++ b/test/rubygems/test_gem_package_tar_reader_entry.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package' class TestGemPackageTarReaderEntry < TarTestCase diff --git a/test/rubygems/test_gem_package_tar_writer.rb b/test/rubygems/test_gem_package_tar_writer.rb index d819065a41..8a4c951286 100644 --- a/test/rubygems/test_gem_package_tar_writer.rb +++ b/test/rubygems/test_gem_package_tar_writer.rb @@ -1,4 +1,10 @@ -require_relative 'gem_package_tar_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_package_tar_test_case" require 'rubygems/package/tar_writer' class TestTarWriter < TarTestCase diff --git a/test/rubygems/test_gem_package_task.rb b/test/rubygems/test_gem_package_task.rb index 2e6710f4ac..11ed69e02b 100644 --- a/test/rubygems/test_gem_package_task.rb +++ b/test/rubygems/test_gem_package_task.rb @@ -1,8 +1,14 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems' require 'rubygems/package_task' -class TestGemPackageTask < MiniTest::Unit::TestCase +class TestGemPackageTask < RubyGemTestCase def test_gem_package gem = Gem::Specification.new do |g| diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 686493511f..ac8a65bf7a 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index d6b78dc7cc..fbeb19c239 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 'domain\user', fetcher.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_equal 'my pass', fetcher.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_equal 'foo\user', fetcher.unescape(proxy.user) + assert_equal 'my bar', fetcher.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 } + conn = { "#{Thread.current.object_id}: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 } + conn = { "#{Thread.current.object_id}: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 + rescue exception_class got_exception = true end + assert got_exception, "Expected exception conforming to #{exception_class}" end diff --git a/test/rubygems/test_gem_requirement.rb b/test/rubygems/test_gem_requirement.rb index a70dd0fd8e..03f3ddd5e7 100644 --- a/test/rubygems/test_gem_requirement.rb +++ b/test/rubygems/test_gem_requirement.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 "1.1.pre", "~> 1.1" refute_satisfied_by "2.0.a", "~> 1.0" - assert_satisfied_by "2.0.a", "~> 2.0" + refute_satisfied_by "2.0.a", "~> 2.0" end def test_satisfied_by_eh_multiple diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb new file mode 100644 index 0000000000..38128e6992 --- /dev/null +++ b/test/rubygems/test_gem_security.rb @@ -0,0 +1,96 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" +require 'rubygems/security' + +class TestGemSecurity < RubyGemTestCase + + def test_class_build_cert + name = OpenSSL::X509::Name.parse "CN=nobody/DC=example" + key = OpenSSL::PKey::RSA.new 512 + opt = { :cert_age => 60 } + + cert = Gem::Security.build_cert name, key, opt + + assert_kind_of OpenSSL::X509::Certificate, cert + + assert_equal 2, cert.version + assert_equal 0, cert.serial + assert_equal key.public_key.to_pem, cert.public_key.to_pem + assert_in_delta Time.now, cert.not_before, 10 + assert_in_delta Time.now + 60, cert.not_after, 10 + assert_equal name.to_s, cert.subject.to_s + + assert_equal 3, cert.extensions.length + + constraints = cert.extensions.find { |ext| ext.oid == 'basicConstraints' } + assert_equal 'CA:FALSE', constraints.value + + key_usage = cert.extensions.find { |ext| ext.oid == 'keyUsage' } + assert_equal 'Digital Signature, Key Encipherment, Data Encipherment', + key_usage.value + + key_ident = cert.extensions.find { |ext| ext.oid == 'subjectKeyIdentifier' } + assert_equal 59, key_ident.value.length + + assert_equal name.to_s, cert.issuer.to_s + assert_equal name.to_s, cert.subject.to_s + end + + def test_class_build_self_signed_cert + email = 'nobody@example' + opt = { + :cert_age => 60, + :key_size => 512, + :save_cert => false, + :save_key => false, + } + + result = Gem::Security.build_self_signed_cert email, opt + + key = result[:key] + + assert_kind_of OpenSSL::PKey::RSA, key + # assert_equal 512, key.something_here + + cert = result[:cert] + + assert_equal '/CN=nobody/DC=example', cert.issuer.to_s + end + + def test_class_sign_cert + name = OpenSSL::X509::Name.parse "CN=nobody/DC=example" + key = OpenSSL::PKey::RSA.new 512 + cert = OpenSSL::X509::Certificate.new + + cert.subject = name + cert.public_key = key.public_key + + signed = Gem::Security.sign_cert cert, key, cert + + assert cert.verify key + assert_equal name.to_s, signed.subject.to_s + end + + def test_class_email_to_name + munger = Gem::Security::OPT[:munge_re] + + assert_equal '/CN=nobody/DC=example', + Gem::Security.email_to_name('nobody@example', munger).to_s + + assert_equal '/CN=nobody/DC=example/DC=com', + Gem::Security.email_to_name('nobody@example.com', munger).to_s + + assert_equal '/CN=no.body/DC=example', + Gem::Security.email_to_name('no.body@example', munger).to_s + + assert_equal '/CN=no_body/DC=example', + Gem::Security.email_to_name('no+body@example', munger).to_s + end + +end + diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index 8f8a9cae05..f7ba61a4b5 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/server' require 'stringio' @@ -92,7 +98,7 @@ class TestGemServer < RubyGemTestCase def test_listen util_listen - out, err = capture_io do + capture_io do @server.listen end @@ -102,109 +108,11 @@ class TestGemServer < RubyGemTestCase def test_listen_addresses util_listen - out, err = capture_io do + 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) + assert_equal 2, @server.server.listeners.length 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 + 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, [] diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb index 40dfeb95c1..95ea94451d 100644 --- a/test/rubygems/test_gem_source_index.rb +++ b/test/rubygems/test_gem_source_index.rb @@ -1,13 +1,13 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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 + out, err = capture_io do assert_equal nil, Gem::SourceIndex.load_specification(spec_file) end - assert_equal '', @ui.output - - expected = <<-EOF -WARNING: # -raise Exception, "epic fail" -WARNING: Invalid .gemspec format in '#{spec_file}' - EOF + assert_equal '', out - assert_equal expected, @ui.error + expected = "Invalid gemspec in [#{spec_file}]: epic fail\n" + assert_equal expected, err 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 + out, err = capture_io do assert_equal nil, Gem::SourceIndex.load_specification(spec_file) end - assert_equal '', @ui.output + assert_equal '', out - assert_match(/syntax error/, @ui.error) - assert_match(/1 \+/, @ui.error) + assert_match(/syntax error/, err) 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 diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 95b74d9bfe..517247b98f 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/spec_fetcher' class TestGemSpecFetcher < RubyGemTestCase diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 97e2615fe2..573610b52d 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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) + capture_io do + Gem::Specification.load(specfile.path) + end rescue => e name_rexp = Regexp.new(Regexp.escape(specfile.path)) assert e.backtrace.grep(name_rexp).any? diff --git a/test/rubygems/test_gem_stream_ui.rb b/test/rubygems/test_gem_stream_ui.rb index 97f6f09833..60bd3032a8 100644 --- a/test/rubygems/test_gem_stream_ui.rb +++ b/test/rubygems/test_gem_stream_ui.rb @@ -1,5 +1,12 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/user_interaction' +require 'timeout' class TestGemStreamUI < RubyGemTestCase @@ -28,6 +35,7 @@ class TestGemStreamUI < RubyGemTestCase @err = StringIO.new @in.extend IsTty + @out.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 + def test_progress_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 + def test_progress_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 + def test_progress_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 + def test_progress_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 + def test_download_reporter_silent_nil + @cfg.verbose = nil + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + assert_kind_of Gem::StreamUI::SilentDownloadReporter, reporter + assert_equal "", @out.string + end + + def test_download_reporter_silent_false + @cfg.verbose = false + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + assert_kind_of Gem::StreamUI::SilentDownloadReporter, reporter + assert_equal "", @out.string + end + + def test_download_reporter_anything + @cfg.verbose = 0 + reporter = @sui.download_reporter + assert_kind_of Gem::StreamUI::VerboseDownloadReporter, reporter + end + + def test_verbose_download_reporter + @cfg.verbose = true + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + assert_equal "Fetching: a.gem", @out.string + end + def test_verbose_download_reporter_progress + @cfg.verbose = true + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + reporter.update 512 + assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)", @out.string + end + + def test_verbose_download_reporter_progress_once + @cfg.verbose = true + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + reporter.update 510 + reporter.update 512 + assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)", @out.string + end + + def test_verbose_download_reporter_progress_complete + @cfg.verbose = true + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + reporter.update 510 + reporter.done + assert_equal "Fetching: a.gem\rFetching: a.gem ( 50%)\rFetching: a.gem (100%)\n", @out.string + end + + def test_verbose_download_reporter_no_tty + @out.tty = false + + @cfg.verbose = true + reporter = @sui.download_reporter + reporter.fetch 'a.gem', 1024 + assert_equal "", @out.string + end +end diff --git a/test/rubygems/test_gem_text.rb b/test/rubygems/test_gem_text.rb new file mode 100644 index 0000000000..b800c5f58c --- /dev/null +++ b/test/rubygems/test_gem_text.rb @@ -0,0 +1,49 @@ +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" +require "rubygems/text" + +class TestGemText < RubyGemTestCase + include Gem::Text + + def test_format_text + assert_equal "text to\nwrap", format_text("text to wrap", 8) + end + + def test_format_text_indent + assert_equal " text to\n wrap", format_text("text to wrap", 8, 2) + end + + def test_format_text_none + assert_equal "text to wrap", format_text("text to wrap", 40) + end + + def test_format_text_none_indent + assert_equal " text to wrap", format_text("text to wrap", 40, 2) + end + + def test_levenshtein_distance_add + assert_equal 2, levenshtein_distance("zentest", "zntst") + assert_equal 2, levenshtein_distance("zntst", "zentest") + end + + def test_levenshtein_distance_empty + assert_equal 5, levenshtein_distance("abcde", "") + assert_equal 5, levenshtein_distance("", "abcde") + end + + def test_levenshtein_distance_remove + assert_equal 3, levenshtein_distance("zentest", "zentestxxx") + assert_equal 3, levenshtein_distance("zentestxxx", "zentest") + end + + def test_levenshtein_distance_replace + assert_equal 2, levenshtein_distance("zentest", "ZenTest") + assert_equal 7, levenshtein_distance("xxxxxxx", "ZenTest") + assert_equal 7, levenshtein_distance("zentest", "xxxxxxx") + end +end diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index d12ef032b9..9d42d9bcde 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -1,4 +1,10 @@ -require_relative 'gem_installer_test_case' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gem_installer_test_case" require 'rubygems/uninstaller' class TestGemUninstaller < GemInstallerTestCase diff --git a/test/rubygems/test_gem_validator.rb b/test/rubygems/test_gem_validator.rb index 51dad524f3..c7f23dcae8 100644 --- a/test/rubygems/test_gem_validator.rb +++ b/test/rubygems/test_gem_validator.rb @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require_relative 'simple_gem' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" +require "test/rubygems/simple_gem" require 'rubygems/validator' class TestGemValidator < RubyGemTestCase diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index f3692682b6..a3fbe24f15 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -1,5 +1,11 @@ -require_relative 'gemutilities' -require 'rubygems/version' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/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_alphanumeric + assert_bumped_version_equal "5.3", "5.2.4.a10" + 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" + assert_version_eql "1.2", "1.2" + refute_version_eql "1.2", "1.2.0" + refute_version_eql "1.2", "1.3" + refute_version_eql "1.2.b1", "1.2.b.1" end - def test_equals - assert_version_equal "1.2", "1.2" - refute_version_equal "1.2", "1.3" + def test_equals2 + assert_version_equal "1.2", "1.2" + refute_version_equal "1.2", "1.3" + assert_version_equal "1.2.b1", "1.2.b.1" 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")) + 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( 1, v("1.8.2.a10") <=> v("1.8.2.a9")) + assert_equal( 0, v("") <=> v("0")) + + assert_nil v("1.0") <=> "whatever" end def test_spermy_recommendation diff --git a/test/rubygems/test_gem_version_option.rb b/test/rubygems/test_gem_version_option.rb index af0b7bf662..a0b4eac380 100644 --- a/test/rubygems/test_gem_version_option.rb +++ b/test/rubygems/test_gem_version_option.rb @@ -1,4 +1,10 @@ -require_relative 'gemutilities' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" require 'rubygems/command' require 'rubygems/version_option' diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index 524b20d82b..dcbb8770f8 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -1,5 +1,10 @@ -require_relative 'gemutilities' -require 'rubygems/package' +###################################################################### +# This file is imported from the rubygems project. +# DO NOT make modifications in this repo. They _will_ be reverted! +# File a patch instead and assign it to Ryan Davis or Eric Hodel. +###################################################################### + +require "test/rubygems/gemutilities" 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_equal Gem::Requirement.new('= 2'), ex.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 + def test_gem_not_adding_bin + assert gem('a', '= 1'), "Should load" + refute $:.any? { |p| %r{a-1/bin} =~ p } + end end - -- cgit v1.2.3