Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Uninstaller command --force option, which enables force all and force…

… ignore deps.

Two new test gems, x, and dep_x. dep_x depends on x.
Tests for the above.
  • Loading branch information...
commit 2786a40b71f1e2711fb0ba5d7e0cc41591c77fa5 1 parent 17833d9
Erik Hollensbe authored
View
5 lib/rubygems/commands/uninstall_command.rb
@@ -54,6 +54,11 @@ def initialize
options[:format_executable] = value
end
+ add_option('--[no-]force',
+ 'Uninstall all gems according to name, regardless of dependencies upon it.') do |value, options|
+ options[:force] = value
+ end
+
add_version_option
add_platform_option
end
View
10 lib/rubygems/test_case.rb
@@ -578,6 +578,12 @@ def util_make_gems(prerelease = false)
@a_evil9 = quick_gem('a_evil', '9', &init)
@b2 = quick_gem('b', '2', &init)
@c1_2 = quick_gem('c', '1.2', &init)
+ @x = quick_gem('x', '1', &init)
+ @dep_x = quick_gem('dep_x', '1') do |s|
+ s.files = %w[lib/code.rb]
+ s.require_paths = %w[lib]
+ s.add_dependency 'x', '>= 1'
+ end
@pl1 = quick_gem 'pl', '1' do |s| # l for legacy
s.files = %w[lib/code.rb]
@@ -598,8 +604,10 @@ def util_make_gems(prerelease = false)
write_file File.join(*%W[gems #{@b2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@c1_2.original_name} lib code.rb])
write_file File.join(*%W[gems #{@pl1.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@x.original_name} lib code.rb])
+ write_file File.join(*%W[gems #{@dep_x.original_name} lib code.rb])
- [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].each do |spec|
+ [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1, @x, @dep_x].each do |spec|
util_build_gem spec
end
View
9 lib/rubygems/uninstaller.rb
@@ -51,6 +51,11 @@ def initialize(gem, options = {})
@bin_dir = options[:bin_dir]
@format_executable = options[:format_executable]
+ if options[:force]
+ @force_all = true
+ @force_ignore = true
+ end
+
# only add user directory if install_dir is not set
@user_install = false
@user_install = options[:user_install] unless options[:install_dir]
@@ -72,7 +77,7 @@ def uninstall
if list.empty? then
raise Gem::InstallError, "cannot uninstall, check `gem list -d #{@gem}`"
- elsif list.size > 1 and @force_all then
+ elsif @force_all
remove_all list
elsif list.size > 1 then
@@ -98,7 +103,7 @@ def uninstall
def uninstall_gem(spec)
@spec = spec
-
+
unless dependencies_ok? spec
unless ask_if_ok(spec)
raise Gem::DependencyRemovalException,
View
5 test/rubygems/test_gem_commands_dependency_command.rb
@@ -51,8 +51,13 @@ def test_execute_no_args
Gem c-1.2
+Gem dep_x-1
+ x (>= 1)
+
Gem pl-1-x86-linux
+Gem x-1
+
EOF
assert_equal expected, @ui.output
View
61 test/rubygems/test_gem_commands_uninstall_command.rb
@@ -13,7 +13,6 @@ def setup
end
@cmd = Gem::Commands::UninstallCommand.new
- @cmd.options[:executables] = true
@executable = File.join(@gemhome, 'bin', 'executable')
end
@@ -38,6 +37,7 @@ def test_execute_removes_executable
open @executable, "wb+" do |f| f.puts "binary" end
+ @cmd.options[:executables] = true
@cmd.options[:args] = [@spec.name]
use_ui @ui do
@cmd.execute
@@ -61,6 +61,7 @@ def test_execute_removes_formatted_executable
formatted_executable = File.join @gemhome, 'bin', 'foo-executable-bar'
assert_equal true, File.exist?(formatted_executable)
+ @cmd.options[:executables] = true
@cmd.options[:format_executable] = true
@cmd.execute
@@ -70,6 +71,7 @@ def test_execute_removes_formatted_executable
end
def test_execute_not_installed
+ @cmd.options[:executables] = true
@cmd.options[:args] = ["foo"]
e = assert_raises Gem::InstallError do
use_ui @ui do
@@ -95,6 +97,7 @@ def test_execute_prerelease
end
end
+ @cmd.options[:executables] = true
@cmd.options[:args] = ["pre"]
use_ui @ui do
@@ -104,5 +107,61 @@ def test_execute_prerelease
output = @ui.output
assert_match(/Successfully uninstalled/, output)
end
+
+ def test_execute_with_force_leaves_executable
+ ui = Gem::MockGemUi.new
+
+ util_make_gems
+ util_setup_gem ui
+
+ @cmd.options[:version] = '1'
+ @cmd.options[:force] = true
+ @cmd.options[:args] = ['a']
+
+ use_ui ui do
+ @cmd.execute
+ end
+
+ assert !Gem::Specification.all_names.include?('a')
+ assert File.exist? File.join(@gemhome, 'bin', 'executable')
+ end
+
+ def test_execute_with_force_uninstalls_all_versions
+ ui = Gem::MockGemUi.new
+
+ util_make_gems
+ util_setup_gem ui
+
+ assert Gem::Specification.find_all_by_name('a').length > 1
+
+ @cmd.options[:force] = true
+ @cmd.options[:args] = ['a']
+
+ use_ui ui do
+ @cmd.execute
+ end
+
+ assert !Gem::Specification.all_names.include?('a')
+ end
+
+ def test_execute_with_force_ignores_dependencies
+ ui = Gem::MockGemUi.new
+
+ util_make_gems
+ util_setup_gem ui
+
+ assert Gem::Specification.find_all_by_name('dep_x').length > 0
+ assert Gem::Specification.find_all_by_name('x').length > 0
+
+ @cmd.options[:force] = true
+ @cmd.options[:args] = ['x']
+
+ use_ui ui do
+ @cmd.execute
+ end
+
+ assert Gem::Specification.find_all_by_name('dep_x').length > 0
+ assert Gem::Specification.find_all_by_name('x').length == 0
+ end
end
View
2  test/rubygems/test_gem_format.rb
@@ -16,7 +16,7 @@ def test_class_from_file_by_path
gems = Dir[File.join(@gemhome, "cache", "*.gem")]
- names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @pl1].map do |spec|
+ names = [@a1, @a2, @a3a, @a_evil9, @b2, @c1_2, @dep_x, @pl1, @x].map do |spec|
spec.original_name
end
View
40 test/rubygems/test_gem_indexer.rb
@@ -73,7 +73,9 @@ def test_build_indicies
["b", Gem::Version.new("2"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
["d", Gem::Version.new("2.0"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]
+ ["dep_x", Gem::Version.new("1"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"],
+ ["x", Gem::Version.new("1"), "ruby"]]
assert_equal expected, specs
@@ -87,7 +89,9 @@ def test_build_indicies
["b", Gem::Version.new("2"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
["d", Gem::Version.new("2.0"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]
+ ["dep_x", Gem::Version.new("1"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"],
+ ["x", Gem::Version.new("1"), "ruby"]]
assert_equal expected, latest_specs, 'latest_specs'
end
@@ -211,6 +215,18 @@ def test_generate_index
<link>http://example.com</link>
</item>
<item>
+ <title>dep_x-1</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>dep_x-1</guid>
+ <enclosure url=\"http://gems.example.com/gems/dep_x-1.gem\"
+ length=\"3584\" type=\"application/octet-stream\" />
+ <pubDate>#{@dep_x.date.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
<title>pl-1-x86-linux</title>
<description>
&lt;pre&gt;This is a test description&lt;/pre&gt;
@@ -223,6 +239,18 @@ def test_generate_index
<link>http://example.com</link>
</item>
<item>
+ <title>x-1</title>
+ <description>
+&lt;pre&gt;This is a test description&lt;/pre&gt;
+ </description>
+ <author>example@example.com (A User)</author>
+ <guid>x-1</guid>
+ <enclosure url=\"http://gems.example.com/gems/x-1.gem\"
+ length=\"3072\" type=\"application/octet-stream\" />
+ <pubDate>#{@x.date.rfc2822}</pubDate>
+ <link>http://example.com</link>
+ </item>
+ <item>
<title>a-1</title>
<description>
&lt;pre&gt;This line is really, really long. So long, in fact, that it is more than
@@ -401,8 +429,8 @@ def test_generate_index_ui
@indexer.generate_index
end
- assert_match %r%^\.\.\.\.\.\.\.\.\.\.$%, @ui.output
- assert_match %r%^Generating Marshal quick index gemspecs for 10 gems$%,
+ assert_match %r%^\.\.\.\.\.\.\.\.\.\.\.\.$%, @ui.output
+ assert_match %r%^Generating Marshal quick index gemspecs for 12 gems$%,
@ui.output
assert_match %r%^Complete$%, @ui.output
assert_match %r%^Generating specs index$%, @ui.output
@@ -432,7 +460,9 @@ def test_generate_index_specs
['b', Gem::Version.new(2), 'ruby'],
['c', Gem::Version.new('1.2'), 'ruby'],
['d', Gem::Version.new('2.0'), 'ruby'],
+ ['dep_x', Gem::Version.new(1), 'ruby'],
['pl', Gem::Version.new(1), 'i386-linux'],
+ ['x', Gem::Version.new(1), 'ruby'],
]
assert_equal expected, specs
@@ -466,7 +496,9 @@ def test_generate_index_latest_specs
['b', Gem::Version.new(2), 'ruby'],
['c', Gem::Version.new('1.2'), 'ruby'],
['d', Gem::Version.new('2.0'), 'ruby'],
+ ['dep_x', Gem::Version.new(1), 'ruby'],
['pl', Gem::Version.new(1), 'i386-linux'],
+ ['x', Gem::Version.new(1), 'ruby'],
]
assert_equal expected, latest_specs
View
4 test/rubygems/test_gem_source_index.rb
@@ -75,9 +75,11 @@ def test_latest_specs
@b2.full_name,
@c1_2.full_name,
@a_evil9.full_name,
+ @dep_x.full_name,
p1_ruby.full_name,
p1_platform.full_name,
- @pl1.full_name
+ @pl1.full_name,
+ @x.full_name,
].sort
latest_specs = @source_index.latest_specs.map { |s| s.full_name }.sort
View
10 test/rubygems/test_gem_spec_fetcher.rb
@@ -286,7 +286,9 @@ def test_list_all
["a", Gem::Version.new("2"), "ruby"],
["a_evil", Gem::Version.new("9"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]],
+ ['dep_x', Gem::Version.new(1), 'ruby'],
+ ["pl", Gem::Version.new("1"), "i386-linux"],
+ ['x', Gem::Version.new(1), 'ruby']],
specs[@uri].sort)
end
@@ -325,7 +327,9 @@ def test_list_latest_all
["a", Gem::Version.new("2"), "ruby"],
["a_evil", Gem::Version.new("9"), "ruby"],
["c", Gem::Version.new("1.2"), "ruby"],
- ["pl", Gem::Version.new("1"), "i386-linux"]]],
+ ["dep_x", Gem::Version.new("1"), "ruby"],
+ ["pl", Gem::Version.new("1"), "i386-linux"],
+ ["x", Gem::Version.new("1"), "ruby"]]],
specs.values, 'specs file not loaded')
end
@@ -343,7 +347,9 @@ def test_load_specs
['a', Gem::Version.new('3.a'), Gem::Platform::RUBY],
['a_evil', Gem::Version.new(9), Gem::Platform::RUBY],
['c', Gem::Version.new('1.2'), Gem::Platform::RUBY],
+ ['dep_x', Gem::Version.new(1), Gem::Platform::RUBY],
['pl', Gem::Version.new(1), 'i386-linux'],
+ ['x', Gem::Version.new(1), Gem::Platform::RUBY]
]
assert_equal expected, @sf.load_specs(@uri, 'specs')
View
2  test/rubygems/test_gem_specification.rb
@@ -1349,8 +1349,10 @@ def test_latest_specs
a-3-x86-other_platform-1
a_evil-9
c-1.2
+ dep_x-1
p-1
#{p1_curr.full_name}
+ x-1
]
latest_specs = Gem::Specification.latest_specs.map(&:full_name).sort
Please sign in to comment.
Something went wrong with that request. Please try again.