From db74541efec489c62310ab85091b28bb360e79c8 Mon Sep 17 00:00:00 2001 From: drbrain Date: Tue, 20 Nov 2007 05:56:43 +0000 Subject: Update to RubyGems 0.9.5 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/gemutilities.rb | 26 +++++++---- test/rubygems/test_gem.rb | 35 +++++++++------ .../test_gem_commands_environment_command.rb | 5 ++- test/rubygems/test_gem_dependency_installer.rb | 51 ++++++++++++++++------ test/rubygems/test_gem_ext_configure_builder.rb | 2 +- test/rubygems/test_gem_format.rb | 18 ++++++++ test/rubygems/test_gem_indexer.rb | 42 ++++++++++++------ test/rubygems/test_gem_platform.rb | 1 + test/rubygems/test_gem_specification.rb | 35 ++++++++++++++- 9 files changed, 162 insertions(+), 53 deletions(-) (limited to 'test') diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index 96711be485..0d5ab0297a 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -39,7 +39,7 @@ class FakeFetcher @paths << path raise ArgumentError, 'need full URI' unless path =~ %r'^http://' data = @data[path] - raise OpenURI::HTTPError.new("no data for #{path}", nil) if data.nil? + raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil? data.respond_to?(:call) ? data.call : data end @@ -48,7 +48,7 @@ class FakeFetcher @paths << path raise ArgumentError, 'need full URI' unless path =~ %r'^http://' data = @data[path] - raise OpenURI::HTTPError.new("no data for #{path}", nil) if data.nil? + raise Gem::RemoteFetcher::FetchError, "no data for #{path}" if data.nil? data.respond_to?(:call) ? data.call : data.length end @@ -189,7 +189,8 @@ class RubyGemTestCase < Test::Unit::TestCase Gem::Builder.new(spec).build end - FileUtils.mv "#{spec.full_name}.gem", File.join(@gemhome, 'cache') + FileUtils.mv "#{spec.full_name}.gem", + File.join(@gemhome, 'cache', "#{spec.original_name}.gem") end end @@ -203,13 +204,22 @@ class RubyGemTestCase < Test::Unit::TestCase @a0_0_2 = quick_gem('a', '0.0.2', &spec) @b0_0_2 = quick_gem('b', '0.0.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] + s.require_paths = %w[lib] + s.platform = Gem::Platform.new 'i386-linux' + 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 #{@c1_2.original_name} lib code.rb]) do end + write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb]) do end - write_file File.join(*%w[gems a-0.0.1 lib code.rb]) do end - write_file File.join(*%w[gems a-0.0.2 lib code.rb]) do end - write_file File.join(*%w[gems b-0.0.2 lib code.rb]) do end - write_file File.join(*%w[gems c-1.2 lib code.rb]) do end + [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].each { |spec| util_build_gem spec } - [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2].each { |spec| util_build_gem spec } + FileUtils.rm_r File.join(@gemhome, 'gems', @pl1.original_name) Gem.source_index = nil end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 723b2559bc..4fe5e8661c 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -10,17 +10,18 @@ class TestGem < RubyGemTestCase super @additional = %w[a b].map { |d| File.join @tempdir, d } - @default_dir_re = %r|/ruby/gems/[0-9.]+| + @default_dir_re = %r|/[Rr]uby/[Gg]ems/[0-9.]+| end def test_self_all_load_paths util_make_gems expected = [ - File.join(@tempdir, *%w[gemhome gems a-0.0.1 lib]), - File.join(@tempdir, *%w[gemhome gems a-0.0.2 lib]), - File.join(@tempdir, *%w[gemhome gems b-0.0.2 lib]), - File.join(@tempdir, *%w[gemhome gems c-1.2 lib]), + 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 #{@c1_2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]), ] assert_equal expected, Gem.all_load_paths.sort @@ -34,8 +35,9 @@ class TestGem < RubyGemTestCase def test_self_bindir_default_dir default = Gem.default_dir - assert_equal Config::CONFIG['bindir'], Gem.bindir(default) - assert_equal Config::CONFIG['bindir'], Gem.bindir(Pathname.new(default)) + bindir = (defined? RUBY_FRAMEWORK_VERSION) ? '/usr/bin' : Config::CONFIG['bindir'] + assert_equal bindir, Gem.bindir(default) + assert_equal bindir, Gem.bindir(Pathname.new(default)) end def test_self_clear_paths @@ -172,9 +174,10 @@ class TestGem < RubyGemTestCase util_make_gems expected = [ - File.join(@tempdir, *%w[gemhome gems a-0.0.2 lib]), - File.join(@tempdir, *%w[gemhome gems b-0.0.2 lib]), - File.join(@tempdir, *%w[gemhome gems c-1.2 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 #{@c1_2.full_name} lib]), + File.join(@gemhome, *%W[gems #{@pl1.full_name} lib]), ] assert_equal expected, Gem.latest_load_paths.sort @@ -195,13 +198,15 @@ class TestGem < RubyGemTestCase end def test_self_path_ENV_PATH + Gem.clear_paths + path_count = Gem.path.size Gem.clear_paths util_ensure_gem_dirs ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR) assert_equal @additional, Gem.path[0,2] - assert_equal 3, Gem.path.size + assert_equal path_count + @additional.size, Gem.path.size assert_match Gem.dir, Gem.path.last end @@ -214,7 +219,9 @@ class TestGem < RubyGemTestCase ENV['GEM_PATH'] = dirs.join File::PATH_SEPARATOR assert_equal @gemhome, Gem.dir - assert_equal @additional + [Gem.dir], Gem.path + paths = [Gem.dir] + paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME + assert_equal @additional + paths, Gem.path end def test_self_path_overlap @@ -225,7 +232,9 @@ class TestGem < RubyGemTestCase ENV['GEM_PATH'] = @additional.join(File::PATH_SEPARATOR) assert_equal @gemhome, Gem.dir - assert_equal @additional + [Gem.dir], Gem.path + paths = [Gem.dir] + paths.insert(0, APPLE_GEM_HOME) if defined? APPLE_GEM_HOME + assert_equal @additional + paths, Gem.path end def test_self_platforms diff --git a/test/rubygems/test_gem_commands_environment_command.rb b/test/rubygems/test_gem_commands_environment_command.rb index 0b97009efa..65c8cf3133 100644 --- a/test/rubygems/test_gem_commands_environment_command.rb +++ b/test/rubygems/test_gem_commands_environment_command.rb @@ -22,13 +22,14 @@ class TestGemCommandsEnvironmentCommand < RubyGemTestCase assert_match %r|RUBYGEMS VERSION: (\d\.)+\d \((\d\.)+\d\)|, @ui.output assert_match %r|RUBY VERSION: \d\.\d\.\d \(.*\) \[.*\]|, @ui.output - assert_match %r|INSTALLATION DIRECTORY: #{@gemhome}|, @ui.output + assert_match %r|INSTALLATION DIRECTORY: #{Regexp.escape @gemhome}|, + @ui.output assert_match %r|RUBYGEMS PREFIX: |, @ui.output assert_match %r|RUBY EXECUTABLE:.*ruby|, @ui.output assert_match %r|RUBYGEMS PLATFORMS:|, @ui.output assert_match %r|- #{Gem::Platform.local}|, @ui.output assert_match %r|GEM PATHS:|, @ui.output - assert_match %r|- #{@gemhome}|, @ui.output + assert_match %r|- #{Regexp.escape @gemhome}|, @ui.output assert_match %r|GEM CONFIGURATION:|, @ui.output assert_match %r|:verbose => |, @ui.output assert_match %r|REMOTE SOURCES:|, @ui.output diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index 18793d3065..c299476eeb 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -92,13 +92,13 @@ class TestGemDependencyInstaller < RubyGemTestCase end def test_install_dependency_old - @e1, @e1_gem = util_gem 'e', '1' - @f1, @f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end - @f2, @f2_gem = util_gem 'f', '2' + e1, e1_gem = util_gem 'e', '1' + f1, f1_gem = util_gem 'f', '1' do |s| s.add_dependency 'e' end + f2, f2_gem = util_gem 'f', '2' - FileUtils.mv @e1_gem, @tempdir - FileUtils.mv @f1_gem, @tempdir - FileUtils.mv @f2_gem, @tempdir + FileUtils.mv e1_gem, @tempdir + FileUtils.mv f1_gem, @tempdir + FileUtils.mv f2_gem, @tempdir inst = nil Dir.chdir @tempdir do @@ -333,7 +333,7 @@ class TestGemDependencyInstaller < RubyGemTestCase assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name } end - def test_download_gem + def test_download a1_data = nil File.open @a1_gem, 'rb' do |fp| a1_data = fp.read @@ -349,7 +349,7 @@ class TestGemDependencyInstaller < RubyGemTestCase assert File.exist?(a1_cache_gem) end - def test_download_gem_cached + def test_download_cached FileUtils.mv @a1_gem, @cache_dir inst = Gem::DependencyInstaller.new 'a' @@ -358,7 +358,7 @@ class TestGemDependencyInstaller < RubyGemTestCase inst.download(@a1, 'http://gems.example.com') end - def test_download_gem_local + def test_download_local FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, "#{@a1.full_name}.gem" inst = nil @@ -371,7 +371,7 @@ class TestGemDependencyInstaller < RubyGemTestCase inst.download(@a1, local_path) end - def test_download_gem_install_dir + def test_download_install_dir a1_data = nil File.open @a1_gem, 'rb' do |fp| a1_data = fp.read @@ -390,7 +390,7 @@ class TestGemDependencyInstaller < RubyGemTestCase end unless win_platform? then # File.chmod doesn't work - def test_download_gem_local_read_only + def test_download_local_read_only FileUtils.mv @a1_gem, @tempdir local_path = File.join @tempdir, "#{@a1.full_name}.gem" inst = nil @@ -407,7 +407,30 @@ class TestGemDependencyInstaller < RubyGemTestCase end end - def test_download_gem_unsupported + def test_download_platform_legacy + original_platform = 'old-platform' + + e1, e1_gem = util_gem 'e', '1' do |s| + s.platform = Gem::Platform::CURRENT + s.instance_variable_set :@original_platform, original_platform + end + + e1_data = nil + File.open e1_gem, 'rb' do |fp| + e1_data = fp.read + end + + @fetcher.data["http://gems.example.com/gems/e-1-#{original_platform}.gem"] = e1_data + + inst = Gem::DependencyInstaller.new 'a' + + e1_cache_gem = File.join(@gemhome, 'cache', "#{e1.full_name}.gem") + assert_equal e1_cache_gem, inst.download(e1, 'http://gems.example.com') + + assert File.exist?(e1_cache_gem) + end + + def test_download_unsupported inst = Gem::DependencyInstaller.new 'a' e = assert_raise Gem::InstallError do @@ -503,8 +526,8 @@ class TestGemDependencyInstaller < RubyGemTestCase util_build_gem spec - cache_file = File.join @tempdir, 'gems', "#{spec.full_name}.gem" - FileUtils.mv File.join(@gemhome, 'cache', "#{spec.full_name}.gem"), + cache_file = File.join @tempdir, 'gems', "#{spec.original_name}.gem" + FileUtils.mv File.join(@gemhome, 'cache', "#{spec.original_name}.gem"), cache_file FileUtils.rm File.join(@gemhome, 'specifications', "#{spec.full_name}.gemspec") diff --git a/test/rubygems/test_gem_ext_configure_builder.rb b/test/rubygems/test_gem_ext_configure_builder.rb index c32aa2e23f..25aa7412aa 100644 --- a/test/rubygems/test_gem_ext_configure_builder.rb +++ b/test/rubygems/test_gem_ext_configure_builder.rb @@ -49,7 +49,7 @@ class TestGemExtConfigureBuilder < RubyGemTestCase expected = %r|configure failed: -sh \./configure --prefix=#{@dest_path} +sh \./configure --prefix=#{Regexp.escape @dest_path} .*?: \./configure: No such file or directory | diff --git a/test/rubygems/test_gem_format.rb b/test/rubygems/test_gem_format.rb index 2b7d821952..6bc7a42e81 100644 --- a/test/rubygems/test_gem_format.rb +++ b/test/rubygems/test_gem_format.rb @@ -17,6 +17,24 @@ class TestGemFormat < RubyGemTestCase @simple_gem = SIMPLE_GEM end + def test_from_file_by_path + util_make_gems + + gems = Dir[File.join(@gemhome, 'cache', '*.gem')] + + names = [@a0_0_1, @a0_0_2, @b0_0_2, @c1_2, @pl1].map do |spec| + spec.original_name + end + + gems_n_names = gems.sort.zip names + + gems_n_names.each do |gemfile, name| + spec = Gem::Format.from_file_by_path(gemfile).spec + + assert_equal name, spec.original_name + end + end + def test_from_file_by_path_nonexistent assert_raise Gem::Exception do Gem::Format.from_file_by_path '/nonexistent' diff --git a/test/rubygems/test_gem_indexer.rb b/test/rubygems/test_gem_indexer.rb index de509c6b97..116a29c562 100644 --- a/test/rubygems/test_gem_indexer.rb +++ b/test/rubygems/test_gem_indexer.rb @@ -49,16 +49,23 @@ class TestGemIndexer < RubyGemTestCase assert File.directory?(quickdir) assert File.directory?(marshal_quickdir) - assert File.exist?(File.join(quickdir, "index")) - assert File.exist?(File.join(quickdir, "index.rz")) - assert File.exist?(File.join(quickdir, "#{@a0_0_1.full_name}.gemspec.rz")) - assert File.exist?(File.join(marshal_quickdir, "#{@a0_0_1.full_name}.gemspec.rz")) - assert File.exist?(File.join(quickdir, "#{@a0_0_2.full_name}.gemspec.rz")) - assert File.exist?(File.join(marshal_quickdir, "#{@a0_0_2.full_name}.gemspec.rz")) - assert File.exist?(File.join(quickdir, "#{@b0_0_2.full_name}.gemspec.rz")) - assert File.exist?(File.join(quickdir, "#{@c1_2.full_name}.gemspec.rz")) - assert !File.exist?(File.join(quickdir, "#{@c1_2.full_name}.gemspec")) - assert !File.exist?(File.join(marshal_quickdir, "#{@c1_2.full_name}.gemspec")) + + 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, "#{@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" + + deny_indexed quickdir, "#{@c1_2.full_name}.gemspec" + deny_indexed marshal_quickdir, "#{@c1_2.full_name}.gemspec" end def test_generate_index_ui @@ -67,8 +74,8 @@ class TestGemIndexer < RubyGemTestCase end expected = <<-EOF -Generating index for 4 gems in #{@tempdir} -.... +Generating index for 5 gems in #{@tempdir} +..... Loaded all gems Generating master indexes (this may take a while) EOF @@ -92,12 +99,21 @@ Generating master indexes (this may take a while) dump_index.each do |_,gem| gem.send :remove_instance_variable, :@loaded - gem.send :remove_instance_variable, :@original_platform end assert_equal yaml_index, dump_index, "expected YAML and Marshal to produce identical results" end + def assert_indexed(dir, name) + file = File.join dir, name + assert File.exist?(file), "#{file} does not exist" + end + + def deny_indexed(dir, name) + file = File.join dir, name + assert !File.exist?(file), "#{file} exists" + end + end if ''.respond_to? :to_xs diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 4c583edf27..4a1651bc0e 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -21,6 +21,7 @@ class TestGemPlatform < RubyGemTestCase def test_self_new assert_equal Gem::Platform::RUBY, Gem::Platform.new(Gem::Platform::RUBY) assert_equal Gem::Platform::RUBY, Gem::Platform.new(nil) + assert_equal Gem::Platform::RUBY, Gem::Platform.new('') end def test_initialize diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 96db29c2c0..69d625ceb6 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -196,6 +196,17 @@ end assert_equal "1.3.5", spec.version.to_s end + def test__dump + @a0_0_2.platform = Gem::Platform.local + @a0_0_2.instance_variable_set :@original_platform, 'old_platform' + + data = Marshal.dump @a0_0_2 + + same_spec = Marshal.load data + + assert_equal 'old_platform', same_spec.original_platform + end + def test_author assert_equal 'A User', @a0_0_1.author end @@ -445,6 +456,14 @@ end assert_equal 'a', @a0_0_1.name end + def test_original_name + assert_equal 'a-0.0.1', @a0_0_1.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 + end + def test_platform assert_equal Gem::Platform::RUBY, @a0_0_1.platform end @@ -573,6 +592,7 @@ end expected = "Gem::Specification.new do |s| s.name = %q{a} s.version = \"0.0.1\" + s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil]) s.specification_version = 2 if s.respond_to? :specification_version= @@ -587,10 +607,9 @@ end s.files = [\"lib/code.rb\", \"test/suite.rb\", \"bin/exec\", \"ext/a/extconf.rb\"] s.has_rdoc = %q{true} s.homepage = %q{http://example.com} - s.platform = Gem::Platform.new([\"ppc\", \"darwin\", nil]) s.require_paths = [\"lib\"] s.requirements = [\"A working computer\"] - s.rubygems_version = %q{0.9.4.6} + s.rubygems_version = %q{#{Gem::RubyGemsVersion}} s.summary = %q{this is a summary} s.test_files = [\"test/suite.rb\"] @@ -615,6 +634,17 @@ end assert_equal gemspec1, gemspec2 end + def test_to_ruby_platform + @a0_0_2.platform = Gem::Platform.local + @a0_0_2.instance_variable_set :@original_platform, 'old_platform' + + ruby_code = @a0_0_2.to_ruby + + same_spec = eval ruby_code + + assert_equal 'old_platform', same_spec.original_platform + end + def test_to_yaml yaml_str = @a0_0_1.to_yaml same_spec = YAML.load(yaml_str) @@ -635,6 +665,7 @@ 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' yaml_str = @a0_0_1.to_yaml -- cgit v1.2.3