2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
require "test/rubygems/gemutilities"
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command_manager'
|
|
|
|
|
|
|
|
class TestGemCommandManager < RubyGemTestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
@command_manager = Gem::CommandManager.instance
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_run_interrupt
|
2011-01-18 19:08:49 -05:00
|
|
|
old_load_path = $:.dup
|
|
|
|
$: << "test/rubygems"
|
|
|
|
Gem.load_env_plugins
|
2010-04-22 04:24:42 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
use_ui @ui do
|
2008-09-25 06:13:50 -04:00
|
|
|
assert_raises MockGemUi::TermError do
|
2007-11-10 02:48:56 -05:00
|
|
|
@command_manager.run 'interrupt'
|
|
|
|
end
|
|
|
|
assert_equal '', ui.output
|
|
|
|
assert_equal "ERROR: Interrupted\n", ui.error
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
ensure
|
|
|
|
$:.replace old_load_path
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
def test_run_crash_command
|
2011-01-18 19:08:49 -05:00
|
|
|
old_load_path = $:.dup
|
|
|
|
$: << "test/rubygems"
|
|
|
|
|
2010-04-22 04:24:42 -04:00
|
|
|
@command_manager.register_command :crash
|
|
|
|
use_ui @ui do
|
|
|
|
assert_raises MockGemUi::TermError do
|
|
|
|
@command_manager.run 'crash'
|
|
|
|
end
|
|
|
|
assert_equal '', ui.output
|
|
|
|
err = ui.error.split("\n").first
|
|
|
|
assert_equal "ERROR: Loading command: crash (RuntimeError)", err
|
|
|
|
end
|
2011-01-18 19:08:49 -05:00
|
|
|
ensure
|
|
|
|
$:.replace old_load_path
|
2010-04-22 04:24:42 -04:00
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def test_process_args_bad_arg
|
|
|
|
use_ui @ui do
|
2008-09-25 06:13:50 -04:00
|
|
|
assert_raises(MockGemUi::TermError) {
|
2007-11-10 02:48:56 -05:00
|
|
|
@command_manager.process_args("--bad-arg")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/invalid option: --bad-arg/i, @ui.error)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_install
|
|
|
|
#capture all install options
|
|
|
|
use_ui @ui do
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['install'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("install")
|
|
|
|
assert_equal true, check_options[:generate_rdoc]
|
|
|
|
assert_equal false, check_options[:force]
|
|
|
|
assert_equal :both, check_options[:domain]
|
|
|
|
assert_equal true, check_options[:wrappers]
|
|
|
|
assert_equal Gem::Requirement.default, check_options[:version]
|
2008-06-17 18:04:18 -04:00
|
|
|
assert_equal nil, check_options[:install_dir]
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal nil, check_options[:bin_dir]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args(
|
2011-01-18 19:08:49 -05:00
|
|
|
"install --force --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal true, check_options[:generate_rdoc]
|
|
|
|
assert_equal true, check_options[:force]
|
|
|
|
assert_equal :local, check_options[:domain]
|
|
|
|
assert_equal false, check_options[:wrappers]
|
|
|
|
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
|
|
|
|
assert_equal Dir.pwd, check_options[:install_dir]
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal Dir.pwd, check_options[:bin_dir]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
#check remote domain
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("install --remote")
|
|
|
|
assert_equal :remote, check_options[:domain]
|
|
|
|
|
|
|
|
#check both domain
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("install --both")
|
|
|
|
assert_equal :both, check_options[:domain]
|
|
|
|
|
|
|
|
#check both domain
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("install --both")
|
|
|
|
assert_equal :both, check_options[:domain]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_uninstall
|
|
|
|
#capture all uninstall options
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['uninstall'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("uninstall")
|
|
|
|
assert_equal Gem::Requirement.default, check_options[:version]
|
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("uninstall foobar --version 3.0")
|
|
|
|
assert_equal "foobar", check_options[:args].first
|
|
|
|
assert_equal Gem::Requirement.new('3.0'), check_options[:version]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_check
|
|
|
|
#capture all check options
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['check'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("check")
|
|
|
|
assert_equal false, check_options[:verify]
|
|
|
|
assert_equal false, check_options[:alien]
|
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("check --verify foobar --alien")
|
|
|
|
assert_equal "foobar", check_options[:verify]
|
|
|
|
assert_equal true, check_options[:alien]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_build
|
|
|
|
#capture all build options
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['build'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("build")
|
|
|
|
#NOTE: Currently no defaults
|
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("build foobar.rb")
|
|
|
|
assert_equal 'foobar.rb', check_options[:args].first
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_query
|
|
|
|
#capture all query options
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['query'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("query")
|
2008-03-31 18:40:06 -04:00
|
|
|
assert_equal(//, check_options[:name])
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal :local, check_options[:domain]
|
|
|
|
assert_equal false, check_options[:details]
|
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("query --name foobar --local --details")
|
|
|
|
assert_equal(/foobar/i, check_options[:name])
|
|
|
|
assert_equal :local, check_options[:domain]
|
|
|
|
assert_equal true, check_options[:details]
|
|
|
|
|
|
|
|
#remote domain
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("query --remote")
|
|
|
|
assert_equal :remote, check_options[:domain]
|
|
|
|
|
|
|
|
#both (local/remote) domains
|
|
|
|
check_options = nil
|
|
|
|
@command_manager.process_args("query --both")
|
|
|
|
assert_equal :both, check_options[:domain]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_process_args_update
|
|
|
|
#capture all update options
|
|
|
|
check_options = nil
|
|
|
|
@command_manager['update'].when_invoked do |options|
|
|
|
|
check_options = options
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
#check defaults
|
|
|
|
@command_manager.process_args("update")
|
|
|
|
assert_equal true, check_options[:generate_rdoc]
|
|
|
|
|
|
|
|
#check settings
|
|
|
|
check_options = nil
|
2011-01-18 19:08:49 -05:00
|
|
|
@command_manager.process_args("update --force --rdoc --install-dir .")
|
2007-11-10 02:48:56 -05:00
|
|
|
assert_equal true, check_options[:generate_rdoc]
|
|
|
|
assert_equal true, check_options[:force]
|
|
|
|
assert_equal Dir.pwd, check_options[:install_dir]
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|