2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-05-12 05:41:32 -04:00
|
|
|
require_relative "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
|
2019-06-01 05:45:11 -04:00
|
|
|
@installer = setup_base_installer
|
|
|
|
@user_installer = setup_base_user_installer
|
2013-09-14 04:59:02 -04:00
|
|
|
common_installer_setup
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2008-07-01 08:33:11 -04:00
|
|
|
build_rake_in do
|
|
|
|
use_ui ui do
|
|
|
|
@installer.install
|
2012-11-29 01:52:18 -05:00
|
|
|
@spec = @installer.spec
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@user_installer.install
|
|
|
|
@user_spec = @user_installer.spec
|
2008-07-01 08:33:11 -04:00
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
Gem::Specification.reset
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_initialize_expand_path
|
2019-04-26 07:26:21 -04:00
|
|
|
FileUtils.mkdir_p "foo/bar"
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :install_dir => "foo//bar"
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{foo/bar$}, uninstaller.instance_variable_get(:@gem_home)
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2012-12-08 01:01:49 -05:00
|
|
|
def test_ask_if_ok
|
2013-11-11 19:16:41 -05:00
|
|
|
c = util_spec "c"
|
2012-12-08 01:01:49 -05:00
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new nil
|
|
|
|
|
|
|
|
ok = :junk
|
|
|
|
|
|
|
|
ui = Gem::MockGemUi.new "\n"
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
ok = uninstaller.ask_if_ok c
|
|
|
|
end
|
|
|
|
|
|
|
|
refute ok
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_remove_all
|
|
|
|
uninstaller = Gem::Uninstaller.new nil
|
|
|
|
|
|
|
|
ui = Gem::MockGemUi.new "y\n"
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
uninstaller.remove_all [@spec]
|
|
|
|
end
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_exist @spec.gem_dir
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def test_remove_executables_force_keep
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :executables => false
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
executable = File.join Gem.bindir(@user_spec.base_dir), "executable"
|
2011-03-07 03:44:45 -05:00
|
|
|
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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
executable = File.join Gem.bindir(@user_spec.base_dir), "executable"
|
2011-03-07 03:44:45 -05:00
|
|
|
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"
|
2012-11-29 01:52:18 -05:00
|
|
|
refute File.exist?(exec_path), "exec still exists in user bin dir"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
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"
|
|
|
|
|
2011-07-26 23:33:45 -04:00
|
|
|
assert_equal "Removing foo-executable-bar\n", @ui.output
|
2011-03-07 03:44:45 -05:00
|
|
|
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"
|
2011-05-31 23:45:05 -04:00
|
|
|
refute File.exist?(exec_path), "removed exec from bin dir"
|
2011-03-07 03:44:45 -05:00
|
|
|
|
|
|
|
assert_equal "Removing executable\n", @ui.output
|
|
|
|
ensure
|
|
|
|
Gem::Installer.exec_format = nil
|
|
|
|
end
|
|
|
|
|
2014-01-06 20:19:28 -05:00
|
|
|
def test_remove_not_in_home
|
2019-04-26 07:26:21 -04:00
|
|
|
Dir.mkdir "#{@gemhome}2"
|
2014-01-06 20:19:28 -05:00
|
|
|
uninstaller = Gem::Uninstaller.new nil, :install_dir => "#{@gemhome}2"
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::GemNotInHomeException do
|
2014-01-06 20:19:28 -05:00
|
|
|
use_ui ui do
|
|
|
|
uninstaller.remove @spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expected =
|
|
|
|
"Gem '#{@spec.full_name}' is not installed in directory #{@gemhome}2"
|
|
|
|
|
|
|
|
assert_equal expected, e.message
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist @spec.gem_dir
|
2014-01-06 20:19:28 -05:00
|
|
|
end
|
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
def test_remove_symlinked_gem_home
|
2021-05-10 23:27:07 -04:00
|
|
|
pend "Symlinks not supported or not enabled" unless symlink_supported?
|
2020-04-18 18:50:28 -04:00
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
Dir.mktmpdir("gem_home") do |dir|
|
|
|
|
symlinked_gem_home = "#{dir}/#{File.basename(@gemhome)}"
|
|
|
|
|
|
|
|
FileUtils.ln_s(@gemhome, dir)
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new nil, :install_dir => symlinked_gem_home
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
uninstaller.remove @spec
|
|
|
|
end
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_exist @spec.gem_dir
|
2019-04-26 07:26:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
def test_remove_plugins
|
|
|
|
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
|
|
|
|
io.write "puts __FILE__"
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec.files += %w[lib/rubygems_plugin.rb]
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-01-31 21:14:04 -05:00
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
plugin_path = File.join Gem.plugindir, "a_plugin.rb"
|
2020-01-31 21:14:04 -05:00
|
|
|
assert File.exist?(plugin_path), "plugin not written"
|
|
|
|
|
|
|
|
Gem::Uninstaller.new(nil).remove_plugins @spec
|
|
|
|
|
|
|
|
refute File.exist?(plugin_path), "plugin not removed"
|
|
|
|
end
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
def test_remove_plugins_with_install_dir
|
|
|
|
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
|
|
|
|
io.write "puts __FILE__"
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec.files += %w[lib/rubygems_plugin.rb]
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-03-24 02:39:24 -04:00
|
|
|
|
|
|
|
plugin_path = File.join Gem.plugindir, "a_plugin.rb"
|
|
|
|
assert File.exist?(plugin_path), "plugin not written"
|
|
|
|
|
|
|
|
Dir.mkdir "#{@gemhome}2"
|
|
|
|
Gem::Uninstaller.new(nil, :install_dir => "#{@gemhome}2").remove_plugins @spec
|
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "plugin unintentionally removed"
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
def test_regenerate_plugins_for
|
|
|
|
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
|
|
|
|
io.write "puts __FILE__"
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec.files += %w[lib/rubygems_plugin.rb]
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-01-31 21:14:04 -05:00
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
plugin_path = File.join Gem.plugindir, "a_plugin.rb"
|
2020-01-31 21:14:04 -05:00
|
|
|
assert File.exist?(plugin_path), "plugin not written"
|
|
|
|
|
|
|
|
FileUtils.rm plugin_path
|
2020-03-24 02:39:24 -04:00
|
|
|
Gem::Uninstaller.new(nil).regenerate_plugins_for @spec, Gem.plugindir
|
2020-01-31 21:14:04 -05:00
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "plugin not regenerated"
|
|
|
|
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
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@spec.loaded_from = @spec.loaded_from.gsub @spec.full_name, '\&-legacy'
|
2015-07-01 17:50:14 -04:00
|
|
|
@spec.internal_init # blow out cache. but why did ^^ depend on cache?
|
2008-06-17 18:04:18 -04:00
|
|
|
@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
|
2018-05-30 09:01:35 -04:00
|
|
|
sleep(0.1) if win_platform?
|
2008-09-25 06:13:50 -04:00
|
|
|
assert File.exist?(gem_dir), "gem_dir should exist"
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.post_uninstall do
|
2018-05-30 09:01:35 -04:00
|
|
|
sleep(0.1) if win_platform?
|
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
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
def test_uninstall_default_gem
|
|
|
|
spec = new_default_spec "default", "2"
|
|
|
|
|
|
|
|
install_default_gems spec
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new spec.name, :executables => true
|
|
|
|
|
2019-08-21 14:17:11 -04:00
|
|
|
use_ui @ui do
|
2012-12-19 02:19:10 -05:00
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
|
2019-08-21 14:17:11 -04:00
|
|
|
lines = @ui.output.split("\n")
|
|
|
|
|
|
|
|
assert_equal "Gem default-2 cannot be uninstalled because it is a default gem", lines.shift
|
2012-12-19 02:19:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_uninstall_default_gem_with_same_version
|
|
|
|
default_spec = new_default_spec "default", "2"
|
|
|
|
install_default_gems default_spec
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
spec = util_spec "default", "2"
|
2012-12-19 02:19:10 -05:00
|
|
|
install_gem spec
|
|
|
|
|
|
|
|
Gem::Specification.reset
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new spec.name, :executables => true
|
|
|
|
|
2021-07-08 11:27:50 -04:00
|
|
|
ui = Gem::MockGemUi.new "1\ny\n"
|
|
|
|
use_ui ui do
|
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
expected = "Successfully uninstalled default-2\n" \
|
|
|
|
"There was both a regular copy and a default copy of default-2. The " \
|
|
|
|
"regular copy was successfully uninstalled, but the default copy " \
|
|
|
|
"was left around because default gems can't be removed.\n"
|
|
|
|
assert_equal expected, ui.output
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_exist spec.gem_dir
|
2012-12-19 02:19:10 -05:00
|
|
|
end
|
|
|
|
|
2013-10-15 20:14:16 -04:00
|
|
|
def test_uninstall_extension
|
|
|
|
@spec.extensions << "extconf.rb"
|
|
|
|
write_file File.join(@tempdir, "extconf.rb") do |io|
|
|
|
|
io.write <<-RUBY
|
|
|
|
require 'mkmf'
|
|
|
|
create_makefile '#{@spec.name}'
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec.files += %w[extconf.rb]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
path = Gem::Package.build @spec
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
installer = Gem::Installer.at path, :force => true
|
2013-10-15 20:14:16 -04:00
|
|
|
installer.install
|
|
|
|
end
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist @spec.extension_dir, "sanity check"
|
2013-10-15 20:14:16 -04:00
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
|
|
|
|
uninstaller.uninstall
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_exist @spec.extension_dir
|
2013-10-15 20:14:16 -04:00
|
|
|
end
|
|
|
|
|
2011-07-26 23:33:45 -04:00
|
|
|
def test_uninstall_nonexistent
|
|
|
|
uninstaller = Gem::Uninstaller.new "bogus", :executables => true
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::InstallError do
|
2011-07-26 23:33:45 -04:00
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'gem "bogus" is not installed', e.message
|
|
|
|
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"
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::DependencyRemovalException do
|
2011-03-07 03:44:45 -05:00
|
|
|
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
|
|
|
|
|
2013-09-18 17:29:41 -04:00
|
|
|
def test_uninstall_user_install
|
2011-05-31 23:45:05 -04:00
|
|
|
@user_spec = Gem::Specification.find_by_name "b"
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new(@user_spec.name,
|
2022-09-07 01:13:04 -04:00
|
|
|
:executables => true,
|
2011-05-31 23:45:05 -04:00
|
|
|
:user_install => true)
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
gem_dir = File.join @user_spec.gem_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
Gem.pre_uninstall do
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_exist gem_dir
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
Gem.post_uninstall do
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_exist gem_dir
|
2008-09-25 06:13:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
uninstaller.uninstall
|
|
|
|
|
2020-05-25 08:05:45 -04:00
|
|
|
assert_path_not_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
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_uninstall_wrong_repo
|
2019-04-26 07:26:21 -04:00
|
|
|
Dir.mkdir "#{@gemhome}2"
|
2012-11-29 01:52:18 -05:00
|
|
|
Gem.use_paths "#{@gemhome}2", [@gemhome]
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
e = assert_raise Gem::InstallError do
|
2012-11-29 01:52:18 -05:00
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-MESSAGE.strip
|
|
|
|
#{@spec.name} is not installed in GEM_HOME, try:
|
|
|
|
\tgem uninstall -i #{@gemhome} a
|
|
|
|
MESSAGE
|
|
|
|
|
|
|
|
assert_equal expected, e.message
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_uninstall_selection
|
|
|
|
util_make_gems
|
|
|
|
|
|
|
|
list = Gem::Specification.find_all_by_name "a"
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new "a"
|
|
|
|
|
|
|
|
ui = Gem::MockGemUi.new "1\ny\n"
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
updated_list = Gem::Specification.find_all_by_name("a")
|
|
|
|
assert_equal list.length - 1, updated_list.length
|
|
|
|
|
|
|
|
assert_match " 1. a-1", ui.output
|
|
|
|
assert_match " 2. a-2", ui.output
|
|
|
|
assert_match " 3. a-3.a", ui.output
|
|
|
|
assert_match " 4. All versions", ui.output
|
|
|
|
assert_match "uninstalled a-1", ui.output
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_uninstall_selection_greater_than_one
|
|
|
|
util_make_gems
|
2012-08-21 00:50:18 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
list = Gem::Specification.find_all_by_name("a")
|
|
|
|
|
|
|
|
uninstaller = Gem::Uninstaller.new("a")
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
use_ui Gem::MockGemUi.new("2\ny\n") do
|
2011-05-31 23:45:05 -04:00
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
updated_list = Gem::Specification.find_all_by_name("a")
|
|
|
|
assert_equal list.length - 1, updated_list.length
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_uninstall_prompts_about_broken_deps
|
2019-02-14 07:59:03 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_dependency "q", "= 1"
|
|
|
|
end
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "q", "1"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q")
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{You have requested to uninstall the gem:}, lines.shift
|
2012-11-29 01:52:18 -05:00
|
|
|
lines.shift
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{r-1 depends on q \(= 1\)}, lines.shift
|
|
|
|
assert_match %r{Successfully uninstalled q-1}, lines.last
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2015-01-09 09:20:10 -05:00
|
|
|
def test_uninstall_only_lists_unsatisfied_deps
|
2019-02-14 07:59:03 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_dependency "q", "~> 1.0"
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem "x", "1" do |s|
|
|
|
|
s.add_dependency "q", "= 1.0"
|
|
|
|
end
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "q", "1.0"
|
|
|
|
quick_gem "q", "1.1"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :version => "1.0")
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{You have requested to uninstall the gem:}, lines.shift
|
2012-11-29 01:52:18 -05:00
|
|
|
lines.shift
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{x-1 depends on q \(= 1.0\)}, lines.shift
|
|
|
|
assert_match %r{Successfully uninstalled q-1.0}, lines.last
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
|
|
|
|
2015-01-09 09:20:10 -05:00
|
|
|
def test_uninstall_doesnt_prompt_when_other_gem_satisfies_requirement
|
2019-02-14 07:59:03 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_dependency "q", "~> 1.0"
|
|
|
|
end
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "q", "1.0"
|
|
|
|
quick_gem "q", "1.1"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :version => "1.0")
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
|
|
|
|
assert_equal "Successfully uninstalled q-1.0", lines.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_uninstall_doesnt_prompt_when_removing_a_dev_dep
|
2019-02-14 07:59:03 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_development_dependency "q", "= 1.0"
|
|
|
|
end
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "q", "1.0"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :version => "1.0")
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
|
|
|
|
assert_equal "Successfully uninstalled q-1.0", lines.shift
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def test_uninstall_doesnt_prompt_and_raises_when_abort_on_dependent_set
|
2019-02-14 07:59:03 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_dependency "q", "= 1"
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
quick_gem "q", "1"
|
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :abort_on_dependent => true)
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::DependencyRemovalException do
|
2013-09-14 04:59:02 -04:00
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
def test_uninstall_prompt_includes_dep_type
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "r", "1" do |s|
|
2012-11-29 01:52:18 -05:00
|
|
|
s.add_development_dependency "q", "= 1"
|
|
|
|
end
|
|
|
|
|
2012-12-19 02:19:10 -05:00
|
|
|
quick_gem "q", "1"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :check_dev => true)
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{You have requested to uninstall the gem:}, lines.shift
|
2012-11-29 01:52:18 -05:00
|
|
|
lines.shift
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{r-1 depends on q \(= 1, development\)}, lines.shift
|
|
|
|
assert_match %r{Successfully uninstalled q-1}, lines.last
|
2012-11-29 01:52:18 -05:00
|
|
|
end
|
2018-05-30 09:01:35 -04:00
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
def test_uninstall_prompt_only_lists_the_dependents_that_prevented_uninstallation
|
|
|
|
quick_gem "r", "1" do |s|
|
|
|
|
s.add_development_dependency "q", "= 1"
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem "s", "1" do |s|
|
|
|
|
s.add_dependency "q", "= 1"
|
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem "q", "1"
|
|
|
|
|
|
|
|
un = Gem::Uninstaller.new("q", :check_dev => false)
|
|
|
|
ui = Gem::MockGemUi.new("y\n")
|
|
|
|
|
|
|
|
use_ui ui do
|
|
|
|
un.uninstall
|
|
|
|
end
|
|
|
|
|
|
|
|
lines = ui.output.split("\n")
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{You have requested to uninstall the gem:}, lines.shift
|
2020-01-31 21:14:04 -05:00
|
|
|
lines.shift
|
|
|
|
lines.shift
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{s-1 depends on q \(= 1\)}, lines.shift
|
|
|
|
assert_match %r{Successfully uninstalled q-1}, lines.last
|
2020-01-31 21:14:04 -05:00
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
def test_uninstall_no_permission
|
|
|
|
uninstaller = Gem::Uninstaller.new @spec.name, :executables => true
|
|
|
|
|
|
|
|
stub_rm_r = lambda do |*args|
|
|
|
|
_path = args.shift
|
|
|
|
options = args.shift || Hash.new
|
|
|
|
# Uninstaller calls a method in RDoc which also calls FileUtils.rm_rf which
|
|
|
|
# is an alias for FileUtils#rm_r, so skip if we're using the force option
|
|
|
|
raise Errno::EPERM unless options[:force]
|
|
|
|
end
|
|
|
|
|
|
|
|
FileUtils.stub :rm_r, stub_rm_r do
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::UninstallError do
|
2018-05-30 09:01:35 -04:00
|
|
|
uninstaller.uninstall
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2020-01-31 21:14:04 -05:00
|
|
|
def test_uninstall_keeps_plugins_up_to_date
|
|
|
|
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
|
|
|
|
io.write "puts __FILE__"
|
|
|
|
end
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
plugin_path = File.join Gem.plugindir, "a_plugin.rb"
|
2020-01-31 21:14:04 -05:00
|
|
|
|
|
|
|
@spec.version = "1"
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-01-31 21:14:04 -05:00
|
|
|
|
|
|
|
refute File.exist?(plugin_path), "version without plugin installed, but plugin written"
|
|
|
|
|
|
|
|
@spec.files += %w[lib/rubygems_plugin.rb]
|
|
|
|
@spec.version = "2"
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-01-31 21:14:04 -05:00
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "version with plugin installed, but plugin not written"
|
|
|
|
assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), "written plugin has incorrect content"
|
|
|
|
|
|
|
|
@spec.version = "3"
|
2020-12-08 02:33:39 -05:00
|
|
|
Gem::Installer.at(Gem::Package.build(@spec), :force => true).install
|
2020-01-31 21:14:04 -05:00
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "version with plugin installed, but plugin removed"
|
|
|
|
assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), "old version installed, but plugin updated"
|
|
|
|
|
|
|
|
Gem::Uninstaller.new("a", :version => "1", :executables => true).uninstall
|
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "plugin removed when old version uninstalled"
|
|
|
|
assert_match %r{\Arequire.*a-3/lib/rubygems_plugin\.rb}, File.read(plugin_path), "old version uninstalled, but plugin updated"
|
|
|
|
|
|
|
|
Gem::Uninstaller.new("a", version: "3", :executables => true).uninstall
|
|
|
|
|
|
|
|
assert File.exist?(plugin_path), "plugin removed when old version uninstalled and another version with plugin still present"
|
|
|
|
assert_match %r{\Arequire.*a-2/lib/rubygems_plugin\.rb}, File.read(plugin_path), "latest version uninstalled, but plugin not updated to previous version"
|
|
|
|
|
|
|
|
Gem::Uninstaller.new("a", version: "2", :executables => true).uninstall
|
|
|
|
|
|
|
|
refute File.exist?(plugin_path), "last version uninstalled, but plugin still present"
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|