2007-11-10 02:48:56 -05:00
|
|
|
require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
|
|
|
|
require 'rubygems/commands/dependency_command'
|
|
|
|
|
|
|
|
class TestGemCommandsDependencyCommand < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::DependencyCommand.new
|
|
|
|
@cmd.options[:domain] = :local
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
util_setup_fake_fetcher
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
quick_gem 'foo' do |gem|
|
2007-12-20 03:39:12 -05:00
|
|
|
gem.add_dependency 'bar', '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
Gem.source_index = nil
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
def test_execute_no_args
|
|
|
|
Gem.source_index = nil
|
|
|
|
|
|
|
|
@cmd.options[:args] = []
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Gem a-1
|
|
|
|
|
|
|
|
Gem a-2
|
|
|
|
|
|
|
|
Gem a_evil-9
|
|
|
|
|
|
|
|
Gem b-2
|
|
|
|
|
|
|
|
Gem c-1.2
|
|
|
|
|
|
|
|
Gem pl-1-x86-linux
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_no_match
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises MockGemUi::TermError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "No gems found matching foo (>= 0)\n", @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_pipe_format
|
|
|
|
quick_gem 'foo' do |gem|
|
2007-12-20 03:39:12 -05:00
|
|
|
gem.add_dependency 'bar', '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:pipe_format] = true
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
assert_equal "bar --version '> 1'\n", @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
def test_execute_regexp
|
|
|
|
Gem.source_index = nil
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[/[ab]/]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Gem a-1
|
|
|
|
|
|
|
|
Gem a-2
|
|
|
|
|
|
|
|
Gem a_evil-9
|
|
|
|
|
|
|
|
Gem b-2
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_reverse
|
|
|
|
quick_gem 'foo' do |gem|
|
2007-12-20 03:39:12 -05:00
|
|
|
gem.add_dependency 'bar', '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
quick_gem 'baz' do |gem|
|
|
|
|
gem.add_dependency 'foo'
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
Gem.source_index = nil
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:reverse_dependencies] = true
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
2007-12-20 03:39:12 -05:00
|
|
|
Gem foo-2
|
2008-06-17 18:04:18 -04:00
|
|
|
bar (> 1, runtime)
|
2007-11-10 02:48:56 -05:00
|
|
|
Used by
|
2008-06-17 18:04:18 -04:00
|
|
|
baz-2 (foo (>= 0, runtime))
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_execute_reverse_remote
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:reverse_dependencies] = true
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises MockGemUi::TermError do
|
2008-06-17 18:04:18 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
ERROR: Only reverse dependencies for local gems are supported.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal '', @ui.output
|
|
|
|
assert_equal expected, @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_remote
|
|
|
|
foo = quick_gem 'foo' do |gem|
|
2007-12-20 03:39:12 -05:00
|
|
|
gem.add_dependency 'bar', '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
@fetcher = Gem::FakeFetcher.new
|
|
|
|
Gem::RemoteFetcher.fetcher = @fetcher
|
|
|
|
|
|
|
|
util_setup_spec_fetcher foo
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
FileUtils.rm File.join(@gemhome, 'specifications',
|
|
|
|
"#{foo.full_name}.gemspec")
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal '', @ui.error
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def test_execute_remote_legacy
|
|
|
|
foo = quick_gem 'foo' do |gem|
|
|
|
|
gem.add_dependency 'bar', '> 1'
|
|
|
|
end
|
|
|
|
|
|
|
|
@fetcher = Gem::FakeFetcher.new
|
|
|
|
Gem::RemoteFetcher.fetcher = @fetcher
|
|
|
|
|
|
|
|
Gem::SpecFetcher.fetcher = nil
|
|
|
|
si = util_setup_source_info_cache foo
|
|
|
|
|
|
|
|
@fetcher.data["#{@gem_repo}yaml"] = YAML.dump si
|
|
|
|
@fetcher.data["#{@gem_repo}Marshal.#{Gem.marshal_version}"] =
|
|
|
|
si.dump
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
@fetcher.data.delete "#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
FileUtils.rm File.join(@gemhome, 'specifications',
|
|
|
|
"#{foo.full_name}.gemspec")
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal "Gem foo-2\n bar (> 1, runtime)\n\n", @ui.output
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
WARNING: RubyGems 1.2+ index not found for:
|
|
|
|
\t#{@gem_repo}
|
|
|
|
|
|
|
|
RubyGems will revert to legacy indexes degrading performance.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|