2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
8 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
9 require 'rubygems/command_manager'
11 class InterruptCommand < Gem::Command
14 super('interrupt', 'Raises an Interrupt Exception', {})
18 raise Interrupt, "Interrupt exception"
23 class TestGemCommandManager < RubyGemTestCase
28 @command_manager = Gem::CommandManager.new
31 def test_run_interrupt
33 @command_manager.register_command :interrupt
34 assert_raises MockGemUi::TermError do
35 @command_manager.run 'interrupt'
37 assert_equal '', ui.output
38 assert_equal "ERROR: Interrupted\n", ui.error
42 def test_process_args_bad_arg
44 assert_raises(MockGemUi::TermError) {
45 @command_manager.process_args("--bad-arg")
49 assert_match(/invalid option: --bad-arg/i, @ui.error)
52 def test_process_args_install
53 #capture all install options
56 @command_manager['install'].when_invoked do |options|
57 check_options = options
62 @command_manager.process_args("install")
63 assert_equal false, check_options[:test]
64 assert_equal true, check_options[:generate_rdoc]
65 assert_equal false, check_options[:force]
66 assert_equal :both, check_options[:domain]
67 assert_equal true, check_options[:wrappers]
68 assert_equal Gem::Requirement.default, check_options[:version]
69 assert_equal Gem.dir, check_options[:install_dir]
70 assert_equal nil, check_options[:bin_dir]
74 @command_manager.process_args(
75 "install --force --test --local --rdoc --install-dir . --version 3.0 --no-wrapper --bindir . ")
76 assert_equal true, check_options[:test]
77 assert_equal true, check_options[:generate_rdoc]
78 assert_equal true, check_options[:force]
79 assert_equal :local, check_options[:domain]
80 assert_equal false, check_options[:wrappers]
81 assert_equal Gem::Requirement.new('3.0'), check_options[:version]
82 assert_equal Dir.pwd, check_options[:install_dir]
83 assert_equal Dir.pwd, check_options[:bin_dir]
87 @command_manager.process_args("install --remote")
88 assert_equal :remote, check_options[:domain]
92 @command_manager.process_args("install --both")
93 assert_equal :both, check_options[:domain]
97 @command_manager.process_args("install --both")
98 assert_equal :both, check_options[:domain]
102 def test_process_args_uninstall
103 #capture all uninstall options
105 @command_manager['uninstall'].when_invoked do |options|
106 check_options = options
111 @command_manager.process_args("uninstall")
112 assert_equal Gem::Requirement.default, check_options[:version]
116 @command_manager.process_args("uninstall foobar --version 3.0")
117 assert_equal "foobar", check_options[:args].first
118 assert_equal Gem::Requirement.new('3.0'), check_options[:version]
121 def test_process_args_check
122 #capture all check options
124 @command_manager['check'].when_invoked do |options|
125 check_options = options
130 @command_manager.process_args("check")
131 assert_equal false, check_options[:verify]
132 assert_equal false, check_options[:alien]
136 @command_manager.process_args("check --verify foobar --alien")
137 assert_equal "foobar", check_options[:verify]
138 assert_equal true, check_options[:alien]
141 def test_process_args_build
142 #capture all build options
144 @command_manager['build'].when_invoked do |options|
145 check_options = options
150 @command_manager.process_args("build")
151 #NOTE: Currently no defaults
155 @command_manager.process_args("build foobar.rb")
156 assert_equal 'foobar.rb', check_options[:args].first
159 def test_process_args_query
160 #capture all query options
162 @command_manager['query'].when_invoked do |options|
163 check_options = options
168 @command_manager.process_args("query")
169 assert_equal(//, check_options[:name])
170 assert_equal :local, check_options[:domain]
171 assert_equal false, check_options[:details]
175 @command_manager.process_args("query --name foobar --local --details")
176 assert_equal(/foobar/i, check_options[:name])
177 assert_equal :local, check_options[:domain]
178 assert_equal true, check_options[:details]
182 @command_manager.process_args("query --remote")
183 assert_equal :remote, check_options[:domain]
185 #both (local/remote) domains
187 @command_manager.process_args("query --both")
188 assert_equal :both, check_options[:domain]
191 def test_process_args_update
192 #capture all update options
194 @command_manager['update'].when_invoked do |options|
195 check_options = options
200 @command_manager.process_args("update")
201 assert_equal true, check_options[:generate_rdoc]
205 @command_manager.process_args("update --force --test --rdoc --install-dir .")
206 assert_equal true, check_options[:test]
207 assert_equal true, check_options[:generate_rdoc]
208 assert_equal true, check_options[:force]
209 assert_equal Dir.pwd, check_options[:install_dir]