2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/installer_test_case'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/uninstaller'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemUninstaller < Gem::InstallerTestCase
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
@user_spec.executables = ["executable"]
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
# HACK util_make_exec
|
|
|
|
user_bin_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name, 'bin'
|
|
|
|
FileUtils.mkdir_p user_bin_dir
|
2011-03-07 03:44:45 -05:00
|
|
|
exec_path = File.join user_bin_dir, "executable"
|
2011-01-28 18:46:47 -05:00
|
|
|
open exec_path, 'w' do |f|
|
2009-06-09 17:38:59 -04:00
|
|
|
f.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
|
|
|
user_bin_dir = File.join Gem.user_dir, 'bin'
|
|
|
|
FileUtils.mkdir_p user_bin_dir
|
2011-03-07 03:44:45 -05:00
|
|
|
exec_path = File.join user_bin_dir, "executable"
|
2011-01-28 18:46:47 -05:00
|
|
|
open exec_path, 'w' do |f|
|
2009-06-09 17:38:59 -04:00
|
|
|
f.puts "#!/usr/bin/ruby"
|
|
|
|
end
|
|
|
|
|
2008-07-01 08:33:11 -04:00
|
|
|
build_rake_in do
|
|
|
|
use_ui ui do
|
|
|
|
@installer.install
|
2009-06-09 17:38:59 -04:00
|
|
|
@user_installer.install
|
|
|
|
Gem::Uninstaller.new(@user_spec.name, :executables => false).uninstall
|
2008-07-01 08:33:11 -04:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_initialize_expand_path
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :install_dir => '/foo//bar'
|
|
|
|
|
|
|
|
assert_match %r|/foo/bar$|, uninstaller.instance_variable_get(:@gem_home)
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def test_remove_executables_force_keep
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => false
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
executable = File.join Gem.user_dir, 'bin', 'executable'
|
|
|
|
assert File.exist?(executable), 'executable not written'
|
2011-01-28 18:46:47 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_ui @ui do
|
2011-01-28 18:46:47 -05:00
|
|
|
uninstaller.remove_executables @user_spec
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
assert File.exist? executable
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
assert_equal "Executables and scripts will remain installed.\n", @ui.output
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_executables_force_remove
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => true
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
executable = File.join Gem.user_dir, 'bin', 'executable'
|
|
|
|
assert File.exist?(executable), 'executable not written'
|
2011-01-28 18:46:47 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_ui @ui do
|
2011-01-28 18:46:47 -05:00
|
|
|
uninstaller.remove_executables @user_spec
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
assert_equal "Removing executable\n", @ui.output
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
refute File.exist? executable
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_remove_executables_user
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => true
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
uninstaller.remove_executables @user_spec
|
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
exec_path = File.join Gem.user_dir, 'bin', 'executable'
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
assert_equal "Removing executable\n", @ui.output
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
def test_remove_executables_user_format
|
|
|
|
Gem::Installer.exec_format = 'foo-%s-bar'
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => true, :format_executable => true
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
uninstaller.remove_executables @user_spec
|
|
|
|
end
|
|
|
|
|
|
|
|
exec_path = File.join Gem.user_dir, 'bin', 'foo-executable-bar'
|
|
|
|
assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
|
|
|
|
|
|
|
|
assert_equal "Removing executable\n", @ui.output
|
|
|
|
ensure
|
|
|
|
Gem::Installer.exec_format = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_executables_user_format_disabled
|
|
|
|
Gem::Installer.exec_format = 'foo-%s-bar'
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => true
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
uninstaller.remove_executables @user_spec
|
|
|
|
end
|
|
|
|
|
|
|
|
exec_path = File.join Gem.user_dir, 'bin', 'executable'
|
|
|
|
assert_equal false, File.exist?(exec_path), 'removed exec from bin dir'
|
|
|
|
|
|
|
|
assert_equal "Removing executable\n", @ui.output
|
|
|
|
ensure
|
|
|
|
Gem::Installer.exec_format = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_path_ok_eh
|
|
|
|
uninstaller = Gem::Uninstaller.new nil
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_path_ok_eh_legacy
|
|
|
|
uninstaller = Gem::Uninstaller.new nil
|
|
|
|
|
|
|
|
@spec.loaded_from.gsub! @spec.full_name, '\&-legacy'
|
|
|
|
@spec.platform = 'legacy'
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal true, uninstaller.path_ok?(@gemhome, @spec)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_path_ok_eh_user
|
|
|
|
uninstaller = Gem::Uninstaller.new nil
|
|
|
|
|
|
|
|
assert_equal true, uninstaller.path_ok?(Gem.user_dir, @user_spec)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
def test_uninstall
|
|
|
|
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
|
|
|
|
|
|
|
|
gem_dir = File.join @gemhome, 'gems', @spec.full_name
|
|
|
|
|
|
|
|
Gem.pre_uninstall do
|
|
|
|
assert File.exist?(gem_dir), 'gem_dir should exist'
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.post_uninstall do
|
2009-06-09 17:38:59 -04:00
|
|
|
refute File.exist?(gem_dir), 'gem_dir should not exist'
|
|
|
|
end
|
|
|
|
|
|
|
|
uninstaller.uninstall
|
|
|
|
|
|
|
|
refute File.exist?(gem_dir)
|
|
|
|
|
|
|
|
assert_same uninstaller, @pre_uninstall_hook_arg
|
|
|
|
assert_same uninstaller, @post_uninstall_hook_arg
|
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
def test_uninstall_not_ok
|
|
|
|
quick_gem 'z' do |s|
|
|
|
|
s.add_runtime_dependency @spec.name
|
|
|
|
end
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new @spec.name
|
|
|
|
|
|
|
|
gem_dir = File.join @gemhome, 'gems', @spec.full_name
|
|
|
|
executable = File.join @gemhome, 'bin', 'executable'
|
|
|
|
|
|
|
|
assert File.exist?(gem_dir), 'gem_dir must exist'
|
|
|
|
assert File.exist?(executable), 'executable must exist'
|
|
|
|
|
|
|
|
ui = Gem::MockGemUi.new "n\n"
|
|
|
|
|
|
|
|
assert_raises Gem::DependencyRemovalException do
|
|
|
|
use_ui ui do
|
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert File.exist?(gem_dir), 'gem_dir must still exist'
|
|
|
|
assert File.exist?(executable), 'executable must still exist'
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_uninstall_user
|
|
|
|
uninstaller = Gem::Uninstaller.new @user_spec.name, :executables => true,
|
|
|
|
:user_install => true
|
|
|
|
|
|
|
|
gem_dir = File.join Gem.user_dir, 'gems', @user_spec.full_name
|
|
|
|
|
|
|
|
Gem.pre_uninstall do
|
|
|
|
assert File.exist?(gem_dir), 'gem_dir should exist'
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.post_uninstall do
|
|
|
|
refute File.exist?(gem_dir), 'gem_dir should not exist'
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
uninstaller.uninstall
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
refute File.exist?(gem_dir)
|
2008-09-25 06:13:50 -04:00
|
|
|
|
|
|
|
assert_same uninstaller, @pre_uninstall_hook_arg
|
|
|
|
assert_same uninstaller, @post_uninstall_hook_arg
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|