From 8cc45aae947d453acca029e13eb64f3f5f0bf942 Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 31 Mar 2008 22:40:06 +0000 Subject: Import RubyGems 1.1.0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rubygems/test_gem_dependency_installer.rb | 351 ++++++++++++------------- 1 file changed, 167 insertions(+), 184 deletions(-) (limited to 'test/rubygems/test_gem_dependency_installer.rb') diff --git a/test/rubygems/test_gem_dependency_installer.rb b/test/rubygems/test_gem_dependency_installer.rb index d2d33fa313..576143904a 100644 --- a/test/rubygems/test_gem_dependency_installer.rb +++ b/test/rubygems/test_gem_dependency_installer.rb @@ -54,8 +54,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a' - inst.install + inst = Gem::DependencyInstaller.new + inst.install 'a' end assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), @@ -70,8 +70,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'b' - inst.install + inst = Gem::DependencyInstaller.new + inst.install 'b' end assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } @@ -84,8 +84,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'b' - inst.install + inst = Gem::DependencyInstaller.new + inst.install 'b' end assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } @@ -102,8 +102,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'f' - inst.install + inst = Gem::DependencyInstaller.new + inst.install 'f' end assert_equal %w[f-2], inst.installed_gems.map { |s| s.full_name } @@ -114,19 +114,49 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a-1.gem' - inst.install + inst = Gem::DependencyInstaller.new :domain => :local + inst.install 'a-1.gem' end assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end + def test_install_local_dependency + FileUtils.mv @a1_gem, @tempdir + FileUtils.mv @b1_gem, @tempdir + + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new :domain => :local + inst.install 'b-1.gem' + end + + assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } + end + + def test_install_local_dependency_installed + FileUtils.mv @a1_gem, @tempdir + FileUtils.mv @b1_gem, @tempdir + + inst = nil + + Dir.chdir @tempdir do + Gem::Installer.new('a-1.gem').install + + inst = Gem::DependencyInstaller.new :domain => :local + inst.install 'b-1.gem' + end + + assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } + end + def test_install_local_subdir inst = nil - + Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'gems/a-1.gem' - inst.install + inst = Gem::DependencyInstaller.new :domain => :local + inst.install 'gems/a-1.gem' end assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } @@ -137,12 +167,11 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a', nil, :env_shebang => true, - :wrappers => true - inst.install + inst = Gem::DependencyInstaller.new :env_shebang => true, :wrappers => true + inst.install 'a' end - assert_match %r|\A#!/usr/bin/env ruby\n|, + assert_match %r|\A#!/usr/bin/env #{Gem::ConfigMap[:RUBY_INSTALL_NAME]}\n|, File.read(File.join(@gemhome, 'bin', 'a_bin')) end @@ -153,8 +182,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'b', nil, :force => true - inst.install + inst = Gem::DependencyInstaller.new :force => true + inst.install 'b' end assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } @@ -165,8 +194,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'b', nil, :ignore_dependencies => true - inst.install + inst = Gem::DependencyInstaller.new :ignore_dependencies => true + inst.install 'b' end assert_equal %w[b-1], inst.installed_gems.map { |s| s.full_name } @@ -179,8 +208,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a', nil, :install_dir => gemhome2 - inst.install + inst = Gem::DependencyInstaller.new :install_dir => gemhome2 + inst.install 'a' end assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } @@ -201,8 +230,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'b', nil, :domain => :both - inst.install + inst = Gem::DependencyInstaller.new :domain => :both + inst.install 'b' end assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } @@ -217,14 +246,34 @@ class TestGemDependencyInstaller < RubyGemTestCase assert_equal b1_expected, b1.loaded_from end + def test_install_domain_both_no_network + Gem::SourceInfoCache.instance_variable_set :@cache, nil + + @fetcher.data["http://gems.example.com/gems/Marshal.#{@marshal_version}"] = + proc do + raise Gem::RemoteFetcher::FetchError + end + + FileUtils.mv @a1_gem, @tempdir + FileUtils.mv @b1_gem, @tempdir + inst = nil + + Dir.chdir @tempdir do + inst = Gem::DependencyInstaller.new :domain => :both + inst.install 'b' + end + + assert_equal %w[a-1 b-1], inst.installed_gems.map { |s| s.full_name } + end + def test_install_domain_local FileUtils.mv @b1_gem, @tempdir inst = nil Dir.chdir @tempdir do e = assert_raise Gem::InstallError do - inst = Gem::DependencyInstaller.new 'b', nil, :domain => :local - inst.install + inst = Gem::DependencyInstaller.new :domain => :local + inst.install 'b' end assert_equal 'b requires a (>= 0)', e.message end @@ -240,8 +289,43 @@ class TestGemDependencyInstaller < RubyGemTestCase @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data - inst = Gem::DependencyInstaller.new 'a', nil, :domain => :remote - inst.install + inst = Gem::DependencyInstaller.new :domain => :remote + inst.install 'a' + + assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } + end + + def test_install_remote + a1_data = nil + File.open @a1_gem, 'rb' do |fp| + a1_data = fp.read + end + + @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data + + inst = Gem::DependencyInstaller.new + + Dir.chdir @tempdir do + inst.install 'a' + end + + assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } + end + + def test_install_remote_dep + a1_data = nil + File.open @a1_gem, 'rb' do |fp| + a1_data = fp.read + end + + @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data + + inst = Gem::DependencyInstaller.new + + Dir.chdir @tempdir do + dep = Gem::Dependency.new @a1.name, @a1.version + inst.install dep + end assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end @@ -266,8 +350,8 @@ class TestGemDependencyInstaller < RubyGemTestCase @fetcher.data["http://gems.example.com/gems/#{a2_o.full_name}.gem"] = a2_o_data - inst = Gem::DependencyInstaller.new 'a', nil, :domain => :remote - inst.install + inst = Gem::DependencyInstaller.new :domain => :remote + inst.install 'a' assert_equal %w[a-1], inst.installed_gems.map { |s| s.full_name } end @@ -278,8 +362,8 @@ class TestGemDependencyInstaller < RubyGemTestCase inst = nil Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a' - inst.install + inst = Gem::DependencyInstaller.new + inst.install 'a' end assert_equal Gem::SourceIndex.new(@a1.full_name => @a1), @@ -290,13 +374,17 @@ class TestGemDependencyInstaller < RubyGemTestCase if defined? OpenSSL then def test_install_security_policy - FileUtils.mv @a1_gem, @cache_dir - FileUtils.mv @b1_gem, @cache_dir + data = File.open(@a1_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/a-1.gem'] = data + + data = File.open(@b1_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/b-1.gem'] = data + policy = Gem::Security::HighSecurity - inst = Gem::DependencyInstaller.new 'b', nil, :security_policy => policy + inst = Gem::DependencyInstaller.new :security_policy => policy e = assert_raise Gem::Exception do - inst.install + inst.install 'b' end assert_equal 'Unsigned gem', e.message @@ -305,145 +393,48 @@ class TestGemDependencyInstaller < RubyGemTestCase end end - def test_install_wrappers - FileUtils.mv @a1_gem, @cache_dir - inst = Gem::DependencyInstaller.new 'a', :wrappers => true + # Wrappers don't work on mswin + unless win_platform? then + def test_install_no_wrappers + @fetcher.data['http://gems.example.com/gems/a-1.gem'] = read_binary(@a1_gem) - inst.install + inst = Gem::DependencyInstaller.new :wrappers => false + inst.install 'a' - assert_match %r|This file was generated by RubyGems.|, - File.read(File.join(@gemhome, 'bin', 'a_bin')) - end - - def test_install_version - FileUtils.mv @d1_gem, @cache_dir - FileUtils.mv @d2_gem, @cache_dir - inst = Gem::DependencyInstaller.new 'd', '= 1' - - inst.install - - assert_equal %w[d-1], inst.installed_gems.map { |s| s.full_name } - end - - def test_install_version_default - FileUtils.mv @d1_gem, @cache_dir - FileUtils.mv @d2_gem, @cache_dir - inst = Gem::DependencyInstaller.new 'd' - - inst.install - - assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name } - end - - def test_download - a1_data = nil - File.open @a1_gem, 'rb' do |fp| - a1_data = fp.read + assert_no_match(%r|This file was generated by RubyGems.|, + File.read(File.join(@gemhome, 'bin', 'a_bin'))) end - - @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data - - inst = Gem::DependencyInstaller.new 'a' - - a1_cache_gem = File.join(@gemhome, 'cache', "#{@a1.full_name}.gem") - assert_equal a1_cache_gem, inst.download(@a1, 'http://gems.example.com') - - assert File.exist?(a1_cache_gem) - end - - def test_download_cached - FileUtils.mv @a1_gem, @cache_dir - - inst = Gem::DependencyInstaller.new 'a' - - assert_equal File.join(@gemhome, 'cache', "#{@a1.full_name}.gem"), - inst.download(@a1, 'http://gems.example.com') - end - - def test_download_local - FileUtils.mv @a1_gem, @tempdir - local_path = File.join @tempdir, "#{@a1.full_name}.gem" - inst = nil - - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a' - end - - assert_equal File.join(@gemhome, 'cache', "#{@a1.full_name}.gem"), - inst.download(@a1, local_path) end - def test_download_install_dir - a1_data = nil - File.open @a1_gem, 'rb' do |fp| - a1_data = fp.read - end - - @fetcher.data['http://gems.example.com/gems/a-1.gem'] = a1_data - - install_dir = File.join @tempdir, 'more_gems' - - inst = Gem::DependencyInstaller.new 'a', nil, :install_dir => install_dir - - a1_cache_gem = File.join install_dir, 'cache', "#{@a1.full_name}.gem" - assert_equal a1_cache_gem, inst.download(@a1, 'http://gems.example.com') + def test_install_version + data = File.open(@d2_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data - assert File.exist?(a1_cache_gem) - end + data = File.open(@d1_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data - unless win_platform? then # File.chmod doesn't work - def test_download_local_read_only - FileUtils.mv @a1_gem, @tempdir - local_path = File.join @tempdir, "#{@a1.full_name}.gem" - inst = nil - File.chmod 0555, File.join(@gemhome, 'cache') + inst = Gem::DependencyInstaller.new - Dir.chdir @tempdir do - inst = Gem::DependencyInstaller.new 'a' - end + inst.install 'd', '= 1' - assert_equal File.join(@tempdir, "#{@a1.full_name}.gem"), - inst.download(@a1, local_path) - ensure - File.chmod 0755, File.join(@gemhome, 'cache') - end + assert_equal %w[d-1], inst.installed_gems.map { |s| s.full_name } end - 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_install_version_default + data = File.open(@d2_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/d-2.gem'] = data - def test_download_unsupported - inst = Gem::DependencyInstaller.new 'a' + data = File.open(@d1_gem, 'rb') { |f| f.read } + @fetcher.data['http://gems.example.com/gems/d-1.gem'] = data - e = assert_raise Gem::InstallError do - inst.download @a1, 'ftp://gems.rubyforge.org' - end + inst = Gem::DependencyInstaller.new + inst.install 'd' - assert_equal 'unsupported URI scheme ftp', e.message + assert_equal %w[d-2], inst.installed_gems.map { |s| s.full_name } end def test_find_gems_gems_with_sources - inst = Gem::DependencyInstaller.new 'a' + inst = Gem::DependencyInstaller.new dep = Gem::Dependency.new 'b', '>= 0' assert_equal [[@b1, 'http://gems.example.com']], @@ -452,7 +443,7 @@ class TestGemDependencyInstaller < RubyGemTestCase def test_find_gems_with_sources_local FileUtils.mv @a1_gem, @tempdir - inst = Gem::DependencyInstaller.new 'b' + inst = Gem::DependencyInstaller.new dep = Gem::Dependency.new 'a', '>= 0' gems = nil @@ -462,7 +453,7 @@ class TestGemDependencyInstaller < RubyGemTestCase assert_equal 2, gems.length remote = gems.first - assert_equal @a1, remote.first, 'remote spec' + assert_equal 'a-1', remote.first.full_name, 'remote spec' assert_equal 'http://gems.example.com', remote.last, 'remote path' local = gems.last @@ -472,7 +463,9 @@ class TestGemDependencyInstaller < RubyGemTestCase end def test_gather_dependencies - inst = Gem::DependencyInstaller.new 'b' + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'b' + inst.gather_dependencies assert_equal %w[a-1 b-1], inst.gems_to_install.map { |s| s.full_name } end @@ -488,7 +481,9 @@ class TestGemDependencyInstaller < RubyGemTestCase @fetcher.uri = URI.parse 'http://gems.example.com' @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml - inst = Gem::DependencyInstaller.new 'c' + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'c' + inst.gather_dependencies assert_equal %w[b-2 c-1], inst.gems_to_install.map { |s| s.full_name } end @@ -496,14 +491,18 @@ class TestGemDependencyInstaller < RubyGemTestCase def test_gather_dependencies_platform_alternate util_set_arch 'cpu-my_platform1' - inst = Gem::DependencyInstaller.new 'w' + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'w' + inst.gather_dependencies assert_equal %w[x-1-cpu-my_platform-1 w-1], inst.gems_to_install.map { |s| s.full_name } end def test_gather_dependencies_platform_bump - inst = Gem::DependencyInstaller.new 'z' + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'z' + inst.gather_dependencies assert_equal %w[y-1 z-1], inst.gems_to_install.map { |s| s.full_name } end @@ -518,27 +517,11 @@ class TestGemDependencyInstaller < RubyGemTestCase @fetcher.uri = URI.parse 'http://gems.example.com' @fetcher.data['http://gems.example.com/gems/yaml'] = si.to_yaml - inst = Gem::DependencyInstaller.new 'e' + inst = Gem::DependencyInstaller.new + inst.find_spec_by_name_and_version 'e' + inst.gather_dependencies assert_equal %w[d-1 e-1], inst.gems_to_install.map { |s| s.full_name } end - - def util_gem(name, version, &block) - spec = quick_gem(name, version, &block) - - util_build_gem spec - - 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") - - spec.loaded_from = nil - spec.loaded = false - - [spec, cache_file] - end - end -- cgit v1.2.3