diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 23791313c8..214ba53a88 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -178,7 +178,7 @@ class Gem::Uninstaller # Removes installed executables and batch files (windows only) for +spec+. def remove_executables(spec) - return if spec.executables.empty? + return if spec.executables.empty? || default_spec_matches?(spec) executables = spec.executables.clone diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index e47f2fa837..5b6ba999a4 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -816,9 +816,15 @@ class Gem::TestCase < Test::Unit::TestCase Gem::Specification.unresolved_deps.values.map(&:to_s).sort end - def new_default_spec(name, version, deps = nil, *files) + def new_default_spec(name, version, deps = nil, *files, executable: false) spec = util_spec name, version, deps + if executable + spec.executables = %w[executable] + + write_file File.join(@tempdir, "bin", "executable") + end + spec.loaded_from = File.join(@gemhome, "specifications", "default", spec.spec_name) spec.files = files diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 66885395d8..81fadfcb99 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -81,6 +81,35 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase assert_equal "Successfully uninstalled z-2", output.shift end + def test_execute_does_not_remove_default_gem_executables + z_1_default = new_default_spec "z", "1", executable: true + install_default_gems z_1_default + + z_1, = util_gem "z", "1" do |spec| + util_make_exec spec + end + install_gem z_1, force: true + + Gem::Specification.reset + + @cmd.options[:all] = true + @cmd.options[:force] = true + @cmd.options[:executables] = true + @cmd.options[:args] = %w[z] + + use_ui @ui do + @cmd.execute + end + + assert File.exist? File.join(@gemhome, "bin", "executable") + + output = @ui.output.split "\n" + + refute_includes output, "Removing executable" + assert_equal "Successfully uninstalled z-1", output.shift + assert_equal "There was both a regular copy and a default copy of z-1. The regular copy was successfully uninstalled, but the default copy was left around because default gems can't be removed.", output.shift + end + def test_execute_dependency_order initial_install