From 8289771e326006cc4e15a667e3eff3a72cfb3327 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 20 Dec 2007 08:39:12 +0000 Subject: Import RubyGems 1.0.0, r1575 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/gemutilities.rb | 21 +- test/rubygems/test_gem.rb | 122 ++---- test/rubygems/test_gem_commands_build_command.rb | 24 +- .../test_gem_commands_dependency_command.rb | 20 +- test/rubygems/test_gem_commands_mirror_command.rb | 13 +- test/rubygems/test_gem_commands_query_command.rb | 10 +- test/rubygems/test_gem_commands_server_command.rb | 27 ++ test/rubygems/test_gem_commands_unpack_command.rb | 22 +- test/rubygems/test_gem_format.rb | 2 +- test/rubygems/test_gem_indexer.rb | 10 +- test/rubygems/test_gem_install_update_options.rb | 2 +- test/rubygems/test_gem_installer.rb | 198 ++++++--- test/rubygems/test_gem_platform.rb | 17 + test/rubygems/test_gem_remote_fetcher.rb | 21 +- test/rubygems/test_gem_remote_installer.rb | 161 ------- test/rubygems/test_gem_server.rb | 45 +- test/rubygems/test_gem_source_index.rb | 4 +- test/rubygems/test_gem_specification.rb | 468 +++++++++++++-------- test/rubygems/test_gem_version.rb | 15 + test/rubygems/test_kernel.rb | 38 +- 20 files changed, 712 insertions(+), 528 deletions(-) create mode 100644 test/rubygems/test_gem_commands_server_command.rb delete mode 100644 test/rubygems/test_gem_remote_installer.rb (limited to 'test/rubygems') diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index bb54ff6362..460d8f2080 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -89,6 +89,9 @@ class RubyGemTestCase < Test::Unit::TestCase @gem_repo = "http://gems.example.com" Gem.sources.replace [@gem_repo] + @orig_BASERUBY = Gem::ConfigMap[:BASERUBY] + Gem::ConfigMap[:BASERUBY] = Gem::ConfigMap[:RUBY_INSTALL_NAME] + @orig_arch = Gem::ConfigMap[:arch] if win_platform? @@ -101,6 +104,7 @@ class RubyGemTestCase < Test::Unit::TestCase end def teardown + Gem::ConfigMap[:BASERUBY] = @orig_BASERUBY Gem::ConfigMap[:arch] = @orig_arch if defined? Gem::RemoteFetcher then @@ -153,7 +157,7 @@ class RubyGemTestCase < Test::Unit::TestCase path end - def quick_gem(gemname, version='0.0.2') + def quick_gem(gemname, version='2') require 'rubygems/specification' spec = Gem::Specification.new do |s| @@ -166,6 +170,7 @@ class RubyGemTestCase < Test::Unit::TestCase s.has_rdoc = true s.summary = "this is a summary" s.description = "This is a test description" + yield(s) if block_given? end @@ -205,9 +210,9 @@ class RubyGemTestCase < Test::Unit::TestCase s.require_paths = %w[lib] end - @a0_0_1 = quick_gem('a', '0.0.1', &spec) - @a0_0_2 = quick_gem('a', '0.0.2', &spec) - @b0_0_2 = quick_gem('b', '0.0.2', &spec) + @a1 = quick_gem('a', '1', &spec) + @a2 = quick_gem('a', '2', &spec) + @b2 = quick_gem('b', '2', &spec) @c1_2 = quick_gem('c', '1.2', &spec) @pl1 = quick_gem 'pl', '1' do |s| # l for legacy s.files = %w[lib/code.rb] @@ -216,13 +221,13 @@ class RubyGemTestCase < Test::Unit::TestCase s.instance_variable_set :@original_platform, 'i386-linux' end - write_file File.join(*%W[gems #{@a0_0_1.original_name} lib code.rb]) do end - write_file File.join(*%W[gems #{@a0_0_2.original_name} lib code.rb]) do end - write_file File.join(*%W[gems #{@b0_0_2.original_name} lib code.rb]) do end + write_file File.join(*%W[gems #{@a1.original_name} lib code.rb]) do end + write_file File.join(*%W[gems #{@a2.original_name} lib code.rb]) do end + write_file File.join(*%W[gems #{@b2.original_name} lib code.rb]) do end write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb]) do end write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end - [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].each { |spec| util_build_gem spec } + [@a1, @a2, @b2, @c1_2, @pl1].each { |spec| util_build_gem spec } FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name) diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 4fe5e8661c..c5ed86a489 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -2,6 +2,7 @@ require 'test/unit' require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') require 'rubygems' require 'rubygems/gem_openssl' +require 'rubygems/installer' require 'pathname' class TestGem < RubyGemTestCase @@ -17,9 +18,9 @@ class TestGem < RubyGemTestCase util_make_gems expected = [ - File.join(@gemhome, *%W[gems #{@a0_0_1.full_name} lib]), - File.join(@gemhome, *%W[gems #{@a0_0_2.full_name} lib]), - File.join(@gemhome, *%W[gems #{@b0_0_2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@a1.full_name} lib]), + File.join(@gemhome, *%W[gems #{@a2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@b2.full_name} lib]), File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]), File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]), ] @@ -89,6 +90,42 @@ class TestGem < RubyGemTestCase assert_match @default_dir_re, Gem.default_dir end + def test_self_default_exec_format + orig_BASERUBY = Gem::ConfigMap[:BASERUBY] + orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME] + Gem::ConfigMap[:BASERUBY] = 'ruby' + Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby' + + assert_equal '%s', Gem.default_exec_format + ensure + Gem::ConfigMap[:BASERUBY] = orig_BASERUBY + Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME + end + + def test_self_default_exec_format_18 + orig_BASERUBY = Gem::ConfigMap[:BASERUBY] + orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME] + Gem::ConfigMap[:BASERUBY] = 'ruby' + Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'ruby18' + + assert_equal '%s18', Gem.default_exec_format + ensure + Gem::ConfigMap[:BASERUBY] = orig_BASERUBY + Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME + end + + def test_self_default_exec_format_jruby + orig_BASERUBY = Gem::ConfigMap[:BASERUBY] + orig_RUBY_INSTALL_NAME = Gem::ConfigMap[:RUBY_INSTALL_NAME] + Gem::ConfigMap[:BASERUBY] = 'ruby' + Gem::ConfigMap[:RUBY_INSTALL_NAME] = 'jruby' + + assert_equal 'j%s', Gem.default_exec_format + ensure + Gem::ConfigMap[:BASERUBY] = orig_BASERUBY + Gem::ConfigMap[:RUBY_INSTALL_NAME] = orig_RUBY_INSTALL_NAME + end + def test_self_default_sources assert_equal %w[http://gems.rubyforge.org], Gem.default_sources end @@ -174,8 +211,8 @@ class TestGem < RubyGemTestCase util_make_gems expected = [ - File.join(@gemhome, *%W[gems #{@a0_0_2.full_name} lib]), - File.join(@gemhome, *%W[gems #{@b0_0_2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@a2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@b2.full_name} lib]), File.join(@gemhome, *%W[gems #{@c1_2.full_name} lib]), File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]), ] @@ -251,10 +288,10 @@ class TestGem < RubyGemTestCase assert_equal File.join(@tempdir, *%w[gemhome gems c-1.2 lib code.rb]), Gem.required_location("c", "code.rb") - assert_equal File.join(@tempdir, *%w[gemhome gems a-0.0.1 lib code.rb]), - Gem.required_location("a", "code.rb", "<0.0.2") - assert_equal File.join(@tempdir, *%w[gemhome gems a-0.0.2 lib code.rb]), - Gem.required_location("a", "code.rb", "=0.0.2") + assert_equal File.join(@tempdir, *%w[gemhome gems a-1 lib code.rb]), + Gem.required_location("a", "code.rb", "< 2") + assert_equal File.join(@tempdir, *%w[gemhome gems a-2 lib code.rb]), + Gem.required_location("a", "code.rb", "= 2") end def test_self_searcher @@ -298,73 +335,6 @@ class TestGem < RubyGemTestCase end end - def test_require_gem_autorequire - name = "AutorequireArray" - files = %w(a.rb b.rb) - gem = quick_gem(name) do |s| - s.files = files.map { |f| File.join("lib", f) } - s.autorequire = files - end - - fullname = gem.full_name - - write_file "gems/#{fullname}/lib/a.rb" do |io| - io.puts "$LOADED_A = true" - end - - write_file "gems/#{fullname}/lib/b.rb" do |io| - io.puts "$LOADED_B = true" - end - - Gem.source_index = nil - - old_loaded = $".dup - old_verbose = $VERBOSE - $VERBOSE = nil - require_gem name - $VERBOSE = old_verbose - new_loaded = $".dup - - if RUBY_VERSION > "1.9" then - files = files.map do |file| - File.join @gemhome, 'gems', gem.full_name, 'lib', file - end - end - - assert_equal files, (new_loaded - old_loaded) - assert defined?($LOADED_A) - assert defined?($LOADED_B) - end - - def test_require_gem_autorequire_string - name = "AutorequireString" - file = "c.rb" - gem = quick_gem(name) do |s| - s.files = File.join("lib", file) - s.autorequire = file - end - - fullname = gem.full_name - - write_file("gems/#{fullname}/lib/c.rb") do |io| - io.puts "$LOADED_C = true" - end - - old_loaded = $".dup - old_verbose = $VERBOSE - $VERBOSE = nil - require_gem name - $VERBOSE = old_verbose - new_loaded = $".dup - - if RUBY_VERSION > "1.9" then - file = File.join @gemhome, 'gems', gem.full_name, 'lib', file - end - - assert_equal(Array(file), (new_loaded - old_loaded)) - assert(defined? $LOADED_C) - end - def util_ensure_gem_dirs Gem.ensure_gem_subdirectories @gemhome @additional.each do |dir| diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index f1fd1503ba..a49b6777bd 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -8,31 +8,31 @@ class TestGemCommandsBuildCommand < RubyGemTestCase def setup super + @gem = quick_gem 'some_gem' do |s| + s.rubyforge_project = 'example' + end + @cmd = Gem::Commands::BuildCommand.new end def test_execute - gem = quick_gem 'some_gem' - - gemspec_file = File.join(@tempdir, "#{gem.full_name}.gemspec") + gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec") File.open gemspec_file, 'w' do |gs| - gs.write gem.to_ruby + gs.write @gem.to_ruby end - util_test_build_gem gem, gemspec_file + util_test_build_gem @gem, gemspec_file end def test_execute_yaml - gem = quick_gem 'some_gem' - - gemspec_file = File.join(@tempdir, "#{gem.full_name}.gemspec") + gemspec_file = File.join(@tempdir, "#{@gem.full_name}.gemspec") File.open gemspec_file, 'w' do |gs| - gs.write gem.to_yaml + gs.write @gem.to_yaml end - util_test_build_gem gem, gemspec_file + util_test_build_gem @gem, gemspec_file end def test_execute_bad_gem @@ -57,8 +57,8 @@ class TestGemCommandsBuildCommand < RubyGemTestCase output = @ui.output.split "\n" assert_equal " Successfully built RubyGem", output.shift assert_equal " Name: some_gem", output.shift - assert_equal " Version: 0.0.2", output.shift - assert_equal " File: some_gem-0.0.2.gem", output.shift + assert_equal " Version: 2", output.shift + assert_equal " File: some_gem-2.gem", output.shift assert_equal [], output assert_equal '', @ui.error diff --git a/test/rubygems/test_gem_commands_dependency_command.rb b/test/rubygems/test_gem_commands_dependency_command.rb index 9bf59537fd..0f0d95695d 100644 --- a/test/rubygems/test_gem_commands_dependency_command.rb +++ b/test/rubygems/test_gem_commands_dependency_command.rb @@ -13,7 +13,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase def test_execute quick_gem 'foo' do |gem| - gem.add_dependency 'bar', '> 1.0.0' + gem.add_dependency 'bar', '> 1' end @cmd.options[:args] = %w[foo] @@ -22,7 +22,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase @cmd.execute end - assert_equal "Gem foo-0.0.2\n bar (> 1.0.0)\n\n", @ui.output + assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output assert_equal '', @ui.error end @@ -41,7 +41,7 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase def test_execute_pipe_format quick_gem 'foo' do |gem| - gem.add_dependency 'bar', '> 1.0.0' + gem.add_dependency 'bar', '> 1' end @cmd.options[:args] = %w[foo] @@ -51,13 +51,13 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase @cmd.execute end - assert_equal "bar --version '> 1.0.0'\n", @ui.output + assert_equal "bar --version '> 1'\n", @ui.output assert_equal '', @ui.error end def test_execute_reverse quick_gem 'foo' do |gem| - gem.add_dependency 'bar', '> 1.0.0' + gem.add_dependency 'bar', '> 1' end quick_gem 'baz' do |gem| @@ -72,10 +72,10 @@ class TestGemCommandsDependencyCommand < RubyGemTestCase end expected = <<-EOF -Gem foo-0.0.2 - bar (> 1.0.0) +Gem foo-2 + bar (> 1) Used by - baz-0.0.2 (foo (>= 0)) + baz-2 (foo (>= 0)) EOF @@ -85,7 +85,7 @@ Gem foo-0.0.2 def test_execute_remote foo = quick_gem 'foo' do |gem| - gem.add_dependency 'bar', '> 1.0.0' + gem.add_dependency 'bar', '> 1' end util_setup_source_info_cache foo @@ -100,7 +100,7 @@ Gem foo-0.0.2 @cmd.execute end - assert_equal "Gem foo-0.0.2\n bar (> 1.0.0)\n\n", @ui.output + assert_equal "Gem foo-2\n bar (> 1)\n\n", @ui.output assert_equal '', @ui.error end diff --git a/test/rubygems/test_gem_commands_mirror_command.rb b/test/rubygems/test_gem_commands_mirror_command.rb index 7ddc8b92f8..359ba5481e 100644 --- a/test/rubygems/test_gem_commands_mirror_command.rb +++ b/test/rubygems/test_gem_commands_mirror_command.rb @@ -34,7 +34,12 @@ class TestGemCommandsMirrorCommand < RubyGemTestCase File.open File.join(Gem.user_home, '.gemmirrorrc'), 'w' do |fp| fp.puts "---" - fp.puts "- from: file://#{@tempdir}" + # 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 @@ -42,9 +47,9 @@ class TestGemCommandsMirrorCommand < RubyGemTestCase @cmd.execute end - assert File.exist?(File.join(mirror, 'gems', "#{@a0_0_1.full_name}.gem")) - assert File.exist?(File.join(mirror, 'gems', "#{@a0_0_2.full_name}.gem")) - assert File.exist?(File.join(mirror, 'gems', "#{@b0_0_2.full_name}.gem")) + assert File.exist?(File.join(mirror, 'gems', "#{@a1.full_name}.gem")) + assert File.exist?(File.join(mirror, 'gems', "#{@a2.full_name}.gem")) + assert File.exist?(File.join(mirror, 'gems', "#{@b2.full_name}.gem")) assert File.exist?(File.join(mirror, 'gems', "#{@c1_2.full_name}.gem")) assert File.exist?(File.join(mirror, "Marshal.#{@marshal_version}")) ensure diff --git a/test/rubygems/test_gem_commands_query_command.rb b/test/rubygems/test_gem_commands_query_command.rb index e2b6a45e92..4430ccfd33 100644 --- a/test/rubygems/test_gem_commands_query_command.rb +++ b/test/rubygems/test_gem_commands_query_command.rb @@ -10,13 +10,17 @@ class TestGemCommandsQueryCommand < RubyGemTestCase @foo_gem = quick_gem 'foo' do |spec| spec.summary = 'This is a lot of text. ' * 5 end + @foo_gem_p = quick_gem 'foo' do |spec| + spec.summary = 'This is a lot of text. ' * 5 + spec.platform = Gem::Platform::CURRENT + end @bar_gem = quick_gem 'bar' @cmd = Gem::Commands::QueryCommand.new end def test_execute - util_setup_source_info_cache @foo_gem + util_setup_source_info_cache @foo_gem, @foo_gem_p @cmd.handle_options %w[-r] @@ -28,7 +32,7 @@ class TestGemCommandsQueryCommand < RubyGemTestCase *** REMOTE GEMS *** -foo (0.0.2) +foo (2) EOF assert_equal expected, @ui.output @@ -48,7 +52,7 @@ foo (0.0.2) *** REMOTE GEMS *** -foo (0.0.2) +foo (2) This is a lot of text. This is a lot of text. This is a lot of text. This is a lot of text. This is a lot of text. EOF diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb new file mode 100644 index 0000000000..3e6af2e11c --- /dev/null +++ b/test/rubygems/test_gem_commands_server_command.rb @@ -0,0 +1,27 @@ +require 'test/unit' +require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') +require 'rubygems/commands/server_command' + +class TestGemCommandsServerCommand < RubyGemTestCase + + def setup + super + + @cmd = Gem::Commands::ServerCommand.new + end + + def test_handle_options + @cmd.send :handle_options, %w[-p 8808 --no-daemon] + + assert_equal false, @cmd.options[:daemon] + assert_equal @gemhome, @cmd.options[:gemdir] + assert_equal 8808, @cmd.options[:port] + + @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon] + + assert_equal true, @cmd.options[:daemon] + assert_equal '/nonexistent', @cmd.options[:gemdir] + assert_equal 9999, @cmd.options[:port] + end +end + diff --git a/test/rubygems/test_gem_commands_unpack_command.rb b/test/rubygems/test_gem_commands_unpack_command.rb index ff3d4e0eae..427f9403c3 100644 --- a/test/rubygems/test_gem_commands_unpack_command.rb +++ b/test/rubygems/test_gem_commands_unpack_command.rb @@ -7,7 +7,9 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase def setup super - @cmd = Gem::Commands::UnpackCommand.new + Dir.chdir @tempdir do + @cmd = Gem::Commands::UnpackCommand.new + end end def test_execute @@ -15,13 +17,29 @@ class TestGemCommandsUnpackCommand < RubyGemTestCase @cmd.options[:args] = %w[a] + use_ui @ui do + Dir.chdir @tempdir do + @cmd.execute + end + end + + assert File.exist?(File.join(@tempdir, 'a-2')) + end + + def test_execute_with_target_option + util_make_gems + + target = 'with_target' + @cmd.options[:args] = %w[a] + @cmd.options[:target] = target + use_ui @ui do Dir.chdir @tempdir do @cmd.execute end end - assert File.exist?(File.join(@tempdir, 'a-0.0.2')) + assert File.exist?(File.join(@tempdir, target, 'a-2')) end def test_execute_exact_match diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index 6bc7a42e81..35eee6bae2 100644 --- a/test/rubygems/test_gem_format.rb +++ b/test/rubygems/test_gem_format.rb @@ -22,7 +22,7 @@ class TestGemFormat < RubyGemTestCase gems = Dir[File.join(@gemhome, 'cache', '*.gem')] - names = [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].map do |spec| + names = [@a1, @a2, @b2, @c1_2, @pl1].map do |spec| spec.original_name end diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index 116a29c562..9eb78500c9 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -53,16 +53,16 @@ class TestGemIndexer < RubyGemTestCase assert_indexed quickdir, "index" assert_indexed quickdir, "index.rz" - assert_indexed quickdir, "#{@a0_0_1.full_name}.gemspec.rz" - assert_indexed quickdir, "#{@a0_0_2.full_name}.gemspec.rz" - assert_indexed quickdir, "#{@b0_0_2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@a2.full_name}.gemspec.rz" + assert_indexed quickdir, "#{@b2.full_name}.gemspec.rz" assert_indexed quickdir, "#{@c1_2.full_name}.gemspec.rz" assert_indexed quickdir, "#{@pl1.original_name}.gemspec.rz" deny_indexed quickdir, "#{@pl1.full_name}.gemspec.rz" - assert_indexed marshal_quickdir, "#{@a0_0_1.full_name}.gemspec.rz" - assert_indexed marshal_quickdir, "#{@a0_0_2.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a1.full_name}.gemspec.rz" + assert_indexed marshal_quickdir, "#{@a2.full_name}.gemspec.rz" deny_indexed quickdir, "#{@c1_2.full_name}.gemspec" deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec" diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb index dafdf65920..8c7a5ce3f7 100644 --- a/test/rubygems/test_gem_install_update_options.rb +++ b/test/rubygems/test_gem_install_update_options.rb @@ -16,7 +16,7 @@ class TestGemInstallUpdateOptions < RubyGemTestCase @cmd.add_install_update_options args = %w[-i /install_to --rdoc --ri -E -f -t -w -P HighSecurity - --ignore-dependencies --include-dependencies] + --ignore-dependencies --format-exec --include-dependencies] assert @cmd.handles?(args) end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 9a091a291e..442ed6cfc3 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -9,11 +9,13 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') require 'rubygems/installer' class Gem::Installer + attr_accessor :gem_dir + attr_writer :format - attr_writer :gem_dir attr_writer :gem_home attr_writer :env_shebang attr_writer :ignore_dependencies + attr_writer :format_executable attr_writer :security_policy attr_writer :spec attr_writer :wrappers @@ -37,11 +39,11 @@ class TestGemInstaller < RubyGemTestCase @installer.spec = @spec end - def util_gem_dir(version = '0.0.2') + def util_gem_dir(version = '2') File.join @gemhome, "gems", "a-#{version}" # HACK end - def util_gem_bindir(version = '0.0.2') + def util_gem_bindir(version = '2') File.join util_gem_dir(version), "bin" end @@ -49,18 +51,19 @@ class TestGemInstaller < RubyGemTestCase File.join @gemhome, "bin" end - def util_make_exec(version = '0.0.2', shebang = "#!/usr/bin/ruby") + def util_make_exec(version = '2', shebang = "#!/usr/bin/ruby") @spec.executables = ["my_exec"] FileUtils.mkdir_p util_gem_bindir(version) - exec_file = File.join(util_gem_bindir(version), "my_exec") - File.open exec_file, 'w' do |f| + exec_file = @installer.formatted_program_filename "my_exec" + exec_path = File.join util_gem_bindir(version), exec_file + File.open exec_path, 'w' do |f| f.puts shebang end end def test_app_script_text - util_make_exec '0.0.2', '' + util_make_exec '2', '' expected = <<-EOF #!#{Gem.ruby} @@ -144,15 +147,15 @@ load 'my_exec' end def test_ensure_dependency - dep = Gem::Dependency.new 'a', '>= 0.0.2' + dep = Gem::Dependency.new 'a', '>= 2' assert @installer.ensure_dependency(@spec, dep) - dep = Gem::Dependency.new 'b', '> 0.0.2' + dep = Gem::Dependency.new 'b', '> 2' e = assert_raise Gem::InstallError do @installer.ensure_dependency @spec, dep end - assert_equal 'a requires b (> 0.0.2)', e.message + assert_equal 'a requires b (> 2)', e.message end def test_expand_and_validate_gem_dir @@ -226,7 +229,32 @@ load 'my_exec' "You may need to remove this file if you broke the test once" end - def test_generate_bin_scripts + def test_generate_bin_bindir + @installer.wrappers = true + + @spec.executables = ["my_exec"] + @spec.bindir = '.' + + exec_file = @installer.formatted_program_filename "my_exec" + exec_path = File.join util_gem_dir(@spec.version), exec_file + File.open exec_path, 'w' do |f| + f.puts '#!/usr/bin/ruby' + end + + @installer.gem_dir = util_gem_dir + + @installer.generate_bin + + assert_equal true, File.directory?(util_inst_bindir) + installed_exec = File.join(util_inst_bindir, "my_exec") + assert_equal true, File.exist?(installed_exec) + assert_equal(0100755, File.stat(installed_exec).mode) unless win_platform? + + wrapper = File.read installed_exec + assert_match %r|generated by RubyGems|, wrapper + end + + def test_generate_bin_script @installer.wrappers = true util_make_exec @installer.gem_dir = util_gem_dir @@ -241,7 +269,36 @@ load 'my_exec' assert_match %r|generated by RubyGems|, wrapper end - def test_generate_bin_scripts_install_dir + def test_generate_bin_script_format + @installer.format_executable = true + @installer.wrappers = true + util_make_exec + @installer.gem_dir = util_gem_dir + + Gem::Installer.exec_format = 'foo-%s-bar' + @installer.generate_bin + assert_equal true, File.directory?(util_inst_bindir) + installed_exec = File.join util_inst_bindir, 'foo-my_exec-bar' + assert_equal true, File.exist?(installed_exec) + ensure + Gem::Installer.exec_format = nil + end + + def test_generate_bin_script_format_disabled + @installer.wrappers = true + util_make_exec + @installer.gem_dir = util_gem_dir + + Gem::Installer.exec_format = 'foo-%s-bar' + @installer.generate_bin + assert_equal true, File.directory?(util_inst_bindir) + installed_exec = File.join util_inst_bindir, 'my_exec' + assert_equal true, File.exist?(installed_exec) + ensure + Gem::Installer.exec_format = nil + end + + def test_generate_bin_script_install_dir @installer.wrappers = true @spec.executables = ["my_exec"] @@ -265,13 +322,13 @@ load 'my_exec' assert_match %r|generated by RubyGems|, wrapper end - def test_generate_bin_scripts_no_execs + def test_generate_bin_script_no_execs @installer.wrappers = true @installer.generate_bin assert_equal false, File.exist?(util_inst_bindir) end - def test_generate_bin_scripts_no_perms + def test_generate_bin_script_no_perms @installer.wrappers = true util_make_exec @@ -286,7 +343,30 @@ load 'my_exec' File.chmod 0700, util_inst_bindir unless $DEBUG end - def test_generate_bin_symlinks + def test_generate_bin_script_no_shebang + @installer.wrappers = true + @spec.executables = ["my_exec"] + + gem_dir = File.join @gemhome, 'gems', @spec.full_name + gem_bindir = File.join gem_dir, 'bin' + FileUtils.mkdir_p gem_bindir + File.open File.join(gem_bindir, "my_exec"), 'w' do |f| + f.puts "blah blah blah" + end + + @installer.generate_bin + + installed_exec = File.join @gemhome, 'bin', 'my_exec' + assert_equal true, File.exist?(installed_exec) + assert_equal 0100755, File.stat(installed_exec).mode unless win_platform? + + wrapper = File.read installed_exec + assert_match %r|generated by RubyGems|, wrapper + # HACK some gems don't have #! in their executables, restore 2008/06 + #assert_no_match %r|generated by RubyGems|, wrapper + end + + def test_generate_bin_symlink return if win_platform? #Windows FS do not support symlinks @installer.wrappers = false @@ -301,13 +381,13 @@ load 'my_exec' File.readlink(installed_exec)) end - def test_generate_bin_symlinks_no_execs + def test_generate_bin_symlink_no_execs @installer.wrappers = false @installer.generate_bin assert_equal false, File.exist?(util_inst_bindir) end - def test_generate_bin_symlinks_no_perms + def test_generate_bin_symlink_no_perms @installer.wrappers = false util_make_exec @installer.gem_dir = util_gem_dir @@ -323,7 +403,7 @@ load 'my_exec' File.chmod 0700, util_inst_bindir unless $DEBUG end - def test_generate_bin_symlinks_update_newer + def test_generate_bin_symlink_update_newer return if win_platform? #Windows FS do not support symlinks @installer.wrappers = false @@ -338,22 +418,22 @@ load 'my_exec' @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] s.name = "a" - s.version = "0.0.3" + s.version = "3" s.summary = "summary" s.description = "desc" s.require_path = 'lib' end - util_make_exec '0.0.3' - @installer.gem_dir = File.join util_gem_dir('0.0.3') + util_make_exec '3' + @installer.gem_dir = File.join util_gem_dir('3') @installer.generate_bin installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_bindir('0.0.3'), "my_exec"), + assert_equal(File.join(util_gem_bindir('3'), "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end - def test_generate_bin_symlinks_update_older + def test_generate_bin_symlink_update_older return if win_platform? #Windows FS do not support symlinks @installer.wrappers = false @@ -368,25 +448,25 @@ load 'my_exec' spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] s.name = "a" - s.version = "0.0.1" + s.version = "1" s.summary = "summary" s.description = "desc" s.require_path = 'lib' end - util_make_exec '0.0.1' - @installer.gem_dir = util_gem_dir('0.0.1') + util_make_exec '1' + @installer.gem_dir = util_gem_dir('1') @installer.spec = spec @installer.generate_bin installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir('0.0.2'), "bin", "my_exec"), + assert_equal(File.join(util_gem_dir('2'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink not moved") end - def test_generate_bin_symlinks_update_remove_wrapper + def test_generate_bin_symlink_update_remove_wrapper return if win_platform? #Windows FS do not support symlinks @installer.wrappers = true @@ -400,23 +480,23 @@ load 'my_exec' @spec = Gem::Specification.new do |s| s.files = ['lib/code.rb'] s.name = "a" - s.version = "0.0.3" + s.version = "3" s.summary = "summary" s.description = "desc" s.require_path = 'lib' end @installer.wrappers = false - util_make_exec '0.0.3' - @installer.gem_dir = util_gem_dir '0.0.3' + util_make_exec '3' + @installer.gem_dir = util_gem_dir '3' @installer.generate_bin installed_exec = File.join(util_inst_bindir, "my_exec") - assert_equal(File.join(util_gem_dir('0.0.3'), "bin", "my_exec"), + assert_equal(File.join(util_gem_dir('3'), "bin", "my_exec"), File.readlink(installed_exec), "Ensure symlink moved to latest version") end - def test_generate_bin_symlinks_win32 + def test_generate_bin_symlink_win32 old_win_platform = Gem.win_platform? Gem.win_platform = true @installer.wrappers = false @@ -454,6 +534,19 @@ load 'my_exec' assert_match(/#{default_shebang}/, shebang_line) end + def test_initialize + spec = quick_gem 'a' do |s| s.platform = Gem::Platform.new 'mswin32' end + gem = File.join @tempdir, "#{spec.full_name}.gem" + + util_build_gem spec + FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"), + @tempdir + + installer = Gem::Installer.new gem + + assert_equal File.join(@gemhome, 'gems', spec.full_name), installer.gem_dir + end + def test_install util_setup_gem @@ -518,7 +611,7 @@ load 'my_exec' installer.install end - gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-0.0.1') + gem_dir = File.join(@gemhome, 'gems', 'old_ruby_required-1') assert File.exist?(gem_dir) end @@ -605,8 +698,8 @@ load 'my_exec' end def test_install_wrong_rubygems_version - spec = quick_gem 'old_rubygems_required', '0.0.1' do |s| - s.required_rubygems_version = '< 0.0.0' + spec = quick_gem 'old_rubygems_required', '1' do |s| + s.required_rubygems_version = '< 0' end util_build_gem spec @@ -618,21 +711,21 @@ load 'my_exec' e = assert_raise Gem::InstallError do @installer.install end - assert_equal 'old_rubygems_required requires RubyGems version < 0.0.0', + assert_equal 'old_rubygems_required requires RubyGems version < 0', e.message end end def test_installation_satisfies_dependency_eh - dep = Gem::Dependency.new 'a', '>= 0.0.2' + dep = Gem::Dependency.new 'a', '>= 2' assert @installer.installation_satisfies_dependency?(dep) - dep = Gem::Dependency.new 'a', '> 0.0.2' + dep = Gem::Dependency.new 'a', '> 2' assert ! @installer.installation_satisfies_dependency?(dep) end def test_shebang - util_make_exec '0.0.2', "#!/usr/bin/ruby" + util_make_exec '2', "#!/usr/bin/ruby" shebang = @installer.shebang 'my_exec' @@ -640,7 +733,7 @@ load 'my_exec' end def test_shebang_arguments - util_make_exec '0.0.2', "#!/usr/bin/ruby -ws" + util_make_exec '2', "#!/usr/bin/ruby -ws" shebang = @installer.shebang 'my_exec' @@ -648,14 +741,14 @@ load 'my_exec' end def test_shebang_empty - util_make_exec '0.0.2', '' + util_make_exec '2', '' shebang = @installer.shebang 'my_exec' assert_equal "#!#{Gem.ruby}", shebang end def test_shebang_env - util_make_exec '0.0.2', "#!/usr/bin/env ruby" + util_make_exec '2', "#!/usr/bin/env ruby" shebang = @installer.shebang 'my_exec' @@ -663,7 +756,7 @@ load 'my_exec' end def test_shebang_env_arguments - util_make_exec '0.0.2', "#!/usr/bin/env ruby -ws" + util_make_exec '2', "#!/usr/bin/env ruby -ws" shebang = @installer.shebang 'my_exec' @@ -671,7 +764,7 @@ load 'my_exec' end def test_shebang_env_shebang - util_make_exec '0.0.2', '' + util_make_exec '2', '' @installer.env_shebang = true shebang = @installer.shebang 'my_exec' @@ -679,7 +772,7 @@ load 'my_exec' end def test_shebang_nested - util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby" shebang = @installer.shebang 'my_exec' @@ -687,7 +780,7 @@ load 'my_exec' end def test_shebang_nested_arguments - util_make_exec '0.0.2', "#!/opt/local/ruby/bin/ruby -ws" + util_make_exec '2', "#!/opt/local/ruby/bin/ruby -ws" shebang = @installer.shebang 'my_exec' @@ -695,7 +788,7 @@ load 'my_exec' end def test_shebang_version - util_make_exec '0.0.2', "#!/usr/bin/ruby18" + util_make_exec '2', "#!/usr/bin/ruby18" shebang = @installer.shebang 'my_exec' @@ -703,7 +796,7 @@ load 'my_exec' end def test_shebang_version_arguments - util_make_exec '0.0.2', "#!/usr/bin/ruby18 -ws" + util_make_exec '2', "#!/usr/bin/ruby18 -ws" shebang = @installer.shebang 'my_exec' @@ -711,7 +804,7 @@ load 'my_exec' end def test_shebang_version_env - util_make_exec '0.0.2', "#!/usr/bin/env ruby18" + util_make_exec '2', "#!/usr/bin/env ruby18" shebang = @installer.shebang 'my_exec' @@ -719,7 +812,7 @@ load 'my_exec' end def test_shebang_version_env_arguments - util_make_exec '0.0.2', "#!/usr/bin/env ruby18 -ws" + util_make_exec '2', "#!/usr/bin/env ruby18 -ws" shebang = @installer.shebang 'my_exec' @@ -753,7 +846,7 @@ load 'my_exec' end def old_ruby_required - spec = quick_gem 'old_ruby_required', '0.0.1' do |s| + spec = quick_gem 'old_ruby_required', '1' do |s| s.required_ruby_version = '= 1.4.6' end @@ -790,4 +883,3 @@ load 'my_exec' end - diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index a1462d4dcd..648c2a9f36 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -5,6 +5,19 @@ 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' @@ -60,6 +73,10 @@ class TestGemPlatform < RubyGemTestCase 'i386-mingw32' => ['x86', 'mingw32', nil], 'i386-mswin32' => ['x86', 'mswin32', nil], 'i386-mswin32_80' => ['x86', 'mswin32', '80'], + 'i386-mswin32-80' => ['x86', 'mswin32', '80'], + 'x86-mswin32' => ['x86', 'mswin32', nil], + 'x86-mswin32_60' => ['x86', 'mswin32', '60'], + 'x86-mswin32-60' => ['x86', 'mswin32', '60'], 'i386-netbsdelf' => ['x86', 'netbsdelf', nil], 'i386-openbsd4.0' => ['x86', 'openbsd', '4.0'], 'i386-solaris2.10' => ['x86', 'solaris', '2.10'], diff --git a/test/rubygems/test_gem_remote_fetcher.rb b/test/rubygems/test_gem_remote_fetcher.rb index 83865e8033..fd3843851a 100644 --- a/test/rubygems/test_gem_remote_fetcher.rb +++ b/test/rubygems/test_gem_remote_fetcher.rb @@ -140,11 +140,12 @@ gems: raise SocketError end + uri = 'http://gems.example.com/yaml' e = assert_raise Gem::RemoteFetcher::FetchError do - fetcher.fetch_size 'http://gems.example.com/yaml' + fetcher.fetch_size uri end - assert_equal 'SocketError (SocketError)', e.message + assert_equal "SocketError (SocketError)\n\tgetting size of #{uri}", e.message end def test_no_proxy @@ -231,6 +232,22 @@ gems: assert_equal 'EOFError: EOFError reading uri', e.message end + def test_fetch_path_open_uri_http_error + fetcher = Gem::RemoteFetcher.new nil + + def fetcher.open_uri_or_path(uri) + io = StringIO.new 'went boom' + err = OpenURI::HTTPError.new 'error', io + raise err + end + + e = assert_raise Gem::RemoteFetcher::FetchError do + fetcher.fetch_path 'uri' + end + + assert_equal "OpenURI::HTTPError: error reading uri\n\twent boom", e.message + end + def test_fetch_path_socket_error fetcher = Gem::RemoteFetcher.new nil diff --git a/test/rubygems/test_gem_remote_installer.rb b/test/rubygems/test_gem_remote_installer.rb deleted file mode 100644 index 90d94843bd..0000000000 --- a/test/rubygems/test_gem_remote_installer.rb +++ /dev/null @@ -1,161 +0,0 @@ -#-- -# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. -# All rights reserved. -# See LICENSE.txt for permissions. -#++ - -require 'test/unit' -require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') -require 'rubygems/remote_installer' - -class MockFetcher - def initialize(uri, proxy) - @uri = uri - @proxy = proxy - end - - def size - 1000 - end - - def source_index - if @uri =~ /non.existent.url/ - fail Gem::RemoteSourceException, - "Error fetching remote gem cache: Mock Socket Exception" - end - result = { - 'foo-1.2.3' => Gem::Specification.new do |s| - s.name = 'foo' - s.version = "1.2.3" - s.summary = "This is a cool package" - end, - 'foo-tools-2.0.0' => Gem::Specification.new do |s| - s.name = 'foo-tools' - s.version = "2.0.0" - s.summary = "This is an even cooler package" - end, - 'foo-2-2.0.0' => Gem::Specification.new do |s| - s.name = 'foo-2' - s.version = "2.0.0" - s.summary = "This is the coolest package evar!~!" - end, - } - result - end - - def fetch_path(path) - end - - def self.finish - end -end - -class TestGemRemoteInstaller < RubyGemTestCase - - def setup - super - - util_setup_fake_fetcher - - util_setup_source_info_cache @gem1, @gem4 - - @installer = Gem::RemoteInstaller.new - @installer.instance_variable_set("@fetcher_class", MockFetcher) - end - - def teardown - FileUtils.rm "dest_file" rescue nil - end - - def test_find_gem_to_install - future_gem = quick_gem @gem1.name, '9.9.9' do |spec| - spec.required_ruby_version = '> 999.999.999' # HACK - end - - util_setup_source_info_cache @gem1, future_gem - version = Gem::Version::Requirement.new "> 0.0.0" - gems = @installer.find_gem_to_install(@gem1.name, version) - - assert_equal @gem1.full_name, gems.first.full_name - end - - def test_source_index_hash - source_hash = @installer.source_index_hash - - assert_equal 1, source_hash.size - assert source_hash.has_key?('http://gems.example.com') - assert_equal [@gem1, @gem4], - source_hash['http://gems.example.com'].search(@gem1.name) - end - - def test_specs_n_sources_matching - version = Gem::Version::Requirement.new "> 0.0.0" - specs_n_sources = @installer.specs_n_sources_matching @gem1.name, version - - gems = specs_n_sources.map { |g,| g.full_name } - - assert_equal [@gem1.full_name], gems, - "Gems with longer names and higher versions must not match" - end - -end - -# This test suite has a number of TODOs in the test cases. The -# TestRemoteInstaller test suite is a reworking of this class from -# scratch. -class RemoteInstallerTest #< RubyGemTestCase # HACK disabled - class RInst < Gem::RemoteInstaller - include Test::Unit::Assertions - - attr_accessor :expected_destination_files - attr_accessor :expected_bodies - attr_accessor :caches - attr_accessor :responses - - def source_index_hash - @caches - end - - def fetch(uri) - @reponses ||= {} - @responses[uri] - end - - def write_gem_to_file(body, destination_file) - expected_destination_file = expected_destination_files.pop - expected_body = expected_bodies.pop - assert_equal expected_body, body, "Unexpected body" - assert_equal expected_destination_file, destination_file, "Unexpected destination file" - end - - def new_installer(gem) - return MockInstaller.new(gem) - end - end - - def setup - Gem.clear_paths - @remote_installer = Gem::RemoteInstaller.new - @remote_installer.instance_eval { @fetcher_class = MockFetcher } - end - - SAMPLE_SPEC = Gem::Specification.new do |s| - s.name = 'foo' - s.version = "1.2.3" - s.platform = Gem::Platform::RUBY - s.summary = "This is a cool package" - s.files = [] - end - SAMPLE_CACHE = { 'foo-1.2.3' => SAMPLE_SPEC } - SAMPLE_CACHE_YAML = SAMPLE_CACHE.to_yaml - - FOO_GEM = '' # TODO - CACHE_DIR = File.join(Gem.dir, 'cache') - - def test_install - result = @remote_installer.install('foo') - assert_equal [nil], result - end - -end - diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb index 98c8ba5543..c283e661dc 100644 --- a/test/rubygems/test_gem_server.rb +++ b/test/rubygems/test_gem_server.rb @@ -4,6 +4,7 @@ require 'rubygems/server' require 'stringio' class Gem::Server + attr_accessor :source_index attr_reader :server end @@ -25,6 +26,7 @@ class TestGemServer < RubyGemTestCase @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", @res.body @@ -36,6 +38,7 @@ class TestGemServer < RubyGemTestCase @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", Zlib::Inflate.inflate(@res.body) @@ -47,6 +50,7 @@ class TestGemServer < RubyGemTestCase @server.quick @req, @res + assert_equal 200, @res.status, @res.body assert @res['date'] assert_equal 'text/plain', @res['content-type'] yaml = Zlib::Inflate.inflate(@res.body) @@ -55,15 +59,54 @@ class TestGemServer < RubyGemTestCase assert_match %r|version: "1"|, yaml end + def test_quick_a_1_mswin32_gemspec_rz + a1_p = quick_gem 'a', '1' do |s| s.platform = Gem::Platform.local end + si = Gem::SourceIndex.new @a1.full_name => @a1, a1_p.full_name => a1_p + @server.source_index = si + + data = StringIO.new "GET /quick/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n" + @req.parse data + + @server.quick @req, @res + + assert_equal 200, @res.status, @res.body + assert @res['date'] + assert_equal 'text/plain', @res['content-type'] + yaml = Zlib::Inflate.inflate(@res.body) + assert_match %r|Gem::Specification|, yaml + assert_match %r|name: a|, yaml + assert_match %r|version: "1"|, yaml + end + + def test_quick_common_substrings + ab1 = quick_gem 'ab', '1' + si = Gem::SourceIndex.new @a1.full_name => @a1, ab1.full_name => ab1 + @server.source_index = si + + data = StringIO.new "GET /quick/a-1.gemspec.rz HTTP/1.0\r\n\r\n" + @req.parse data + + @server.quick @req, @res + + assert_equal 200, @res.status, @res.body + assert @res['date'] + assert_equal 'text/plain', @res['content-type'] + yaml = Zlib::Inflate.inflate @res.body + assert_match %r|Gem::Specification|, yaml + assert_match %r|name: a$|, yaml + assert_match %r|version: "1"|, yaml + end + def test_quick_z_9_gemspec_rz data = StringIO.new "GET /quick/z-9.gemspec.rz HTTP/1.0\r\n\r\n" @req.parse data @server.quick @req, @res + assert_equal 404, @res.status, @res.body assert_match %r| \d\d:\d\d:\d\d |, @res['date'] assert_equal 'text/plain', @res['content-type'] - assert_equal '', @res.body + assert_equal 'No gems found matching "z" "9" nil', @res.body assert_equal 404, @res.status end diff --git a/test/rubygems/test_gem_source_index.rb b/test/rubygems/test_gem_source_index.rb index befbbe6f67..45f59f2430 100644 --- a/test/rubygems/test_gem_source_index.rb +++ b/test/rubygems/test_gem_source_index.rb @@ -178,7 +178,7 @@ class TestGemSourceIndex < RubyGemTestCase end def test_latest_specs - spec = quick_gem @gem1.name, '0.0.1' + spec = quick_gem @gem1.name, '1' @source_index.add_spec spec expected = [ @@ -223,7 +223,7 @@ class TestGemSourceIndex < RubyGemTestCase def test_search assert_equal [@gem1, @gem4], @source_index.search("gem_one") - assert_equal [@gem1], @source_index.search("gem_one", "= 0.0.2") + assert_equal [@gem1], @source_index.search("gem_one", "= 2") assert_equal [], @source_index.search("bogusstring") assert_equal [], @source_index.search("gem_one", "= 3.2.1") diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 69d625ceb6..723e566a24 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -47,12 +47,13 @@ end def setup super - @a0_0_1 = quick_gem 'a', '0.0.1' do |s| + @a1 = quick_gem 'a', '1' do |s| s.executable = 'exec' s.extensions << 'ext/a/extconf.rb' s.has_rdoc = 'true' s.test_file = 'test/suite.rb' s.requirements << 'A working computer' + s.rubyforge_project = 'example' s.add_dependency 'rake', '> 0.4' s.add_dependency 'jabber4r', '> 0.0.0' @@ -62,9 +63,14 @@ end s.files = %w[lib/code.rb] end - @a0_0_2 = quick_gem 'a', '0.0.2' do |s| + @a2 = quick_gem 'a', '2' do |s| s.files = %w[lib/code.rb] end + + FileUtils.mkdir_p File.join(@tempdir, 'bin') + File.open File.join(@tempdir, 'bin', 'exec'), 'w' do |fp| + fp.puts "#!#{Gem.ruby}" + end end def test_self_attribute_names @@ -107,10 +113,10 @@ end end def test_self_load - spec = File.join @gemhome, 'specifications', "#{@a0_0_2.full_name}.gemspec" + spec = File.join @gemhome, 'specifications', "#{@a2.full_name}.gemspec" gs = Gem::Specification.load spec - assert_equal @a0_0_2, gs + assert_equal @a2, gs end def test_self_load_legacy_ruby @@ -119,7 +125,7 @@ end assert_equal '0.4.0', s.version.to_s assert_equal true, s.has_rdoc? assert_equal Gem::Specification::TODAY, s.date - assert s.required_ruby_version.satisfied_by?(Gem::Version.new('0.0.1')) + assert s.required_ruby_version.satisfied_by?(Gem::Version.new('1')) assert_equal false, s.has_unit_tests? end @@ -129,7 +135,7 @@ end assert_equal '0.4.0', s.version.to_s assert_equal true, s.has_rdoc? #assert_equal Date.today, s.date - #assert s.required_ruby_version.satisfied_by?(Gem::Version.new('0.0.1')) + #assert s.required_ruby_version.satisfied_by?(Gem::Version.new('1')) assert_equal false, s.has_unit_tests? end @@ -197,10 +203,10 @@ end end def test__dump - @a0_0_2.platform = Gem::Platform.local - @a0_0_2.instance_variable_set :@original_platform, 'old_platform' + @a2.platform = Gem::Platform.local + @a2.instance_variable_set :@original_platform, 'old_platform' - data = Marshal.dump @a0_0_2 + data = Marshal.dump @a2 same_spec = Marshal.load data @@ -208,64 +214,64 @@ end end def test_author - assert_equal 'A User', @a0_0_1.author + assert_equal 'A User', @a1.author end def test_authors - assert_equal ['A User'], @a0_0_1.authors + assert_equal ['A User'], @a1.authors end def test_bindir_equals - @a0_0_1.bindir = 'apps' + @a1.bindir = 'apps' - assert_equal 'apps', @a0_0_1.bindir + assert_equal 'apps', @a1.bindir end def test_bindir_equals_nil - @a0_0_2.bindir = nil - @a0_0_2.executable = 'app' + @a2.bindir = nil + @a2.executable = 'app' - assert_equal nil, @a0_0_2.bindir - assert_equal %w[lib/code.rb app], @a0_0_2.files + assert_equal nil, @a2.bindir + assert_equal %w[lib/code.rb app], @a2.files end def test_date - assert_equal Gem::Specification::TODAY, @a0_0_1.date + assert_equal Gem::Specification::TODAY, @a1.date end def test_date_equals_date - @a0_0_1.date = Date.new(2003, 9, 17) - assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date + @a1.date = Date.new(2003, 9, 17) + assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date end def test_date_equals_string - @a0_0_1.date = '2003-09-17' - assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date + @a1.date = '2003-09-17' + assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date end def test_date_equals_time - @a0_0_1.date = Time.local(2003, 9, 17, 0,0,0) - assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date + @a1.date = Time.local(2003, 9, 17, 0,0,0) + assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date end def test_date_equals_time_local # HACK PDT - @a0_0_1.date = Time.local(2003, 9, 17, 19,50,0) - assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date + @a1.date = Time.local(2003, 9, 17, 19,50,0) + assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date end def test_date_equals_time_utc # HACK PDT - @a0_0_1.date = Time.local(2003, 9, 17, 19,50,0) - assert_equal Time.local(2003, 9, 17, 0,0,0), @a0_0_1.date + @a1.date = Time.local(2003, 9, 17, 19,50,0) + assert_equal Time.local(2003, 9, 17, 0,0,0), @a1.date end def test_default_executable - assert_equal 'exec', @a0_0_1.default_executable + assert_equal 'exec', @a1.default_executable - @a0_0_1.default_executable = nil - @a0_0_1.instance_variable_set :@executables, nil - assert_equal nil, @a0_0_1.default_executable + @a1.default_executable = nil + @a1.instance_variable_set :@executables, nil + assert_equal nil, @a1.default_executable end def test_dependencies @@ -273,11 +279,11 @@ end jabber = Gem::Dependency.new 'jabber4r', '> 0.0.0' pqa = Gem::Dependency.new 'pqa', ['> 0.4', '<= 0.6'] - assert_equal [rake, jabber, pqa], @a0_0_1.dependencies + assert_equal [rake, jabber, pqa], @a1.dependencies end def test_description - assert_equal 'This is a test description', @a0_0_1.description + assert_equal 'This is a test description', @a1.description end def test_eql_eh @@ -290,10 +296,10 @@ end end def test_equals2 - assert_equal @a0_0_1, @a0_0_1 - assert_equal @a0_0_1, @a0_0_1.dup - assert_not_equal @a0_0_1, @a0_0_2 - assert_not_equal @a0_0_1, Object.new + assert_equal @a1, @a1 + assert_equal @a1, @a1.dup + assert_not_equal @a1, @a2 + assert_not_equal @a1, Object.new end # The cgikit specification was reported to be causing trouble in at least @@ -322,42 +328,42 @@ end end def test_equals2_default_executable - spec = @a0_0_1.dup + spec = @a1.dup spec.default_executable = 'xx' - assert_not_equal @a0_0_1, spec - assert_not_equal spec, @a0_0_1 + assert_not_equal @a1, spec + assert_not_equal spec, @a1 end def test_equals2_extensions - spec = @a0_0_1.dup + spec = @a1.dup spec.extensions = 'xx' - assert_not_equal @a0_0_1, spec - assert_not_equal spec, @a0_0_1 + assert_not_equal @a1, spec + assert_not_equal spec, @a1 end def test_executables - @a0_0_1.executable = 'app' - assert_equal %w[app], @a0_0_1.executables + @a1.executable = 'app' + assert_equal %w[app], @a1.executables end def test_executable_equals - @a0_0_2.executable = 'app' - assert_equal 'app', @a0_0_2.executable - assert_equal %w[lib/code.rb bin/app], @a0_0_2.files + @a2.executable = 'app' + assert_equal 'app', @a2.executable + assert_equal %w[lib/code.rb bin/app], @a2.files end def test_extensions - assert_equal ['ext/a/extconf.rb'], @a0_0_1.extensions + assert_equal ['ext/a/extconf.rb'], @a1.extensions end def test_files - @a0_0_1.files = %w(files bin/common) - @a0_0_1.test_files = %w(test_files bin/common) - @a0_0_1.executables = %w(executables common) - @a0_0_1.extra_rdoc_files = %w(extra_rdoc_files bin/common) - @a0_0_1.extensions = %w(extensions bin/common) + @a1.files = %w(files bin/common) + @a1.test_files = %w(test_files bin/common) + @a1.executables = %w(executables common) + @a1.extra_rdoc_files = %w(extra_rdoc_files bin/common) + @a1.extensions = %w(extensions bin/common) expected = %w[ bin/common @@ -367,113 +373,123 @@ end files test_files ] - assert_equal expected, @a0_0_1.files.sort + assert_equal expected, @a1.files.sort end def test_files_duplicate - @a0_0_2.files = %w[a b c d b] - @a0_0_2.extra_rdoc_files = %w[x y z x] - @a0_0_2.normalize + @a2.files = %w[a b c d b] + @a2.extra_rdoc_files = %w[x y z x] + @a2.normalize - assert_equal %w[a b c d x y z], @a0_0_2.files - assert_equal %w[x y z], @a0_0_2.extra_rdoc_files + assert_equal %w[a b c d x y z], @a2.files + assert_equal %w[x y z], @a2.extra_rdoc_files end def test_files_extra_rdoc_files - @a0_0_2.files = %w[a b c d] - @a0_0_2.extra_rdoc_files = %w[x y z] - @a0_0_2.normalize - assert_equal %w[a b c d x y z], @a0_0_2.files + @a2.files = %w[a b c d] + @a2.extra_rdoc_files = %w[x y z] + @a2.normalize + assert_equal %w[a b c d x y z], @a2.files end def test_files_non_array - @a0_0_1.files = "F" - @a0_0_1.test_files = "TF" - @a0_0_1.executables = "X" - @a0_0_1.extra_rdoc_files = "ERF" - @a0_0_1.extensions = "E" + @a1.files = "F" + @a1.test_files = "TF" + @a1.executables = "X" + @a1.extra_rdoc_files = "ERF" + @a1.extensions = "E" - assert_equal %w[E ERF F TF bin/X], @a0_0_1.files.sort + assert_equal %w[E ERF F TF bin/X], @a1.files.sort end def test_files_non_array_pathological - @a0_0_1.instance_variable_set :@files, "F" - @a0_0_1.instance_variable_set :@test_files, "TF" - @a0_0_1.instance_variable_set :@extra_rdoc_files, "ERF" - @a0_0_1.instance_variable_set :@extensions, "E" - @a0_0_1.instance_variable_set :@executables, "X" + @a1.instance_variable_set :@files, "F" + @a1.instance_variable_set :@test_files, "TF" + @a1.instance_variable_set :@extra_rdoc_files, "ERF" + @a1.instance_variable_set :@extensions, "E" + @a1.instance_variable_set :@executables, "X" + + assert_equal %w[E ERF F TF bin/X], @a1.files.sort + assert_kind_of Integer, @a1.hash + end - assert_equal %w[E ERF F TF bin/X], @a0_0_1.files.sort - assert_kind_of Integer, @a0_0_1.hash + def test_full_gem_path + assert_equal File.join(@gemhome, 'gems', @a1.full_name), + @a1.full_gem_path + + @a1.original_platform = 'mswin32' + + assert_equal File.join(@gemhome, 'gems', @a1.original_name), + @a1.full_gem_path end def test_full_name - assert_equal 'a-0.0.1', @a0_0_1.full_name + assert_equal 'a-1', @a1.full_name - @a0_0_1.platform = Gem::Platform.new ['universal', 'darwin', nil] - assert_equal 'a-0.0.1-universal-darwin', @a0_0_1.full_name + @a1.platform = Gem::Platform.new ['universal', 'darwin', nil] + assert_equal 'a-1-universal-darwin', @a1.full_name - @a0_0_1.instance_variable_set :@new_platform, 'mswin32' - assert_equal 'a-0.0.1-mswin32', @a0_0_1.full_name, 'legacy' + @a1.instance_variable_set :@new_platform, 'mswin32' + assert_equal 'a-1-mswin32', @a1.full_name, 'legacy' return if win_platform? - @a0_0_1.platform = 'current' - assert_equal 'a-0.0.1-x86-darwin-8', @a0_0_1.full_name + @a1.platform = 'current' + assert_equal 'a-1-x86-darwin-8', @a1.full_name end def test_full_name_windows test_cases = { - 'i386-mswin32' => 'a-0.0.1-x86-mswin32-60', - 'i386-mswin32_80' => 'a-0.0.1-x86-mswin32-80', - 'i386-mingw32' => 'a-0.0.1-x86-mingw32' + 'i386-mswin32' => 'a-1-x86-mswin32-60', + 'i386-mswin32_80' => 'a-1-x86-mswin32-80', + 'i386-mingw32' => 'a-1-x86-mingw32' } test_cases.each do |arch, expected| util_set_arch arch - @a0_0_1.platform = 'current' - assert_equal expected, @a0_0_1.full_name + @a1.platform = 'current' + assert_equal expected, @a1.full_name end end def test_has_rdoc_eh - assert_equal true, @a0_0_1.has_rdoc? + assert_equal true, @a1.has_rdoc? end def test_hash - assert_equal @a0_0_1.hash, @a0_0_1.hash - assert_equal @a0_0_1.hash, @a0_0_1.dup.hash - assert_not_equal @a0_0_1.hash, @a0_0_2.hash + assert_equal @a1.hash, @a1.hash + assert_equal @a1.hash, @a1.dup.hash + assert_not_equal @a1.hash, @a2.hash end def test_lib_files - @a0_0_1.files = %w[lib/foo.rb Rakefile] + @a1.files = %w[lib/foo.rb Rakefile] - assert_equal %w[lib/foo.rb], @a0_0_1.lib_files + assert_equal %w[lib/foo.rb], @a1.lib_files end def test_name - assert_equal 'a', @a0_0_1.name + assert_equal 'a', @a1.name end def test_original_name - assert_equal 'a-0.0.1', @a0_0_1.full_name + assert_equal 'a-1', @a1.full_name - @a0_0_1.platform = 'i386-linux' - @a0_0_1.instance_variable_set :@original_platform, 'i386-linux' - assert_equal 'a-0.0.1-i386-linux', @a0_0_1.original_name + @a1.platform = 'i386-linux' + @a1.instance_variable_set :@original_platform, 'i386-linux' + assert_equal 'a-1-i386-linux', @a1.original_name end def test_platform - assert_equal Gem::Platform::RUBY, @a0_0_1.platform + assert_equal Gem::Platform::RUBY, @a1.platform end def test_platform_equals - @a0_0_1.platform = nil - assert_equal Gem::Platform::RUBY, @a0_0_1.platform + @a1.platform = nil + assert_equal Gem::Platform::RUBY, @a1.platform - @a0_0_1.platform = Gem::Platform::RUBY - assert_equal Gem::Platform::RUBY, @a0_0_1.platform + @a1.platform = Gem::Platform::RUBY + assert_equal Gem::Platform::RUBY, @a1.platform test_cases = { 'i386-mswin32' => ['x86', 'mswin32', '60'], @@ -484,29 +500,35 @@ end test_cases.each do |arch, expected| util_set_arch arch - @a0_0_1.platform = Gem::Platform::CURRENT - assert_equal Gem::Platform.new(expected), @a0_0_1.platform + @a1.platform = Gem::Platform::CURRENT + assert_equal Gem::Platform.new(expected), @a1.platform end end + def test_platform_equals_current + @a1.platform = Gem::Platform::CURRENT + assert_equal Gem::Platform.local, @a1.platform + assert_equal Gem::Platform.local.to_s, @a1.original_platform + end + def test_platform_equals_legacy - @a0_0_1.platform = Gem::Platform::WIN32 - assert_equal Gem::Platform::MSWIN32, @a0_0_1.platform + @a1.platform = 'mswin32' + assert_equal Gem::Platform.new('x86-mswin32'), @a1.platform - @a0_0_1.platform = Gem::Platform::LINUX_586 - assert_equal Gem::Platform::X86_LINUX, @a0_0_1.platform + @a1.platform = 'i586-linux' + assert_equal Gem::Platform.new('x86-linux'), @a1.platform - @a0_0_1.platform = Gem::Platform::DARWIN - assert_equal Gem::Platform::PPC_DARWIN, @a0_0_1.platform + @a1.platform = 'powerpc-darwin' + assert_equal Gem::Platform.new('ppc-darwin'), @a1.platform end def test_require_paths - @a0_0_1.require_path = 'lib' - assert_equal %w[lib], @a0_0_1.require_paths + @a1.require_path = 'lib' + assert_equal %w[lib], @a1.require_paths end def test_requirements - assert_equal ['A working computer'], @a0_0_1.requirements + assert_equal ['A working computer'], @a1.requirements end def test_spaceship_name @@ -539,28 +561,22 @@ end end def test_summary - assert_equal 'this is a summary', @a0_0_1.summary + assert_equal 'this is a summary', @a1.summary end def test_test_files - @a0_0_1.test_file = 'test/suite.rb' - assert_equal ['test/suite.rb'], @a0_0_1.test_files - end - - def test_test_suite_file - @a0_0_2.test_suite_file = 'test/suite.rb' - assert_equal ['test/suite.rb'], @a0_0_2.test_files - # XXX: what about the warning? + @a1.test_file = 'test/suite.rb' + assert_equal ['test/suite.rb'], @a1.test_files end def test_to_ruby - @a0_0_2.required_rubygems_version = Gem::Requirement.new '> 0' + @a2.required_rubygems_version = Gem::Requirement.new '> 0' - ruby_code = @a0_0_2.to_ruby + ruby_code = @a2.to_ruby expected = "Gem::Specification.new do |s| s.name = %q{a} - s.version = \"0.0.2\" + s.version = \"2\" s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION} if s.respond_to? :specification_version= @@ -582,17 +598,20 @@ end same_spec = eval ruby_code - assert_equal @a0_0_2, same_spec + assert_equal @a2, same_spec end def test_to_ruby_fancy - @a0_0_1.platform = Gem::Platform::PPC_DARWIN - ruby_code = @a0_0_1.to_ruby + @a1.platform = Gem::Platform.local + ruby_code = @a1.to_ruby + + local = Gem::Platform.local + expected_platform = "[#{local.cpu.inspect}, #{local.os.inspect}, #{local.version.inspect}]" expected = "Gem::Specification.new do |s| s.name = %q{a} - s.version = \"0.0.1\" - s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil]) + s.version = \"1\" + s.platform = Gem::Platform.new(#{expected_platform}) s.specification_version = 2 if s.respond_to? :specification_version= @@ -609,6 +628,7 @@ end s.homepage = %q{http://example.com} s.require_paths = [\"lib\"] s.requirements = [\"A working computer\"] + s.rubyforge_project = %q{example} s.rubygems_version = %q{#{Gem::RubyGemsVersion}} s.summary = %q{this is a summary} s.test_files = [\"test/suite.rb\"] @@ -623,7 +643,7 @@ end same_spec = eval ruby_code - assert_equal @a0_0_1, same_spec + assert_equal @a1, same_spec end def test_to_ruby_legacy @@ -635,10 +655,10 @@ end end def test_to_ruby_platform - @a0_0_2.platform = Gem::Platform.local - @a0_0_2.instance_variable_set :@original_platform, 'old_platform' + @a2.platform = Gem::Platform.local + @a2.instance_variable_set :@original_platform, 'old_platform' - ruby_code = @a0_0_2.to_ruby + ruby_code = @a2.to_ruby same_spec = eval ruby_code @@ -646,28 +666,34 @@ end end def test_to_yaml - yaml_str = @a0_0_1.to_yaml + yaml_str = @a1.to_yaml same_spec = YAML.load(yaml_str) - assert_equal @a0_0_1, same_spec + assert_equal @a1, same_spec end def test_to_yaml_fancy - @a0_0_1.platform = Gem::Platform::PPC_DARWIN - yaml_str = @a0_0_1.to_yaml + @a1.platform = Gem::Platform.local + yaml_str = @a1.to_yaml same_spec = YAML.load(yaml_str) - assert_equal Gem::Platform::PPC_DARWIN, same_spec.platform + assert_equal Gem::Platform.local, same_spec.platform - assert_equal @a0_0_1, same_spec + assert_equal @a1, same_spec end - def test_to_yaml_legacy_platform - @a0_0_1.platform = 'powerpc-darwin7.9.0' - @a0_0_1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0' + def test_to_yaml_platform_empty_string + @a1.instance_variable_set :@original_platform, '' - yaml_str = @a0_0_1.to_yaml + assert_match %r|^platform: ruby$|, @a1.to_yaml + end + + def test_to_yaml_platform_legacy + @a1.platform = 'powerpc-darwin7.9.0' + @a1.instance_variable_set :@original_platform, 'powerpc-darwin7.9.0' + + yaml_str = @a1.to_yaml same_spec = YAML.load(yaml_str) @@ -675,8 +701,61 @@ end assert_equal 'powerpc-darwin7.9.0', same_spec.original_platform end + def test_to_yaml_platform_nil + @a1.instance_variable_set :@original_platform, nil + + assert_match %r|^platform: ruby$|, @a1.to_yaml + end + def test_validate - assert @a0_0_1.validate + Dir.chdir @tempdir do + assert @a1.validate + end + end + + def test_validate_authors + Dir.chdir @tempdir do + @a1.authors = [] + + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: no author specified\n", @ui.error, 'error' + + @a1.authors = [Object.new] + + e = assert_raise Gem::InvalidSpecificationException do + @a1.validate + end + + assert_equal 'authors must be Array of Strings', e.message + end + end + + def test_validate_autorequire + Dir.chdir @tempdir do + @a1.autorequire = 'code' + + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: deprecated autorequire specified\n", + @ui.error, 'error' + end + end + + def test_validate_email + Dir.chdir @tempdir do + @a1.email = '' + + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: no email specified\n", @ui.error, 'error' + end end def test_validate_empty @@ -687,51 +766,104 @@ end assert_equal 'missing value for attribute name', e.message end + def test_validate_executables + FileUtils.mkdir_p File.join(@tempdir, 'bin') + File.open File.join(@tempdir, 'bin', 'exec'), 'w' do end + + use_ui @ui do + Dir.chdir @tempdir do + assert @a1.validate + end + end + + assert_equal '', @ui.output, 'output' + assert_equal "WARNING: bin/exec is missing #! line\n", @ui.error, 'error' + end + def test_validate_empty_require_paths - @a0_0_1.require_paths = [] + @a1.require_paths = [] e = assert_raise Gem::InvalidSpecificationException do - @a0_0_1.validate + @a1.validate end assert_equal 'specification must have at least one require_path', e.message end - def test_validate_platform_bad - @a0_0_1.platform = Object.new - assert_raise Gem::InvalidSpecificationException do @a0_0_1.validate end + def test_validate_homepage + Dir.chdir @tempdir do + @a1.homepage = '' - @a0_0_1.platform = "my-custom-platform" - e = assert_raise Gem::InvalidSpecificationException do - @a0_0_1.validate + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: no homepage specified\n", @ui.error, 'error' end + end - assert_equal 'invalid platform "my-custom-platform", see Gem::Platform', - e.message + def test_validate_has_rdoc + Dir.chdir @tempdir do + @a1.has_rdoc = false + + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: RDoc will not be generated (has_rdoc == false)\n", + @ui.error, 'error' + end end def test_validate_platform_legacy - @a0_0_1.platform = Gem::Platform::WIN32 - assert @a0_0_1.validate + Dir.chdir @tempdir do + @a1.platform = 'mswin32' + assert @a1.validate + + @a1.platform = 'i586-linux' + assert @a1.validate + + @a1.platform = 'powerpc-darwin' + assert @a1.validate + end + end - @a0_0_1.platform = Gem::Platform::LINUX_586 - assert @a0_0_1.validate + def test_validate_rubyforge_project + Dir.chdir @tempdir do + @a1.rubyforge_project = '' - @a0_0_1.platform = Gem::Platform::DARWIN - assert @a0_0_1.validate + 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 - @a0_0_1.rubygems_version = "3" + @a1.rubygems_version = "3" e = assert_raise Gem::InvalidSpecificationException do - @a0_0_1.validate + @a1.validate end assert_equal "expected RubyGems version #{Gem::RubyGemsVersion}, was 3", e.message end + def test_validate_summary + Dir.chdir @tempdir do + @a1.summary = '' + + use_ui @ui do + @a1.validate + end + + assert_equal "WARNING: no summary specified\n", @ui.error, 'error' + end + end + def test_version - assert_equal Gem::Version.new('0.0.1'), @a0_0_1.version + assert_equal Gem::Version.new('1'), @a1.version end end diff --git a/test/rubygems/test_gem_version.rb b/test/rubygems/test_gem_version.rb index 95f37ddd23..99dd49933d 100644 --- a/test/rubygems/test_gem_version.rb +++ b/test/rubygems/test_gem_version.rb @@ -55,6 +55,11 @@ class TestGemVersion < RubyGemTestCase assert_inadequate( "1.0.0.1", "= 1.0") end + def test_bump_trailing_zeros + v = Gem::Version.new("5.0.0") + assert_equal "5.1", v.bump.to_s + end + def test_bump v = Gem::Version.new("5.2.4") assert_equal "5.3", v.bump.to_s @@ -65,6 +70,16 @@ class TestGemVersion < RubyGemTestCase assert_equal "6", v.bump.to_s end + def test_eql_eh + v = Gem::Version.new("1.2") + + assert_equal true, v.eql?(@v1_2) + assert_equal true, @v1_2.eql?(v) + + assert_equal false, @v1_2.eql?(@v1_3) + assert_equal false, @v1_3.eql?(@v1_2) + end + def test_equals2 v = Gem::Version.new("1.2") diff --git a/test/rubygems/test_kernel.rb b/test/rubygems/test_kernel.rb index d7d5eaaee2..e06a78e32a 100644 --- a/test/rubygems/test_kernel.rb +++ b/test/rubygems/test_kernel.rb @@ -25,39 +25,39 @@ class TestKernel < RubyGemTestCase end def test_gem - assert gem('a', '= 0.0.1'), "Should load" - assert $:.any? { |p| %r{a-0.0.1/lib} =~ p } - assert $:.any? { |p| %r{a-0.0.1/bin} =~ p } + 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', '= 0.0.1'), "Should load" - assert ! gem('a', '= 0.0.1'), "Should not load" - assert_equal 1, $:.select { |p| %r{a-0.0.1/lib} =~ p }.size - assert_equal 1, $:.select { |p| %r{a-0.0.1/bin} =~ p }.size + assert gem('a', '= 1'), "Should load" + assert ! 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', '= 0.0.1'), "Should load" - assert ! gem('a', '>= 0.0.1'), "Should not load" - assert_equal 1, $:.select { |p| %r{a-0.0.1/lib} =~ p }.size - assert_equal 1, $:.select { |p| %r{a-0.0.1/bin} =~ p }.size + assert gem('a', '= 1'), "Should load" + assert ! 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 - assert gem('a', '= 0.0.1'), "Should load" + assert gem('a', '= 1'), "Should load" ex = assert_raise Gem::Exception do - gem 'a', '= 0.0.2' + gem 'a', '= 2' end - assert_match(/activate a \(= 0\.0\.2\)/, ex.message) - assert_match(/activated a-0\.0\.1/, ex.message) + assert_match(/activate a \(= 2\)/, ex.message) + assert_match(/activated a-1/, ex.message) - assert $:.any? { |p| %r{a-0.0.1/lib} =~ p } - assert $:.any? { |p| %r{a-0.0.1/bin} =~ p } - assert ! $:.any? { |p| %r{a-0.0.2/lib} =~ p } - assert ! $:.any? { |p| %r{a-0.0.2/bin} =~ p } + assert $:.any? { |p| %r{a-1/lib} =~ p } + assert $:.any? { |p| %r{a-1/bin} =~ p } + assert ! $:.any? { |p| %r{a-2/lib} =~ p } + assert ! $:.any? { |p| %r{a-2/bin} =~ p } end end -- cgit v1.2.3