diff options
Diffstat (limited to 'test/rubygems/test_gem_uninstaller.rb')
-rw-r--r-- | test/rubygems/test_gem_uninstaller.rb | 159 |
1 files changed, 122 insertions, 37 deletions
diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index dfa01768bc..aa5ab0ed67 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -25,7 +25,7 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_initialize_expand_path FileUtils.mkdir_p "foo/bar" - uninstaller = Gem::Uninstaller.new nil, :install_dir => "foo//bar" + uninstaller = Gem::Uninstaller.new nil, install_dir: "foo//bar" assert_match %r{foo/bar$}, uninstaller.instance_variable_get(:@gem_home) end @@ -59,7 +59,7 @@ class TestGemUninstaller < Gem::InstallerTestCase end def test_remove_executables_force_keep - uninstaller = Gem::Uninstaller.new nil, :executables => false + uninstaller = Gem::Uninstaller.new nil, executables: false executable = File.join Gem.bindir(@user_spec.base_dir), "executable" assert File.exist?(executable), "executable not written" @@ -74,7 +74,7 @@ class TestGemUninstaller < Gem::InstallerTestCase end def test_remove_executables_force_remove - uninstaller = Gem::Uninstaller.new nil, :executables => true + uninstaller = Gem::Uninstaller.new nil, executables: true executable = File.join Gem.bindir(@user_spec.base_dir), "executable" assert File.exist?(executable), "executable not written" @@ -89,7 +89,7 @@ class TestGemUninstaller < Gem::InstallerTestCase end def test_remove_executables_user - uninstaller = Gem::Uninstaller.new nil, :executables => true + uninstaller = Gem::Uninstaller.new nil, executables: true use_ui @ui do uninstaller.remove_executables @user_spec @@ -104,7 +104,7 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_user_format Gem::Installer.exec_format = "foo-%s-bar" - uninstaller = Gem::Uninstaller.new nil, :executables => true, :format_executable => true + uninstaller = Gem::Uninstaller.new nil, executables: true, format_executable: true use_ui @ui do uninstaller.remove_executables @user_spec @@ -121,7 +121,7 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_executables_user_format_disabled Gem::Installer.exec_format = "foo-%s-bar" - uninstaller = Gem::Uninstaller.new nil, :executables => true + uninstaller = Gem::Uninstaller.new nil, executables: true use_ui @ui do uninstaller.remove_executables @user_spec @@ -137,7 +137,7 @@ class TestGemUninstaller < Gem::InstallerTestCase def test_remove_not_in_home Dir.mkdir "#{@gemhome}2" - uninstaller = Gem::Uninstaller.new nil, :install_dir => "#{@gemhome}2" + uninstaller = Gem::Uninstaller.new nil, install_dir: "#{@gemhome}2" e = assert_raise Gem::GemNotInHomeException do use_ui ui do @@ -161,7 +161,7 @@ class TestGemUninstaller < Gem::InstallerTestCase FileUtils.ln_s(@gemhome, dir) - uninstaller = Gem::Uninstaller.new nil, :install_dir => symlinked_gem_home + uninstaller = Gem::Uninstaller.new nil, install_dir: symlinked_gem_home use_ui ui do uninstaller.remove @spec @@ -178,7 +178,7 @@ class TestGemUninstaller < Gem::InstallerTestCase @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + Gem::Installer.at(Gem::Package.build(@spec), force: true).install plugin_path = File.join Gem.plugindir, "a_plugin.rb" assert File.exist?(plugin_path), "plugin not written" @@ -188,22 +188,81 @@ class TestGemUninstaller < Gem::InstallerTestCase refute File.exist?(plugin_path), "plugin not removed" end - def test_remove_plugins_with_install_dir + def test_uninstall_with_install_dir_removes_plugins write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io| io.write "# do nothing" end @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + package = Gem::Package.build(@spec) + + Gem::Installer.at(package, force: true).install 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 + install_dir = "#{@gemhome}2" + + Gem::Installer.at(package, force: true, install_dir: install_dir).install + + install_dir_plugin_path = File.join install_dir, "plugins/a_plugin.rb" + assert File.exist?(install_dir_plugin_path), "plugin not written" + + Gem::Specification.dirs = [install_dir] + Gem::Uninstaller.new(@spec.name, executables: true, install_dir: install_dir).uninstall assert File.exist?(plugin_path), "plugin unintentionally removed" + refute File.exist?(install_dir_plugin_path), "plugin not removed" + end + + def test_uninstall_with_install_dir_regenerates_plugins + write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io| + io.write "# do nothing" + end + + @spec.files += %w[lib/rubygems_plugin.rb] + + install_dir = "#{@gemhome}2" + + package = Gem::Package.build(@spec) + + spec_v9 = @spec.dup + spec_v9.version = "9" + package_v9 = Gem::Package.build(spec_v9) + + Gem::Installer.at(package, force: true, install_dir: install_dir).install + Gem::Installer.at(package_v9, force: true, install_dir: install_dir).install + + install_dir_plugin_path = File.join install_dir, "plugins/a_plugin.rb" + assert File.exist?(install_dir_plugin_path), "plugin not written" + + Gem::Specification.dirs = [install_dir] + Gem::Uninstaller.new(@spec.name, version: "9", executables: true, install_dir: install_dir).uninstall + assert File.exist?(install_dir_plugin_path), "plugin unintentionally removed" + + Gem::Specification.dirs = [install_dir] + Gem::Uninstaller.new(@spec.name, executables: true, install_dir: install_dir).uninstall + refute File.exist?(install_dir_plugin_path), "plugin not removed" + end + + def test_remove_plugins_user_installed + write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io| + io.write "# do nothing" + end + + @spec.files += %w[lib/rubygems_plugin.rb] + + Gem::Installer.at(Gem::Package.build(@spec), force: true, user_install: true).install + + plugin_path = File.join Gem.user_dir, "plugins/a_plugin.rb" + assert File.exist?(plugin_path), "plugin not written" + + Gem::Specification.dirs = [Gem.dir, Gem.user_dir] + + Gem::Uninstaller.new(@spec.name, executables: true, force: true, user_install: true).uninstall + + refute File.exist?(plugin_path), "plugin not removed" end def test_regenerate_plugins_for @@ -213,7 +272,7 @@ class TestGemUninstaller < Gem::InstallerTestCase @spec.files += %w[lib/rubygems_plugin.rb] - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + Gem::Installer.at(Gem::Package.build(@spec), force: true).install plugin_path = File.join Gem.plugindir, "a_plugin.rb" assert File.exist?(plugin_path), "plugin not written" @@ -247,7 +306,7 @@ class TestGemUninstaller < Gem::InstallerTestCase end def test_uninstall - uninstaller = Gem::Uninstaller.new @spec.name, :executables => true + uninstaller = Gem::Uninstaller.new @spec.name, executables: true gem_dir = File.join @gemhome, "gems", @spec.full_name @@ -274,7 +333,7 @@ class TestGemUninstaller < Gem::InstallerTestCase install_default_gems spec - uninstaller = Gem::Uninstaller.new spec.name, :executables => true + uninstaller = Gem::Uninstaller.new spec.name, executables: true use_ui @ui do uninstaller.uninstall @@ -294,7 +353,7 @@ class TestGemUninstaller < Gem::InstallerTestCase Gem::Specification.reset - uninstaller = Gem::Uninstaller.new spec.name, :executables => true + uninstaller = Gem::Uninstaller.new spec.name, executables: true ui = Gem::MockGemUi.new "1\ny\n" use_ui ui do @@ -322,20 +381,20 @@ create_makefile '#{@spec.name}' use_ui @ui do path = Gem::Package.build @spec - installer = Gem::Installer.at path, :force => true + installer = Gem::Installer.at path, force: true installer.install end assert_path_exist @spec.extension_dir, "sanity check" - uninstaller = Gem::Uninstaller.new @spec.name, :executables => true + uninstaller = Gem::Uninstaller.new @spec.name, executables: true uninstaller.uninstall assert_path_not_exist @spec.extension_dir end def test_uninstall_nonexistent - uninstaller = Gem::Uninstaller.new "bogus", :executables => true + uninstaller = Gem::Uninstaller.new "bogus", executables: true e = assert_raise Gem::InstallError do uninstaller.uninstall @@ -370,11 +429,11 @@ create_makefile '#{@spec.name}' end def test_uninstall_user_install - @user_spec = Gem::Specification.find_by_name "b" + Gem::Specification.dirs = [Gem.user_dir] uninstaller = Gem::Uninstaller.new(@user_spec.name, - :executables => true, - :user_install => true) + executables: true, + user_install: true) gem_dir = File.join @user_spec.gem_dir @@ -394,11 +453,37 @@ create_makefile '#{@spec.name}' assert_same uninstaller, @post_uninstall_hook_arg end + def test_uninstall_user_install_with_symlinked_home + pend "Symlinks not supported or not enabled" unless symlink_supported? + + Gem::Specification.dirs = [Gem.user_dir] + + symlinked_home = File.join(@tempdir, "new-home") + FileUtils.ln_s(Gem.user_home, symlinked_home) + + ENV["HOME"] = symlinked_home + Gem.instance_variable_set(:@user_home, nil) + Gem.instance_variable_set(:@data_home, nil) + + uninstaller = Gem::Uninstaller.new(@user_spec.name, + executables: true, + user_install: true, + force: true) + + gem_dir = File.join @user_spec.gem_dir + + assert_path_exist gem_dir + + uninstaller.uninstall + + assert_path_not_exist gem_dir + end + def test_uninstall_wrong_repo Dir.mkdir "#{@gemhome}2" Gem.use_paths "#{@gemhome}2", [@gemhome] - uninstaller = Gem::Uninstaller.new @spec.name, :executables => true + uninstaller = Gem::Uninstaller.new @spec.name, executables: true e = assert_raise Gem::InstallError do uninstaller.uninstall @@ -487,7 +572,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1.0" quick_gem "q", "1.1" - un = Gem::Uninstaller.new("q", :version => "1.0") + un = Gem::Uninstaller.new("q", version: "1.0") ui = Gem::MockGemUi.new("y\n") use_ui ui do @@ -513,7 +598,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1.0" quick_gem "q", "1.1" - un = Gem::Uninstaller.new("q", :version => "1.0") + un = Gem::Uninstaller.new("q", version: "1.0") ui = Gem::MockGemUi.new("y\n") use_ui ui do @@ -532,7 +617,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1.0" - un = Gem::Uninstaller.new("q", :version => "1.0") + un = Gem::Uninstaller.new("q", version: "1.0") ui = Gem::MockGemUi.new("y\n") use_ui ui do @@ -551,7 +636,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1" - un = Gem::Uninstaller.new("q", :abort_on_dependent => true) + un = Gem::Uninstaller.new("q", abort_on_dependent: true) ui = Gem::MockGemUi.new("y\n") assert_raise Gem::DependencyRemovalException do @@ -568,7 +653,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1" - un = Gem::Uninstaller.new("q", :check_dev => true) + un = Gem::Uninstaller.new("q", check_dev: true) ui = Gem::MockGemUi.new("y\n") use_ui ui do @@ -597,7 +682,7 @@ create_makefile '#{@spec.name}' quick_gem "q", "1" - un = Gem::Uninstaller.new("q", :check_dev => false) + un = Gem::Uninstaller.new("q", check_dev: false) ui = Gem::MockGemUi.new("y\n") use_ui ui do @@ -616,7 +701,7 @@ create_makefile '#{@spec.name}' end def test_uninstall_no_permission - uninstaller = Gem::Uninstaller.new @spec.name, :executables => true + uninstaller = Gem::Uninstaller.new @spec.name, executables: true stub_rm_r = lambda do |*args| _path = args.shift @@ -641,34 +726,34 @@ create_makefile '#{@spec.name}' plugin_path = File.join Gem.plugindir, "a_plugin.rb" @spec.version = "1" - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + Gem::Installer.at(Gem::Package.build(@spec), force: true).install refute File.exist?(plugin_path), "version without plugin installed, but plugin written" @spec.files += %w[lib/rubygems_plugin.rb] @spec.version = "2" - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + Gem::Installer.at(Gem::Package.build(@spec), force: true).install 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" - Gem::Installer.at(Gem::Package.build(@spec), :force => true).install + Gem::Installer.at(Gem::Package.build(@spec), force: true).install 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 + 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 + 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 + Gem::Uninstaller.new("a", version: "2", executables: true).uninstall refute File.exist?(plugin_path), "last version uninstalled, but plugin still present" end |