From d478c7a7342478847cc1148f4134b5f0db04e1d9 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 25 Sep 2008 10:13:50 +0000 Subject: Update to RubyGems 1.3.0 r1891 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/gemutilities.rb | 37 ++++++- test/rubygems/mockgemui.rb | 24 +++- test/rubygems/test_gem.rb | 121 +++++++++++++++++++-- test/rubygems/test_gem_builder.rb | 2 +- test/rubygems/test_gem_command_manager.rb | 4 +- .../test_gem_commands_dependency_command.rb | 2 +- test/rubygems/test_gem_commands_install_command.rb | 10 +- test/rubygems/test_gem_commands_list_command.rb | 37 +++++++ test/rubygems/test_gem_commands_lock_command.rb | 69 ++++++++++++ test/rubygems/test_gem_commands_query_command.rb | 41 ++++++- .../test_gem_commands_uninstall_command.rb | 60 ++++++++++ test/rubygems/test_gem_config_file.rb | 5 + test/rubygems/test_gem_ext_configure_builder.rb | 5 +- test/rubygems/test_gem_ext_rake_builder.rb | 10 +- test/rubygems/test_gem_gem_path_searcher.rb | 22 ++-- test/rubygems/test_gem_install_update_options.rb | 6 +- test/rubygems/test_gem_installer.rb | 60 ++++++++-- test/rubygems/test_gem_local_remote_options.rb | 12 ++ test/rubygems/test_gem_package_tar_header.rb | 8 +- test/rubygems/test_gem_platform.rb | 19 +--- test/rubygems/test_gem_remote_fetcher.rb | 24 ++-- test/rubygems/test_gem_source_index.rb | 95 ++++++++++++---- test/rubygems/test_gem_source_info_cache.rb | 3 +- test/rubygems/test_gem_spec_fetcher.rb | 14 ++- test/rubygems/test_gem_specification.rb | 20 ++-- test/rubygems/test_gem_stream_ui.rb | 2 +- test/rubygems/test_gem_uninstaller.rb | 21 ++++ test/rubygems/test_gem_version.rb | 2 +- 28 files changed, 630 insertions(+), 105 deletions(-) create mode 100644 test/rubygems/test_gem_commands_list_command.rb create mode 100644 test/rubygems/test_gem_commands_lock_command.rb create mode 100644 test/rubygems/test_gem_commands_uninstall_command.rb (limited to 'test/rubygems') diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index 0ab2c5272c..d1e50676d5 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -19,6 +19,10 @@ require 'rubygems/test_utilities' require File.join(File.expand_path(File.dirname(__FILE__)), 'mockgemui') module Gem + def self.searcher=(searcher) + MUTEX.synchronize do @searcher = searcher end + end + def self.source_index=(si) @@source_index = si end @@ -26,7 +30,7 @@ module Gem def self.win_platform=(val) @@win_platform = val end - + module DefaultUserInteraction @ui = MockGemUi.new end @@ -89,6 +93,27 @@ class RubyGemTestCase < Test::Unit::TestCase 'private_key.pem') @public_cert = File.expand_path File.join(File.dirname(__FILE__), 'public_cert.pem') + + Gem.post_install_hooks.clear + Gem.post_uninstall_hooks.clear + Gem.pre_install_hooks.clear + Gem.pre_uninstall_hooks.clear + + Gem.post_install do |installer| + @post_install_hook_arg = installer + end + + Gem.post_uninstall do |uninstaller| + @post_uninstall_hook_arg = uninstaller + end + + Gem.pre_install do |installer| + @pre_install_hook_arg = installer + end + + Gem.pre_uninstall do |uninstaller| + @pre_uninstall_hook_arg = uninstaller + end end def teardown @@ -435,7 +460,15 @@ class RubyGemTestCase < Test::Unit::TestCase end @@ruby = rubybin - @@rake = ENV["rake"] || (@@ruby + " " + File.expand_path("../../../bin/rake", __FILE__)) + env_rake = ENV['rake'] + ruby19_rake = @@ruby + " " + File.expand_path("../../../bin/rake", __FILE__) + @@rake = if env_rake then + ENV["rake"] + elsif File.exist? ruby19_rake then + ruby19_rake + else + 'rake' + end end diff --git a/test/rubygems/mockgemui.rb b/test/rubygems/mockgemui.rb index 95a95fbf98..57582ef57d 100644 --- a/test/rubygems/mockgemui.rb +++ b/test/rubygems/mockgemui.rb @@ -12,8 +12,28 @@ require 'rubygems/user_interaction' class MockGemUi < Gem::StreamUI class TermError < RuntimeError; end - def initialize(input="") - super(StringIO.new(input), StringIO.new, StringIO.new) + module TTY + + attr_accessor :tty + + def tty?() + @tty = true unless defined?(@tty) + @tty + end + + end + + def initialize(input = "") + ins = StringIO.new input + outs = StringIO.new + errs = StringIO.new + + ins.extend TTY + outs.extend TTY + errs.extend TTY + + super ins, outs, errs + @terminated = false end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index c26eeb573d..6735f2f02a 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -45,7 +45,12 @@ class TestGem < RubyGemTestCase def test_self_bindir_default_dir default = Gem.default_dir - bindir = (defined? RUBY_FRAMEWORK_VERSION) ? '/usr/bin' : Config::CONFIG['bindir'] + bindir = if defined?(RUBY_FRAMEWORK_VERSION) then + '/usr/bin' + else + Config::CONFIG['bindir'] + end + assert_equal bindir, Gem.bindir(default) assert_equal bindir, Gem.bindir(Pathname.new(default)) end @@ -218,6 +223,36 @@ class TestGem < RubyGemTestCase Gem.ssl_available = orig_Gem_ssl_available end + def test_self_find_files + foo1 = quick_gem 'foo', '1' do |s| + s.files << 'lib/foo/discover.rb' + end + + foo2 = quick_gem 'foo', '2' do |s| + s.files << 'lib/foo/discover.rb' + end + + path = File.join 'gems', foo1.full_name, 'lib', 'foo', 'discover.rb' + write_file(path) { |fp| fp.puts "# #{path}" } + + path = File.join 'gems', foo2.full_name, 'lib', 'foo', 'discover.rb' + write_file(path) { |fp| fp.puts "# #{path}" } + + @fetcher = Gem::FakeFetcher.new + Gem::RemoteFetcher.fetcher = @fetcher + + Gem.source_index = util_setup_spec_fetcher foo1, foo2 + + Gem.searcher = nil + + expected = [ + File.join(foo1.full_gem_path, 'lib', 'foo', 'discover.rb'), + File.join(foo2.full_gem_path, 'lib', 'foo', 'discover.rb'), + ] + + assert_equal expected, Gem.find_files('foo/discover').sort + end + def test_self_latest_load_paths util_make_gems @@ -261,20 +296,21 @@ class TestGem < RubyGemTestCase unless win_platform? def test_self_path_APPLE_GEM_HOME Gem.clear_paths - Dir.mktmpdir("apple_gem_home") {|d| - Gem.const_set :APPLE_GEM_HOME, d - assert Gem.path.include?(d) - } + apple_gem_home = File.join @tempdir, 'apple_gem_home' + Gem.const_set :APPLE_GEM_HOME, apple_gem_home + + assert Gem.path.include?(apple_gem_home) ensure Gem.send :remove_const, :APPLE_GEM_HOME end - + def test_self_path_APPLE_GEM_HOME_GEM_PATH Gem.clear_paths ENV['GEM_PATH'] = @gemhome - Gem.const_set :APPLE_GEM_HOME, '/tmp/apple_gem_home' - - assert !Gem.path.include?('/tmp/apple_gem_home') + apple_gem_home = File.join @tempdir, 'apple_gem_home' + Gem.const_set :APPLE_GEM_HOME, apple_gem_home + + assert !Gem.path.include?(apple_gem_home) ensure Gem.send :remove_const, :APPLE_GEM_HOME end @@ -291,7 +327,7 @@ class TestGem < RubyGemTestCase assert_equal path_count + @additional.size, Gem.path.size, "extra path components: #{Gem.path[2..-1].inspect}" - assert_match Gem.dir, Gem.path.last + assert_equal Gem.dir, Gem.path.last end def test_self_path_duplicate @@ -390,6 +426,44 @@ class TestGem < RubyGemTestCase Gem.required_location("a", "code.rb", "= 2") end + def test_self_ruby_escaping_spaces_in_path + orig_ruby = Gem.ruby + orig_bindir = Gem::ConfigMap[:bindir] + orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name] + orig_exe_ext = Gem::ConfigMap[:EXEEXT] + + Gem::ConfigMap[:bindir] = "C:/Ruby 1.8/bin" + Gem::ConfigMap[:ruby_install_name] = "ruby" + Gem::ConfigMap[:EXEEXT] = ".exe" + Gem.instance_variable_set("@ruby", nil) + + assert_equal "\"C:/Ruby 1.8/bin/ruby.exe\"", Gem.ruby + ensure + Gem.instance_variable_set("@ruby", orig_ruby) + Gem::ConfigMap[:bindir] = orig_bindir + Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name + Gem::ConfigMap[:EXEEXT] = orig_exe_ext + end + + def test_self_ruby_path_without_spaces + orig_ruby = Gem.ruby + orig_bindir = Gem::ConfigMap[:bindir] + orig_ruby_install_name = Gem::ConfigMap[:ruby_install_name] + orig_exe_ext = Gem::ConfigMap[:EXEEXT] + + Gem::ConfigMap[:bindir] = "C:/Ruby18/bin" + Gem::ConfigMap[:ruby_install_name] = "ruby" + Gem::ConfigMap[:EXEEXT] = ".exe" + Gem.instance_variable_set("@ruby", nil) + + assert_equal "C:/Ruby18/bin/ruby.exe", Gem.ruby + ensure + Gem.instance_variable_set("@ruby", orig_ruby) + Gem::ConfigMap[:bindir] = orig_bindir + Gem::ConfigMap[:ruby_install_name] = orig_ruby_install_name + Gem::ConfigMap[:EXEEXT] = orig_exe_ext + end + def test_self_ruby_version version = RUBY_VERSION.dup version << ".#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL @@ -430,6 +504,11 @@ class TestGem < RubyGemTestCase assert_equal @additional + [Gem.dir], Gem.path end + def test_self_user_dir + assert_equal File.join(@userhome, '.gem', Gem.ruby_engine, + Gem::ConfigMap[:ruby_version]), Gem.user_dir + end + def test_self_user_home if ENV['HOME'] then assert_equal ENV['HOME'], Gem.user_home @@ -438,6 +517,28 @@ class TestGem < RubyGemTestCase end end + def test_self_user_home_user_drive_and_path + Gem.clear_paths + + # safe-keep env variables + orig_home, orig_user_profile = ENV['HOME'], ENV['USERPROFILE'] + orig_user_drive, orig_user_path = ENV['HOMEDRIVE'], ENV['HOMEPATH'] + + # prepare the environment + ENV.delete('HOME') + ENV.delete('USERPROFILE') + ENV['HOMEDRIVE'] = 'Z:' + ENV['HOMEPATH'] = '\\Users\\RubyUser' + + assert_equal "Z:\\Users\\RubyUser", Gem.user_home + + ensure + ENV['HOME'] = orig_home + ENV['USERPROFILE'] = orig_user_profile + ENV['USERDRIVE'] = orig_user_drive + ENV['USERPATH'] = orig_user_path + end + def util_ensure_gem_dirs Gem.ensure_gem_subdirectories @gemhome @additional.each do |dir| diff --git a/test/rubygems/test_gem_builder.rb b/test/rubygems/test_gem_builder.rb index 3463b4d403..31a0d71880 100644 --- a/test/rubygems/test_gem_builder.rb +++ b/test/rubygems/test_gem_builder.rb @@ -25,7 +25,7 @@ class TestGemBuilder < RubyGemTestCase def test_build_validates builder = Gem::Builder.new Gem::Specification.new - assert_raise Gem::InvalidSpecificationException do + assert_raises Gem::InvalidSpecificationException do builder.build end end diff --git a/test/rubygems/test_gem_command_manager.rb b/test/rubygems/test_gem_command_manager.rb index 59d3b5cb8e..ee58e89844 100644 --- a/test/rubygems/test_gem_command_manager.rb +++ b/test/rubygems/test_gem_command_manager.rb @@ -31,7 +31,7 @@ class TestGemCommandManager < RubyGemTestCase def test_run_interrupt use_ui @ui do @command_manager.register_command :interrupt - assert_raise MockGemUi::TermError do + assert_raises MockGemUi::TermError do @command_manager.run 'interrupt' end assert_equal '', ui.output @@ -41,7 +41,7 @@ class TestGemCommandManager < RubyGemTestCase def test_process_args_bad_arg use_ui @ui do - assert_raise(MockGemUi::TermError) { + assert_raises(MockGemUi::TermError) { @command_manager.process_args("--bad-arg") } end diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb index e143110a71..0acf2a0ddb 100644 --- a/test/rubygems/test_gem_commands_dependency_command.rb +++ b/test/rubygems/test_gem_commands_dependency_command.rb @@ -199,7 +199,7 @@ ERROR: Only reverse dependencies for local gems are supported. @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = si.dump - @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil + @fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz" FileUtils.rm File.join(@gemhome, 'specifications', "#{foo.full_name}.gemspec") diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb index e972429ce1..ef04072b93 100644 --- a/test/rubygems/test_gem_commands_install_command.rb +++ b/test/rubygems/test_gem_commands_install_command.rb @@ -43,7 +43,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase orig_dir = Dir.pwd begin Dir.chdir @tempdir - e = assert_raise Gem::SystemExitException do + e = assert_raises Gem::SystemExitException do @cmd.execute end assert_equal 0, e.exit_code @@ -65,7 +65,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase @cmd.options[:args] = %w[no_such_gem] use_ui @ui do - e = assert_raise Gem::SystemExitException do + e = assert_raises Gem::SystemExitException do @cmd.execute end assert_equal 2, e.exit_code @@ -91,7 +91,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase @cmd.options[:args] = %w[nonexistent] use_ui @ui do - e = assert_raise Gem::SystemExitException do + e = assert_raises Gem::SystemExitException do @cmd.execute end assert_equal 2, e.exit_code @@ -114,7 +114,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase @cmd.options[:args] = [@a2.name] use_ui @ui do - e = assert_raise Gem::SystemExitException do + e = assert_raises Gem::SystemExitException do @cmd.execute end assert_equal 0, e.exit_code @@ -146,7 +146,7 @@ class TestGemCommandsInstallCommand < RubyGemTestCase orig_dir = Dir.pwd begin Dir.chdir @tempdir - e = assert_raise Gem::SystemExitException do + e = assert_raises Gem::SystemExitException do @cmd.execute end assert_equal 0, e.exit_code diff --git a/test/rubygems/test_gem_commands_list_command.rb b/test/rubygems/test_gem_commands_list_command.rb new file mode 100644 index 0000000000..bac9cca03f --- /dev/null +++ b/test/rubygems/test_gem_commands_list_command.rb @@ -0,0 +1,37 @@ +require 'test/unit' +require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') +require 'rubygems/commands/list_command' + +class TestGemCommandsListCommand < RubyGemTestCase + + def setup + super + + @cmd = Gem::Commands::ListCommand.new + + util_setup_fake_fetcher + + @si = util_setup_spec_fetcher @a1, @a2, @pl1 + + @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = proc do + raise Gem::RemoteFetcher::FetchError + end + end + + def test_execute_installed + @cmd.handle_options %w[c --installed] + + e = assert_raise Gem::SystemExitException do + use_ui @ui do + @cmd.execute + end + end + + assert_equal 0, e.exit_code + + assert_equal "true\n", @ui.output + + assert_equal '', @ui.error + end + +end diff --git a/test/rubygems/test_gem_commands_lock_command.rb b/test/rubygems/test_gem_commands_lock_command.rb new file mode 100644 index 0000000000..089fed6e9a --- /dev/null +++ b/test/rubygems/test_gem_commands_lock_command.rb @@ -0,0 +1,69 @@ +require 'test/unit' +require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') +require 'rubygems/commands/lock_command' + +class TestGemCommandsLockCommand < RubyGemTestCase + + def setup + super + + @a1 = quick_gem 'a', '1' + @b1 = quick_gem 'b', '1' do |s| + s.add_runtime_dependency 'a' + end + + @d1 = quick_gem 'd', '1' do |s| + s.add_runtime_dependency 'z' + end + + @cmd = Gem::Commands::LockCommand.new + end + + def test_execute + @cmd.handle_options %w[b-1] + + use_ui @ui do + @cmd.execute + end + + expected = <<-EXPECTED +require 'rubygems' +gem 'b', '= 1' +gem 'a', '= 1' + EXPECTED + + assert_equal expected, @ui.output + assert_equal '', @ui.error + end + + def test_execute_missing_dependency + @cmd.handle_options %w[d-1] + + use_ui @ui do + @cmd.execute + end + + expected = <<-EXPECTED +require 'rubygems' +gem 'd', '= 1' +# Unable to satisfy 'z (>= 0, runtime)' from currently installed gems + EXPECTED + + assert_equal expected, @ui.output + assert_equal '', @ui.error + end + + def test_execute_strict + @cmd.handle_options %w[c-1 --strict] + + e = assert_raise Gem::Exception do + use_ui @ui do + @cmd.execute + end + end + + assert_equal 'Could not find gem c-1, try using the full name', e.message + end + +end + diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index 1b65fc7633..b17e2a3ad5 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -180,7 +180,7 @@ pl (1) @fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] = si.dump - @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil + @fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz" @cmd.handle_options %w[-r] @@ -265,6 +265,27 @@ pl (1) assert_equal '', @ui.error end + def test_execute_local_notty + @cmd.handle_options %w[] + + @ui.outs.tty = false + + use_ui @ui do + @cmd.execute + end + + expected = <<-EOF +a (2, 1) +a_evil (9) +b (2) +c (1.2) +pl (1) + EOF + + assert_equal expected, @ui.output + assert_equal '', @ui.error + end + def test_execute_no_versions @cmd.handle_options %w[-r --no-versions] @@ -284,5 +305,23 @@ pl assert_equal '', @ui.error end + def test_execute_notty + @cmd.handle_options %w[-r] + + @ui.outs.tty = false + + use_ui @ui do + @cmd.execute + end + + expected = <<-EOF +a (2) +pl (1) + EOF + + assert_equal expected, @ui.output + assert_equal '', @ui.error + end + end diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb new file mode 100644 index 0000000000..dfe84dc348 --- /dev/null +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -0,0 +1,60 @@ +require 'test/unit' +require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') +require File.join(File.expand_path(File.dirname(__FILE__)), + 'gem_installer_test_case') +require 'rubygems/commands/uninstall_command' + +class TestGemCommandsUninstallCommand < GemInstallerTestCase + + def setup + super + + ui = MockGemUi.new + util_setup_gem ui + + use_ui ui do + @installer.install + end + + @cmd = Gem::Commands::UninstallCommand.new + @cmd.options[:executables] = true + @executable = File.join(@gemhome, 'bin', 'executable') + end + + def test_execute_removes_executable + if win_platform? + assert_equal true, File.exist?(@executable) + else + assert_equal true, File.symlink?(@executable) + end + + # Evil hack to prevent false removal success + FileUtils.rm_f @executable + File.open(@executable, "wb+") {|f| f.puts "binary"} + + @cmd.options[:args] = Array(@spec.name) + use_ui @ui do + @cmd.execute + end + + output = @ui.output.split "\n" + assert_match(/Removing executable/, output.shift) + assert_match(/Successfully uninstalled/, output.shift) + assert_equal false, File.exist?(@executable) + assert_nil output.shift, "UI output should have contained only two lines" + end + + def test_execute_not_installed + @cmd.options[:args] = ["foo"] + e = assert_raise(Gem::InstallError) do + use_ui @ui do + @cmd.execute + end + end + + assert_match(/\AUnknown gem foo >= 0$/, e.message) + output = @ui.output.split "\n" + assert output.empty?, "UI output should be empty after an uninstall error" + end +end + diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 06321d4e7c..17071ef65f 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -57,6 +57,9 @@ class TestGemConfigFile < RubyGemTestCase fp.puts ":sources:" fp.puts " - http://more-gems.example.com" fp.puts "install: --wrappers" + fp.puts ":gempath:" + fp.puts "- /usr/ruby/1.8/lib/ruby/gems/1.8" + fp.puts "- /var/ruby/1.8/gem_home" end util_config_file @@ -68,6 +71,8 @@ class TestGemConfigFile < RubyGemTestCase assert_equal false, @cfg.update_sources 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'], + @cfg.path) end def test_initialize_handle_arguments_config_file diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb index 9ce17075bc..a1b656353a 100644 --- a/test/rubygems/test_gem_ext_configure_builder.rb +++ b/test/rubygems/test_gem_ext_configure_builder.rb @@ -53,12 +53,13 @@ class TestGemExtConfigureBuilder < RubyGemTestCase expected = %r(configure failed: #{Regexp.escape sh_prefix_configure}#{Regexp.escape @dest_path} -.*?: #{shell_error_msg}) +.*?: #{shell_error_msg} +) assert_match expected, error.message assert_equal "#{sh_prefix_configure}#{@dest_path}", output.shift - assert_match %r(#{shell_error_msg}\n), output.shift + assert_match %r(#{shell_error_msg}), output.shift assert_equal true, output.empty? end diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb index 6d9184e804..b1e7783d54 100644 --- a/test/rubygems/test_gem_ext_rake_builder.rb +++ b/test/rubygems/test_gem_ext_rake_builder.rb @@ -32,6 +32,8 @@ class TestGemExtRakeBuilder < RubyGemTestCase end end + output = output.join "\n" + expected = [ "#{@@ruby} mkrf_conf.rb", "", @@ -39,7 +41,9 @@ class TestGemExtRakeBuilder < RubyGemTestCase "(in #{realdir})\n" ] - assert_equal expected, output + assert_no_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 end def test_class_build_fail @@ -69,7 +73,9 @@ rake failed: #{@@rake} RUBYARCHDIR=#{@dest_path} RUBYLIBDIR=#{@dest_path} EOF - assert_equal expected, error.message.split("\n")[0..4].join("\n") + 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 end end diff --git a/test/rubygems/test_gem_gem_path_searcher.rb b/test/rubygems/test_gem_gem_path_searcher.rb index c9da4d2b05..a6124df84d 100644 --- a/test/rubygems/test_gem_gem_path_searcher.rb +++ b/test/rubygems/test_gem_gem_path_searcher.rb @@ -5,10 +5,6 @@ require 'rubygems/gem_path_searcher' class Gem::GemPathSearcher attr_accessor :gemspecs attr_accessor :lib_dirs - - public :init_gemspecs - public :matching_file - public :lib_dirs_for end class TestGemGemPathSearcher < RubyGemTestCase @@ -40,6 +36,10 @@ class TestGemGemPathSearcher < RubyGemTestCase assert_equal @foo1, @gps.find('foo') end + def test_find_all + assert_equal [@foo1], @gps.find_all('foo') + end + def test_init_gemspecs assert_equal [@bar2, @bar1, @foo2, @foo1], @gps.init_gemspecs end @@ -51,9 +51,17 @@ class TestGemGemPathSearcher < RubyGemTestCase assert_equal expected, lib_dirs end - def test_matching_file - assert !@gps.matching_file(@foo1, 'bar') - assert @gps.matching_file(@foo1, 'foo') + def test_matching_file_eh + assert !@gps.matching_file?(@foo1, 'bar') + assert @gps.matching_file?(@foo1, 'foo') + end + + def test_matching_files + assert_equal [], @gps.matching_files(@foo1, 'bar') + + expected = File.join @foo1.full_gem_path, 'lib', 'foo.rb' + + assert_equal [expected], @gps.matching_files(@foo1, 'foo') end end diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index 9a017384a5..cccbb74314 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -41,8 +41,8 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase @installer = Gem::Installer.new @gem, @cmd.options @installer.install - assert File.exist?(File.join(@userhome, '.gem', 'gems')) - assert File.exist?(File.join(@userhome, '.gem', 'gems', + assert File.exist?(File.join(Gem.user_dir, 'gems')) + assert File.exist?(File.join(Gem.user_dir, 'gems', @spec.full_name)) end @@ -52,7 +52,7 @@ class TestGemInstallUpdateOptions < GemInstallerTestCase File.chmod 0755, @userhome FileUtils.chmod 0000, @gemhome - assert_raise(Gem::FilePermissionError) do + assert_raises(Gem::FilePermissionError) do @installer = Gem::Installer.new @gem, @cmd.options end ensure diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index e57461f53a..4dc31efd1b 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -70,7 +70,10 @@ load 'my_exec' #{Gem.ruby}: No such file or directory -- extconf.rb (LoadError) EOF - assert_equal expected, File.read(gem_make_out) + assert_match %r%#{Regexp.escape Gem.ruby} extconf.rb%, + File.read(gem_make_out) + assert_match %r%#{Regexp.escape Gem.ruby}: No such file%, + File.read(gem_make_out) end def test_build_extensions_unsupported @@ -287,7 +290,7 @@ load 'my_exec' Dir.mkdir util_inst_bindir File.chmod 0000, util_inst_bindir - assert_raise Gem::FilePermissionError do + assert_raises Gem::FilePermissionError do @installer.generate_bin end @@ -372,7 +375,7 @@ load 'my_exec' Dir.mkdir util_inst_bindir File.chmod 0000, util_inst_bindir - assert_raise Gem::FilePermissionError do + assert_raises Gem::FilePermissionError do @installer.generate_bin end @@ -529,6 +532,16 @@ load 'my_exec' Dir.mkdir util_inst_bindir util_setup_gem + cache_file = File.join @gemhome, 'cache', "#{@spec.full_name}.gem" + + Gem.pre_install do |installer| + assert !File.exist?(cache_file), 'cache file should not exist yet' + end + + Gem.post_install do |installer| + assert File.exist?(cache_file), 'cache file should exist' + end + build_rake_in do use_ui @ui do assert_equal @spec, @installer.install @@ -552,6 +565,9 @@ load 'my_exec' assert_equal spec_file, @spec.loaded_from assert File.exist?(spec_file) + + assert_same @installer, @pre_install_hook_arg + assert_same @installer, @post_install_hook_arg end def test_install_bad_gem @@ -586,6 +602,29 @@ load 'my_exec' end end + def test_install_check_dependencies_install_dir + gemhome2 = "#{@gemhome}2" + @spec.add_dependency 'b' + + b2 = quick_gem 'b', 2 + + FileUtils.mv @gemhome, gemhome2 + Gem.source_index.gems.delete b2.full_name + source_index = Gem::SourceIndex.from_gems_in File.join(gemhome2, + 'specifications') + + util_setup_gem + + @installer = Gem::Installer.new @gem, :install_dir => gemhome2, + :source_index => source_index + + use_ui @ui do + @installer.install + end + + assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name)) + end + def test_install_force use_ui @ui do installer = Gem::Installer.new old_ruby_required, :force => true @@ -641,13 +680,13 @@ load 'my_exec' assert File.exist?(File.join(@gemhome, 'specifications', "#{@spec.full_name}.gemspec")) end + unless win_platform? # File.chmod doesn't work def test_install_user_local_fallback Dir.mkdir util_inst_bindir File.chmod 0755, @userhome File.chmod 0000, util_inst_bindir File.chmod 0000, Gem.dir - install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name @spec.executables = ["executable"] build_rake_in do @@ -656,9 +695,10 @@ load 'my_exec' @installer.install end end - - assert File.exist?(File.join(install_dir, 'lib', 'code.rb')) - assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) + + assert File.exist?(File.join(Gem.user_dir, 'gems', + @spec.full_name, 'lib', 'code.rb')) + assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable')) ensure File.chmod 0755, Gem.dir File.chmod 0755, util_inst_bindir @@ -676,13 +716,13 @@ load 'my_exec' @installer.install end end - - assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) + + assert File.exist?(File.join(Gem.user_dir, 'bin', 'executable')) ensure File.chmod 0755, util_inst_bindir end end - + def test_install_with_message @spec.post_install_message = 'I am a shiny gem!' diff --git a/test/rubygems/test_gem_local_remote_options.rb b/test/rubygems/test_gem_local_remote_options.rb index e676c94f21..5f2a1d3d86 100644 --- a/test/rubygems/test_gem_local_remote_options.rb +++ b/test/rubygems/test_gem_local_remote_options.rb @@ -19,6 +19,18 @@ class TestGemLocalRemoteOptions < RubyGemTestCase assert @cmd.handles?(args) end + def test_both_eh + assert_equal false, @cmd.both? + + @cmd.options[:domain] = :local + + assert_equal false, @cmd.both? + + @cmd.options[:domain] = :both + + assert_equal true, @cmd.both? + end + def test_local_eh assert_equal false, @cmd.local? diff --git a/test/rubygems/test_gem_package_tar_header.rb b/test/rubygems/test_gem_package_tar_header.rb index 9158061cf6..9b7708dca8 100644 --- a/test/rubygems/test_gem_package_tar_header.rb +++ b/test/rubygems/test_gem_package_tar_header.rb @@ -62,19 +62,19 @@ class TestGemPackageTarHeader < TarTestCase end def test_initialize_bad - assert_raise ArgumentError do + assert_raises ArgumentError do Gem::Package::TarHeader.new :name => '', :size => '', :mode => '' end - assert_raise ArgumentError do + assert_raises ArgumentError do Gem::Package::TarHeader.new :name => '', :size => '', :prefix => '' end - assert_raise ArgumentError do + assert_raises ArgumentError do Gem::Package::TarHeader.new :name => '', :prefix => '', :mode => '' end - assert_raise ArgumentError do + assert_raises ArgumentError do Gem::Package::TarHeader.new :prefix => '', :size => '', :mode => '' end end diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 648c2a9f36..362a366266 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -5,19 +5,6 @@ require 'rbconfig' class TestGemPlatform < RubyGemTestCase - def test_self_const_missing - consts = [:DARWIN, :LINUX_586, :MSWIN32, :PPC_DARWIN, :WIN32, :X86_LINUX] - - consts.each do |const| - e = assert_raise NameError do - Gem::Platform.const_missing const - end - - assert_equal "#{const} has been removed, use CURRENT instead", - e.message - end - end - def test_self_local util_set_arch 'i686-darwin8.10.1' @@ -105,6 +92,12 @@ class TestGemPlatform < RubyGemTestCase platform = Gem::Platform.new 'i386-mswin32-80' assert_equal expected, platform.to_a, 'i386-mswin32-80' + + expected = ['x86', 'solaris', '2.10'] + + platform = Gem::Platform.new 'i386-solaris-2.10' + + assert_equal expected, platform.to_a, 'i386-solaris-2.10' end def test_initialize_mswin32_vc6 diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 484104dd8f..103cb38898 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -268,15 +268,15 @@ gems: ensure File.chmod 0755, File.join(@gemhome, 'cache') end - + def test_download_read_only File.chmod 0555, File.join(@gemhome, 'cache') File.chmod 0555, File.join(@gemhome) fetcher = util_fuck_with_fetcher File.read(@a1_gem) fetcher.download(@a1, 'http://gems.example.com') - assert File.exist?(File.join(@userhome, '.gem', - 'cache', "#{@a1.full_name}.gem")) + assert File.exist?(File.join(Gem.user_dir, 'cache', + "#{@a1.full_name}.gem")) ensure File.chmod 0755, File.join(@gemhome) File.chmod 0755, File.join(@gemhome, 'cache') @@ -391,6 +391,16 @@ gems: assert_equal 'foo', fetcher.fetch_path(@uri + 'foo.gz') end + def test_fetch_path_gzip_unmodified + fetcher = Gem::RemoteFetcher.new nil + + def fetcher.open_uri_or_path(uri, mtime, head = nil) + nil + end + + assert_equal nil, fetcher.fetch_path(@uri + 'foo.gz', Time.at(0)) + end + def test_fetch_path_io_error fetcher = Gem::RemoteFetcher.new nil @@ -441,10 +451,10 @@ gems: fetcher = Gem::RemoteFetcher.new nil def fetcher.open_uri_or_path(uri, mtime, head = nil) - '' + nil end - assert_equal '', fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) + assert_equal nil, fetcher.fetch_path(URI.parse(@gem_repo), Time.at(0)) end def test_get_proxy_from_env_empty @@ -504,7 +514,7 @@ gems: def conn.request(req) unless defined? @requested then @requested = true - res = Net::HTTPRedirection.new nil, 301, nil + res = Net::HTTPMovedPermanently.new nil, 301, nil res.add_field 'Location', 'http://gems.example.com/real_path' res else @@ -528,7 +538,7 @@ gems: conn = Object.new def conn.started?() true end def conn.request(req) - res = Net::HTTPRedirection.new nil, 301, nil + res = Net::HTTPMovedPermanently.new nil, 301, nil res.add_field 'Location', 'http://gems.example.com/redirect' res end diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb index 263826759a..7f379ef19a 100644 --- a/test/rubygems/test_gem_source_index.rb +++ b/test/rubygems/test_gem_source_index.rb @@ -64,6 +64,54 @@ class TestGemSourceIndex < RubyGemTestCase assert_equal a1.author, spec.author end + def test_self_load_specification_utf_8 + spec_dir = File.join @gemhome, 'specifications' + + FileUtils.rm_r spec_dir + + FileUtils.mkdir_p spec_dir + + spec_file = File.join spec_dir, "utf-8.gemspec" + spec_data = <<-SPEC +Gem::Specification.new do |s| + s.name = %q{utf} + s.version = "8" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") + s.authors = ["\317\200"] + s.date = %q{2008-09-10} + s.description = %q{This is a test description} + s.email = %q{example@example.com} + s.has_rdoc = true + s.homepage = %q{http://example.com} + s.require_paths = ["lib"] + s.rubygems_version = %q{1.2.0} + s.summary = %q{this is a summary} + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 2 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end + SPEC + + spec_data.force_encoding 'UTF-8' + + File.open spec_file, 'w' do |io| io.write spec_data end + + spec = Gem::SourceIndex.load_specification spec_file + + pi = "\317\200" + pi.force_encoding 'UTF-8' if pi.respond_to? :force_encoding + + assert_equal pi, spec.author + end if Gem.ruby_version > Gem::Version.new('1.9') + def test_self_load_specification_exception spec_dir = File.join @gemhome, 'specifications' @@ -437,6 +485,27 @@ WARNING: Invalid .gemspec format in '#{spec_file}' assert_equal [], missing end + def test_find_name + assert_equal [@a1, @a2], @source_index.find_name('a') + assert_equal [@a2], @source_index.find_name('a', '= 2') + assert_equal [], @source_index.find_name('bogusstring') + assert_equal [], @source_index.find_name('a', '= 3') + + source_index = Gem::SourceIndex.new + source_index.add_spec @a1 + source_index.add_spec @a2 + + assert_equal [@a1], source_index.find_name(@a1.name, '= 1') + + r1 = Gem::Requirement.create '= 1' + assert_equal [@a1], source_index.find_name(@a1.name, r1) + end + + def test_find_name_empty_cache + empty_source_index = Gem::SourceIndex.new({}) + assert_equal [], empty_source_index.find_name("foo") + end + def test_latest_specs p1_ruby = quick_gem 'p', '1' p1_platform = quick_gem 'p', '1' do |spec| @@ -573,28 +642,12 @@ WARNING: Invalid .gemspec format in '#{spec_file}' end def test_search - assert_equal [@a1, @a2, @a_evil9], @source_index.search('a') - assert_equal [@a2], @source_index.search('a', '= 2') - - assert_equal [], @source_index.search('bogusstring') - assert_equal [], @source_index.search('a', '= 3') + requirement = Gem::Requirement.create '= 9' + with_version = Gem::Dependency.new(/^a/, requirement) + assert_equal [@a_evil9], @source_index.search(with_version) - source_index = Gem::SourceIndex.new - source_index.add_spec @a1 - source_index.add_spec @a2 - - assert_equal [@a1], source_index.search(@a1.name, '= 1') - - r1 = Gem::Requirement.create '= 1' - assert_equal [@a1], source_index.search(@a1.name, r1) - - dep = Gem::Dependency.new @a1.name, r1 - assert_equal [@a1], source_index.search(dep) - end - - def test_search_empty_cache - empty_source_index = Gem::SourceIndex.new({}) - assert_equal [], empty_source_index.search("foo") + with_default = Gem::Dependency.new(/^a/, Gem::Requirement.default) + assert_equal [@a1, @a2, @a_evil9], @source_index.search(with_default) end def test_search_platform diff --git a/test/rubygems/test_gem_source_info_cache.rb b/test/rubygems/test_gem_source_info_cache.rb index 86866a8012..744a51c154 100644 --- a/test/rubygems/test_gem_source_info_cache.rb +++ b/test/rubygems/test_gem_source_info_cache.rb @@ -224,7 +224,8 @@ class TestGemSourceInfoCache < RubyGemTestCase @sic.set_cache_data @gem_repo => sice latest = @sic.latest_cache_data - gems = latest[@gem_repo].source_index.search('a').map { |s| s.full_name } + beginning_with_a = Gem::Dependency.new(/^a/, Gem::Requirement.default) + gems = latest[@gem_repo].source_index.search(beginning_with_a).map { |s| s.full_name } assert_equal %w[a-2 a_evil-9], gems end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index 2e9ce1b7eb..8f3ab77bb8 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -67,7 +67,7 @@ class TestGemSpecFetcher < RubyGemTestCase end def test_fetch_legacy_repo - @fetcher.data["#{@gem_repo}specs.#{Gem.marshal_version}.gz"] = nil + @fetcher.data.delete "#{@gem_repo}specs.#{Gem.marshal_version}.gz" @fetcher.data["#{@gem_repo}yaml"] = '' util_setup_source_info_cache @a1, @a2 @@ -259,6 +259,16 @@ RubyGems will revert to legacy indexes degrading performance. assert_equal specs, cached_specs end + def test_list_latest_all + specs = @sf.list false + + assert_equal [@latest_specs], specs.values + + specs = @sf.list true + + assert_equal [@specs], specs.values, 'specs file not loaded' + end + def test_load_specs specs = @sf.load_specs @uri, 'specs' @@ -280,7 +290,7 @@ RubyGems will revert to legacy indexes degrading performance. end def test_load_specs_cached - @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = '' + @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = nil @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}"] = ' ' * Marshal.dump(@latest_specs).length diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 57c3fdc158..9c3b585c91 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -500,7 +500,7 @@ end end def test_has_rdoc_eh - assert_equal true, @a1.has_rdoc? + assert @a1.has_rdoc? end def test_hash @@ -634,7 +634,10 @@ end ruby_code = @a2.to_ruby - expected = "Gem::Specification.new do |s| + expected = <<-SPEC +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| s.name = %q{a} s.version = \"2\" @@ -654,7 +657,7 @@ end current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} - if current_version >= 3 then + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [\"= 1\"]) else s.add_dependency(%q, [\"= 1\"]) @@ -663,7 +666,7 @@ end s.add_dependency(%q, [\"= 1\"]) end end -" + SPEC assert_equal expected, ruby_code @@ -679,7 +682,10 @@ end local = Gem::Platform.local expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]" - expected = "Gem::Specification.new do |s| + expected = <<-SPEC +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| s.name = %q{a} s.version = \"1\" s.platform = Gem::Platform.new(#{expected_platform}) @@ -706,7 +712,7 @@ end current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION s.specification_version = 2 - if current_version >= 3 then + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [\"> 0.4\"]) s.add_runtime_dependency(%q, [\"> 0.0.0\"]) s.add_runtime_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) @@ -721,7 +727,7 @@ end s.add_dependency(%q, [\"> 0.4\", \"<= 0.6\"]) end end -" + SPEC assert_equal expected, ruby_code diff --git a/test/rubygems/test_gem_stream_ui.rb b/test/rubygems/test_gem_stream_ui.rb index caf620ff00..a8564ba94f 100644 --- a/test/rubygems/test_gem_stream_ui.rb +++ b/test/rubygems/test_gem_stream_ui.rb @@ -63,7 +63,7 @@ class TestGemStreamUI < RubyGemTestCase @in.tty = false timeout(0.1) do - assert_raise(Gem::OperationNotSupportedError) do + assert_raises(Gem::OperationNotSupportedError) do @sui.ask_yes_no("do coconuts migrate?") end end diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index 7d7890c3ea..bb90f5cc5f 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -62,5 +62,26 @@ class TestGemUninstaller < GemInstallerTestCase assert_equal true, uninstaller.path_ok?(@spec) end + def test_uninstall + uninstaller = Gem::Uninstaller.new @spec.name, :executables => true + + gem_dir = File.join @gemhome, 'gems', @spec.full_name + + Gem.pre_uninstall do + assert File.exist?(gem_dir), 'gem_dir should exist' + end + + Gem.post_uninstall do + assert !File.exist?(gem_dir), 'gem_dir should not exist' + end + + uninstaller.uninstall + + assert !File.exist?(gem_dir) + + assert_same uninstaller, @pre_uninstall_hook_arg + assert_same uninstaller, @post_uninstall_hook_arg + end + end diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 5c04502d48..8d10700490 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -107,7 +107,7 @@ class TestGemVersion < RubyGemTestCase def test_illformed_requirements [ ">>> 1.3.5", "> blah" ].each do |rq| - assert_raise(ArgumentError, "req [#{rq}] should fail") { + assert_raises(ArgumentError, "req [#{rq}] should fail") { Gem::Version::Requirement.new(rq) } end -- cgit v1.2.3