diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-23 00:35:09 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-23 00:35:09 +0000 |
commit | 6fe32d72667945605ef710395706e04491bfd86a (patch) | |
tree | 7fe4b8f779ff75067b45f48502864fb05787cee7 /test/rubygems/test_gem_installer.rb | |
parent | c47c095b9740e7c19d6fdca29ab661c1089221d4 (diff) | |
download | ruby-6fe32d72667945605ef710395706e04491bfd86a.tar.gz |
* lib/rubygems/commands/check_command.rb: Added --doctor and --dry-run
options to clean up after failed uninstallation.
* test/rubygems/test_gem_commands_check_command.rb: Test for above.
* lib/rubygems/commands/push_command.rb: Allow pushes from RubyGems
2.0.0.preview3
* lib/rubygems/commands/update_command.rb: Use Gem.ruby_version
* lib/rubygems/dependency.rb: Update style.
* lib/rubygems/installer.rb: Ensure installed gem specifications will
be useable. Refactor.
* test/rubygems/test_gem_installer.rb: ditto.
* lib/rubygems/validator.rb: Fixed bug with unreadable files.
* lib/rubygems.rb: Fixed broken methods.
* test/rubygems/test_gem.rb: Test for above.
* test/rubygems/test_gem_commands_push_command.rb: Fixed overridden
Gem.latest_rubygems_version
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rubygems/test_gem_installer.rb')
-rw-r--r-- | test/rubygems/test_gem_installer.rb | 209 |
1 files changed, 132 insertions, 77 deletions
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 0683001f33..98f1878dfb 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -245,6 +245,34 @@ load Gem.bin_path('a', 'executable', version) assert_equal 'a requires b (> 2)', e.message end + def test_ensure_loadable_spec + a, a_gem = util_gem 'a', 2 do |s| + s.add_dependency 'garbage ~> 5' + end + + installer = Gem::Installer.new a_gem + + e = assert_raises Gem::InstallError do + installer.ensure_loadable_spec + end + + assert_equal "The specification for #{a.full_name} is corrupt " + + "(SyntaxError)", e.message + end + + def test_ensure_loadable_spec_security_policy + a, a_gem = util_gem 'a', 2 do |s| + s.add_dependency 'garbage ~> 5' + end + + policy = Gem::Security::HighSecurity + installer = Gem::Installer.new a_gem, :security_policy => policy + + assert_raises Gem::Security::Exception do + installer.ensure_loadable_spec + end + end + def test_extract_files @installer.extract_files @@ -818,45 +846,6 @@ load Gem.bin_path('a', 'executable', version) "code.rb from prior install of same gem shouldn't remain here") end - def test_install_check_dependencies - @spec.add_dependency 'b', '> 5' - util_setup_gem - - use_ui @ui do - assert_raises Gem::InstallError do - @installer.install - end - end - end - - def test_install_check_dependencies_install_dir - gemhome2 = "#{@gemhome}2" - @spec.add_dependency 'd' - - quick_gem 'd', 2 - - FileUtils.mv @gemhome, gemhome2 - - # Don't leak any already activated gems into the installer, require - # that it work everything out on it's own. - Gem::Specification.reset - - util_setup_gem - - @installer = Gem::Installer.new @gem, :install_dir => gemhome2 - - gem_home = Gem.dir - - build_rake_in do - use_ui @ui do - @installer.install - end - end - - assert File.exist?(File.join(gemhome2, 'gems', @spec.full_name)) - assert_equal gem_home, Gem.dir - end - def test_install_force use_ui @ui do installer = Gem::Installer.new old_ruby_required, :force => true @@ -867,30 +856,6 @@ load Gem.bin_path('a', 'executable', version) assert File.exist?(gem_dir) end - def test_install_ignore_dependencies - Dir.mkdir util_inst_bindir - @spec.add_dependency 'b', '> 5' - util_setup_gem - @installer.ignore_dependencies = true - - build_rake_in do - use_ui @ui do - assert_equal @spec, @installer.install - end - end - - gemdir = File.join @gemhome, 'gems', @spec.full_name - assert File.exist?(gemdir) - - exe = File.join(gemdir, 'bin', 'executable') - assert File.exist?(exe) - exe_mode = File.stat(exe).mode & 0111 - assert_equal 0111, exe_mode, "0%o" % exe_mode unless win_platform? - assert File.exist?(File.join(gemdir, 'lib', 'code.rb')) - - assert File.exist?(File.join(@gemhome, 'specifications', @spec.spec_name)) - end - def test_install_missing_dirs FileUtils.rm_f File.join(Gem.dir, 'cache') FileUtils.rm_f File.join(Gem.dir, 'docs') @@ -999,18 +964,78 @@ load Gem.bin_path('a', 'executable', version) assert_match %r|I am a shiny gem!|, @ui.output end - def test_install_wrong_ruby_version + def test_installation_satisfies_dependency_eh + quick_spec 'a' + + dep = Gem::Dependency.new 'a', '>= 2' + assert @installer.installation_satisfies_dependency?(dep) + + dep = Gem::Dependency.new 'a', '> 2' + refute @installer.installation_satisfies_dependency?(dep) + end + + def test_pre_install_checks_dependencies + @spec.add_dependency 'b', '> 5' + util_setup_gem + + use_ui @ui do + assert_raises Gem::InstallError do + @installer.install + end + end + end + + def test_pre_install_checks_dependencies_ignore + @spec.add_dependency 'b', '> 5' + @installer.ignore_dependencies = true + + build_rake_in do + use_ui @ui do + assert @installer.pre_install_checks + end + end + end + + def test_pre_install_checks_dependencies_install_dir + gemhome2 = "#{@gemhome}2" + @spec.add_dependency 'd' + + quick_gem 'd', 2 + + gem = File.join @gemhome, @spec.file_name + + FileUtils.mv @gemhome, gemhome2 + FileUtils.mkdir @gemhome + + FileUtils.mv File.join(gemhome2, 'cache', @spec.file_name), gem + + # Don't leak any already activated gems into the installer, require + # that it work everything out on it's own. + Gem::Specification.reset + + installer = Gem::Installer.new gem, :install_dir => gemhome2 + + gem_home = Gem.dir + + build_rake_in do + use_ui @ui do + assert installer.pre_install_checks + end + end + end + + def test_pre_install_checks_ruby_version use_ui @ui do installer = Gem::Installer.new old_ruby_required e = assert_raises Gem::InstallError do - installer.install + installer.pre_install_checks end assert_equal 'old_ruby_required requires Ruby version = 1.4.6.', e.message end end - def test_install_wrong_rubygems_version + def test_pre_install_checks_wrong_rubygems_version spec = quick_spec 'old_rubygems_required', '1' do |s| s.required_rubygems_version = '< 0' end @@ -1022,23 +1047,13 @@ load Gem.bin_path('a', 'executable', version) use_ui @ui do @installer = Gem::Installer.new gem e = assert_raises Gem::InstallError do - @installer.install + @installer.pre_install_checks end assert_equal 'old_rubygems_required requires RubyGems version < 0. ' + "Try 'gem update --system' to update RubyGems itself.", e.message end end - def test_installation_satisfies_dependency_eh - quick_spec 'a' - - dep = Gem::Dependency.new 'a', '>= 2' - assert @installer.installation_satisfies_dependency?(dep) - - dep = Gem::Dependency.new 'a', '> 2' - refute @installer.installation_satisfies_dependency?(dep) - end - def test_shebang util_make_exec @spec, "#!/usr/bin/ruby" @@ -1190,6 +1205,46 @@ load Gem.bin_path('a', 'executable', version) assert File.exist?(File.join(dest, 'bin', 'executable')) end + def test_write_build_args + refute_path_exists @spec.build_info_file + + @installer.build_args = %w[ + --with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4 + ] + + @installer.write_build_info_file + + assert_path_exists @spec.build_info_file + + expected = "--with-libyaml-dir\n/usr/local/Cellar/libyaml/0.1.4\n" + + assert_equal expected, File.read(@spec.build_info_file) + end + + def test_write_build_args_empty + refute_path_exists @spec.build_info_file + + @installer.write_build_info_file + + refute_path_exists @spec.build_info_file + end + + def test_write_cache_file + cache_file = File.join @gemhome, 'cache', @spec.file_name + gem = File.join @gemhome, @spec.file_name + + FileUtils.mv cache_file, gem + refute_path_exists cache_file + + installer = Gem::Installer.new gem + installer.spec = @spec + installer.gem_home = @gemhome + + installer.write_cache_file + + assert_path_exists cache_file + end + def test_write_spec FileUtils.rm @spec.spec_file refute File.exist?(@spec.spec_file) |