2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/dependency_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsDependencyCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
2018-05-30 09:01:35 -04:00
|
|
|
@stub_ui = Gem::MockGemUi.new
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd = Gem::Commands::DependencyCommand.new
|
|
|
|
@cmd.options[:domain] = :local
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute
|
|
|
|
quick_gem 'foo' do |gem|
|
2007-12-20 03:39:12 -05:00
|
|
|
gem.add_dependency 'bar', '> 1'
|
2010-02-21 21:52:35 -05:00
|
|
|
gem.add_dependency 'baz', '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2011-03-07 03:44:45 -05:00
|
|
|
assert_equal "Gem foo-2\n bar (> 1)\n baz (> 1)\n\n",
|
2018-05-30 09:01:35 -04:00
|
|
|
@stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
def test_execute_no_args
|
2018-05-30 09:01:35 -04:00
|
|
|
install_specs util_spec 'x', '2'
|
2015-07-01 17:50:14 -04:00
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'dep_x', 1, 'x' => '>= 1'
|
|
|
|
fetcher.legacy_platform
|
|
|
|
end
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
@cmd.options[:args] = []
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2008-06-19 14:15:26 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Gem a-1
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
Gem a-2.a
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
Gem dep_x-1
|
|
|
|
x (>= 1)
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
Gem pl-1-x86-linux
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
Gem x-2
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
EOF
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal expected, @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2008-06-19 14:15:26 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_no_match
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal "No gems found matching foo (>= 0)\n", @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_pipe_format
|
2015-07-01 17:50:14 -04:00
|
|
|
spec = util_spec '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
|
2015-07-01 17:50:14 -04:00
|
|
|
install_specs util_spec 'bar', 2
|
|
|
|
install_specs spec
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:pipe_format] = true
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal "bar --version '> 1'\n", @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
def test_execute_regexp
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
fetcher.spec 'a_evil', 9
|
|
|
|
fetcher.spec 'b', 2
|
|
|
|
end
|
|
|
|
|
2019-04-26 07:26:21 -04:00
|
|
|
@cmd.options[:args] = %w[[ab]]
|
2008-06-19 14:15:26 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2008-06-19 14:15:26 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Gem a-1
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
Gem a-2.a
|
|
|
|
|
2008-06-19 14:15:26 -04:00
|
|
|
Gem a_evil-9
|
|
|
|
|
|
|
|
Gem b-2
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal expected, @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2008-06-19 14:15:26 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_reverse
|
2011-03-07 03:44:45 -05:00
|
|
|
# FIX: this shouldn't need to write out, but fails if you switch it
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:reverse_dependencies] = true
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
2007-12-20 03:39:12 -05:00
|
|
|
Gem foo-2
|
2011-03-07 03:44:45 -05:00
|
|
|
bar (> 1)
|
2007-11-10 02:48:56 -05:00
|
|
|
Used by
|
2011-03-07 03:44:45 -05:00
|
|
|
baz-2 (foo (>= 0))
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal expected, @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2007-11-10 02:48:56 -05:00
|
|
|
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
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
assert_raises Gem::MockGemUi::TermError do
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2008-06-17 18:04:18 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
ERROR: Only reverse dependencies for local gems are supported.
|
|
|
|
EOF
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal '', @stub_ui.output
|
|
|
|
assert_equal expected, @stub_ui.error
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_remote
|
2018-05-30 09:01:35 -04:00
|
|
|
install_specs util_spec 'bar', '2'
|
2015-07-01 17:50:14 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'foo', 2, 'bar' => '> 1'
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal "Gem foo-2\n bar (> 1)\n\n", @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_execute_remote_version
|
|
|
|
@fetcher = Gem::FakeFetcher.new
|
|
|
|
Gem::RemoteFetcher.fetcher = @fetcher
|
|
|
|
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
fetcher.spec 'a', 2
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[a]
|
|
|
|
@cmd.options[:domain] = :remote
|
|
|
|
@cmd.options[:version] = req '= 1'
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2011-05-31 23:45:05 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal "Gem a-1\n\n", @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
def test_execute_prerelease
|
2013-11-11 19:16:41 -05:00
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', '2.a'
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
@cmd.options[:args] = %w[a]
|
2008-06-17 18:04:18 -04:00
|
|
|
@cmd.options[:domain] = :remote
|
2010-02-21 21:52:35 -05:00
|
|
|
@cmd.options[:prerelease] = true
|
2008-06-17 18:04:18 -04:00
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
use_ui @stub_ui do
|
2008-06-17 18:04:18 -04:00
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2018-05-30 09:01:35 -04:00
|
|
|
assert_equal "Gem a-2.a\n\n", @stub_ui.output
|
|
|
|
assert_equal '', @stub_ui.error
|
2008-06-17 18:04:18 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|