2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/installer_test_case'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/install_update_options'
|
|
|
|
require 'rubygems/command'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/dependency_installer'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
class TestGemInstallUpdateOptions < Gem::InstallerTestCase
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@cmd = Gem::Command.new 'dummy', 'dummy',
|
|
|
|
Gem::DependencyInstaller::DEFAULT_OPTIONS
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.extend Gem::InstallUpdateOptions
|
2008-06-25 22:06:00 -04:00
|
|
|
@cmd.add_install_update_options
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_install_update_options
|
2012-11-29 01:52:18 -05:00
|
|
|
args = %w[
|
|
|
|
--document
|
2014-09-13 23:30:02 -04:00
|
|
|
--build-root build_root
|
2012-11-29 01:52:18 -05:00
|
|
|
--format-exec
|
|
|
|
--ignore-dependencies
|
|
|
|
--rdoc
|
|
|
|
--ri
|
|
|
|
-E
|
|
|
|
-f
|
|
|
|
-i /install_to
|
|
|
|
-w
|
2014-09-13 23:30:02 -04:00
|
|
|
--vendor
|
2016-02-01 07:43:26 -05:00
|
|
|
--post-install-message
|
2012-11-29 01:52:18 -05:00
|
|
|
]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2013-09-14 04:59:02 -04:00
|
|
|
args.concat %w[-P HighSecurity] if defined?(OpenSSL::SSL)
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
assert @cmd.handles?(args)
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_build_root
|
|
|
|
@cmd.handle_options %w[--build-root build_root]
|
|
|
|
|
|
|
|
assert_equal File.expand_path('build_root'), @cmd.options[:build_root]
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_doc
|
|
|
|
@cmd.handle_options %w[--doc]
|
|
|
|
|
|
|
|
assert_equal %w[ri], @cmd.options[:document].sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_doc_rdoc
|
|
|
|
@cmd.handle_options %w[--doc=rdoc]
|
|
|
|
|
|
|
|
assert_equal %w[rdoc], @cmd.options[:document]
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--doc ri]
|
|
|
|
|
|
|
|
assert_equal %w[ri], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_doc_rdoc_ri
|
|
|
|
@cmd.handle_options %w[--doc=rdoc,ri]
|
|
|
|
|
|
|
|
assert_equal %w[rdoc ri], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_doc_no
|
|
|
|
@cmd.handle_options %w[--no-doc]
|
|
|
|
|
|
|
|
assert_equal [], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document
|
|
|
|
@cmd.handle_options %w[--document]
|
|
|
|
|
|
|
|
assert_equal %w[ri], @cmd.options[:document].sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document_no
|
|
|
|
@cmd.handle_options %w[--no-document]
|
|
|
|
|
|
|
|
assert_equal %w[], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document_rdoc
|
|
|
|
@cmd.handle_options %w[--document=rdoc]
|
|
|
|
|
|
|
|
assert_equal %w[rdoc], @cmd.options[:document]
|
|
|
|
|
|
|
|
@cmd.handle_options %w[--document ri]
|
|
|
|
|
|
|
|
assert_equal %w[ri], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc
|
|
|
|
@cmd.handle_options %w[--rdoc]
|
|
|
|
|
|
|
|
assert_equal %w[rdoc ri], @cmd.options[:document].sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rdoc_no
|
|
|
|
@cmd.handle_options %w[--no-rdoc]
|
|
|
|
|
|
|
|
assert_equal %w[ri], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ri
|
|
|
|
@cmd.handle_options %w[--no-ri]
|
|
|
|
|
|
|
|
assert_equal %w[], @cmd.options[:document]
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_security_policy
|
2013-09-14 04:59:02 -04:00
|
|
|
skip 'openssl is missing' unless defined?(OpenSSL::SSL)
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.handle_options %w[-P HighSecurity]
|
|
|
|
|
|
|
|
assert_equal Gem::Security::HighSecurity, @cmd.options[:security_policy]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_security_policy_unknown
|
|
|
|
@cmd.add_install_update_options
|
|
|
|
|
2008-10-25 18:58:43 -04:00
|
|
|
assert_raises OptionParser::InvalidArgument do
|
2007-11-10 02:48:56 -05:00
|
|
|
@cmd.handle_options %w[-P UnknownSecurity]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-25 22:06:00 -04:00
|
|
|
def test_user_install_enabled
|
|
|
|
@cmd.handle_options %w[--user-install]
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
assert @cmd.options[:user_install]
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
@installer = Gem::Installer.at @gem, @cmd.options
|
2008-06-25 22:06:00 -04:00
|
|
|
@installer.install
|
2011-05-31 23:45:05 -04:00
|
|
|
assert_path_exists File.join(Gem.user_dir, 'gems')
|
|
|
|
assert_path_exists File.join(Gem.user_dir, 'gems', @spec.full_name)
|
2008-06-25 22:06:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_user_install_disabled_read_only
|
2009-06-09 17:38:59 -04:00
|
|
|
if win_platform?
|
|
|
|
skip('test_user_install_disabled_read_only test skipped on MS Windows')
|
|
|
|
else
|
|
|
|
@cmd.handle_options %w[--no-user-install]
|
2008-06-25 22:06:00 -04:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
refute @cmd.options[:user_install]
|
2008-06-25 22:06:00 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
FileUtils.chmod 0755, @userhome
|
2009-06-09 17:38:59 -04:00
|
|
|
FileUtils.chmod 0000, @gemhome
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem.use_paths @gemhome, @userhome
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
assert_raises(Gem::FilePermissionError) do
|
2015-07-01 17:50:14 -04:00
|
|
|
Gem::Installer.at(@gem, @cmd.options).install
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2008-06-25 22:06:00 -04:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
FileUtils.chmod 0755, @gemhome
|
|
|
|
end
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
def test_vendor
|
|
|
|
@cmd.handle_options %w[--vendor]
|
|
|
|
|
|
|
|
assert @cmd.options[:vendor]
|
|
|
|
assert_equal Gem.vendor_dir, @cmd.options[:install_dir]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_vendor_missing
|
|
|
|
orig_vendordir = RbConfig::CONFIG['vendordir']
|
|
|
|
RbConfig::CONFIG.delete 'vendordir'
|
|
|
|
|
|
|
|
e = assert_raises OptionParser::InvalidOption do
|
|
|
|
@cmd.handle_options %w[--vendor]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'invalid option: --vendor your platform is not supported',
|
|
|
|
e.message
|
|
|
|
|
|
|
|
refute @cmd.options[:vendor]
|
|
|
|
refute @cmd.options[:install_dir]
|
|
|
|
|
|
|
|
ensure
|
|
|
|
RbConfig::CONFIG['vendordir'] = orig_vendordir
|
|
|
|
end
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
def test_post_install_message_no
|
|
|
|
@cmd.handle_options %w[--no-post-install-message]
|
|
|
|
|
|
|
|
assert_equal false, @cmd.options[:post_install_message]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_post_install_message
|
|
|
|
@cmd.handle_options %w[--post-install-message]
|
|
|
|
|
|
|
|
assert_equal true, @cmd.options[:post_install_message]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|