2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2021-05-12 05:41:32 -04:00
|
|
|
require_relative 'test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/commands/contents_command'
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemCommandsContentsCommand < Gem::TestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::ContentsCommand.new
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem(name, version = 2)
|
2014-09-13 23:30:02 -04:00
|
|
|
spec = quick_gem name, version do |gem|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem.files = %W[lib/#{name}.rb Rakefile]
|
|
|
|
end
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} lib #{name}.rb])
|
|
|
|
write_file File.join(*%W[gems #{spec.full_name} Rakefile])
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute
|
|
|
|
@cmd.options[:args] = %w[foo]
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
gem 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{lib/foo\.rb}, @ui.output
|
|
|
|
assert_match %r{Rakefile}, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_all
|
|
|
|
@cmd.options[:all] = true
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{lib/foo\.rb}, @ui.output
|
|
|
|
assert_match %r{lib/bar\.rb}, @ui.output
|
|
|
|
assert_match %r{Rakefile}, @ui.output
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_execute_bad_gem
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{Unable to find gem 'foo' in default gem paths}, @ui.output
|
|
|
|
assert_match %r{Directories searched:}, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_exact_match
|
|
|
|
@cmd.options[:args] = %w[foo]
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{lib/foo\.rb}, @ui.output
|
|
|
|
assert_match %r{Rakefile}, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_lib_only
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:lib_only] = true
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{lib/foo\.rb}, @ui.output
|
|
|
|
refute_match %r{Rakefile}, @ui.output
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def test_execute_missing_single
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2013-09-14 04:59:02 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match "Unable to find gem 'foo'", @ui.output
|
|
|
|
assert_empty @ui.error
|
|
|
|
end
|
|
|
|
|
2020-03-24 02:39:24 -04:00
|
|
|
def test_execute_missing_version
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:version] = Gem::Requirement.new '= 2'
|
|
|
|
|
|
|
|
gem 'foo', 1
|
|
|
|
|
2021-05-10 23:25:46 -04:00
|
|
|
assert_raise Gem::MockGemUi::TermError do
|
2020-03-24 02:39:24 -04:00
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match "Unable to find gem 'foo'", @ui.output
|
|
|
|
assert_empty @ui.error
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
def test_execute_missing_multiple
|
|
|
|
@cmd.options[:args] = %w[foo bar]
|
|
|
|
|
|
|
|
gem 'foo'
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match "lib/foo.rb", @ui.output
|
|
|
|
assert_match "Unable to find gem 'bar'", @ui.output
|
|
|
|
|
|
|
|
assert_empty @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_multiple
|
|
|
|
@cmd.options[:args] = %w[foo bar]
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
|
|
|
gem 'bar'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 14:51:43 -04:00
|
|
|
assert_match %r{lib/foo\.rb}, @ui.output
|
|
|
|
assert_match %r{lib/bar\.rb}, @ui.output
|
|
|
|
assert_match %r{Rakefile}, @ui.output
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_execute_show_install_dir
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:show_install_dir] = true
|
|
|
|
|
|
|
|
gem 'foo'
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = File.join @gemhome, 'gems', 'foo-2'
|
|
|
|
|
|
|
|
assert_equal "#{expected}\n", @ui.output
|
2020-03-24 02:39:24 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_show_install_dir_latest_version
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:show_install_dir] = true
|
|
|
|
|
|
|
|
gem 'foo', 1
|
|
|
|
gem 'foo', 2
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = File.join @gemhome, 'gems', 'foo-2'
|
|
|
|
|
|
|
|
assert_equal "#{expected}\n", @ui.output
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_execute_show_install_dir_version
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:show_install_dir] = true
|
|
|
|
@cmd.options[:version] = Gem::Requirement.new '= 1'
|
|
|
|
|
|
|
|
gem 'foo', 1
|
|
|
|
gem 'foo', 2
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = File.join @gemhome, 'gems', 'foo-1'
|
|
|
|
|
|
|
|
assert_equal "#{expected}\n", @ui.output
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
def test_execute_no_prefix
|
|
|
|
@cmd.options[:args] = %w[foo]
|
|
|
|
@cmd.options[:prefix] = false
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
gem 'foo'
|
2009-06-09 17:38:59 -04:00
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
expected = <<-EOF
|
|
|
|
Rakefile
|
2011-05-31 23:45:05 -04:00
|
|
|
lib/foo.rb
|
2009-06-09 17:38:59 -04:00
|
|
|
EOF
|
|
|
|
|
|
|
|
assert_equal expected, @ui.output
|
|
|
|
|
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_execute_default_gem
|
|
|
|
default_gem_spec = new_default_spec("default", "2.0.0.0",
|
|
|
|
nil, "default/gem.rb")
|
|
|
|
default_gem_spec.executables = ["default_command"]
|
|
|
|
default_gem_spec.files += ["default_gem.so"]
|
2020-12-08 02:33:39 -05:00
|
|
|
install_default_gems(default_gem_spec)
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
@cmd.options[:args] = %w[default]
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
expected = [
|
2014-11-11 00:08:59 -05:00
|
|
|
[RbConfig::CONFIG['bindir'], 'default_command'],
|
|
|
|
[RbConfig::CONFIG['rubylibdir'], 'default/gem.rb'],
|
2020-12-08 02:33:39 -05:00
|
|
|
[RbConfig::CONFIG['archdir'], 'default_gem.so'],
|
2020-06-10 13:46:05 -04:00
|
|
|
].sort.map{|a|File.join a }.join "\n"
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2012-11-30 01:20:34 -05:00
|
|
|
assert_equal expected, @ui.output.chomp
|
2012-11-29 01:52:18 -05:00
|
|
|
assert_equal "", @ui.error
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_handle_options
|
2010-04-22 04:24:42 -04:00
|
|
|
refute @cmd.options[:lib_only]
|
|
|
|
assert @cmd.options[:prefix]
|
|
|
|
assert_empty @cmd.options[:specdirs]
|
|
|
|
assert_nil @cmd.options[:version]
|
2014-09-13 23:30:02 -04:00
|
|
|
refute @cmd.options[:show_install_dir]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
@cmd.send :handle_options, %w[
|
|
|
|
-l
|
|
|
|
-s
|
|
|
|
foo
|
|
|
|
--version 0.0.2
|
|
|
|
--no-prefix
|
|
|
|
--show-install-dir
|
|
|
|
]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
assert @cmd.options[:lib_only]
|
|
|
|
refute @cmd.options[:prefix]
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal %w[foo], @cmd.options[:specdirs]
|
|
|
|
assert_equal Gem::Requirement.new('0.0.2'), @cmd.options[:version]
|
2014-09-13 23:30:02 -04:00
|
|
|
assert @cmd.options[:show_install_dir]
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|