129
131
def test_simple(self):
130
132
my_config = self._get_config("[ALIASES]\n"
131
"diff=diff -r -2..-1\n")
133
"diff=diff -r -2..-1\n")
132
134
self.assertEqual([u'diff', u'-r', u'-2..-1'],
133
commands.get_alias("diff", config=my_config))
135
commands.get_alias("diff", config=my_config))
135
137
def test_single_quotes(self):
136
138
my_config = self._get_config("[ALIASES]\n"
137
"diff=diff -r -2..-1 --diff-options "
138
"'--strip-trailing-cr -wp'\n")
139
"diff=diff -r -2..-1 --diff-options "
140
"'--strip-trailing-cr -wp'\n")
139
141
self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
140
142
u'--strip-trailing-cr -wp'],
141
commands.get_alias("diff", config=my_config))
143
commands.get_alias("diff", config=my_config))
143
145
def test_double_quotes(self):
144
146
my_config = self._get_config("[ALIASES]\n"
145
"diff=diff -r -2..-1 --diff-options "
146
"\"--strip-trailing-cr -wp\"\n")
147
"diff=diff -r -2..-1 --diff-options "
148
"\"--strip-trailing-cr -wp\"\n")
147
149
self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
148
150
u'--strip-trailing-cr -wp'],
149
commands.get_alias("diff", config=my_config))
151
commands.get_alias("diff", config=my_config))
151
153
def test_unicode(self):
152
154
my_config = self._get_config("[ALIASES]\n"
153
u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
155
u'iam=whoami "Erik B\u00e5gfors <erik@bagfors.nu>"\n')
154
156
self.assertEqual([u'whoami', u'Erik B\u00e5gfors <erik@bagfors.nu>'],
155
commands.get_alias("iam", config=my_config))
157
commands.get_alias("iam", config=my_config))
158
160
class TestSeeAlso(tests.TestCase):
188
190
"""Additional terms can be supplied and are deduped and sorted."""
189
191
command = self._get_command_with_see_also(['foo', 'bar'])
190
192
self.assertEqual(['bar', 'foo', 'gam'],
191
command.get_see_also(['gam', 'bar', 'gam']))
193
command.get_see_also(['gam', 'bar', 'gam']))
194
196
class TestRegisterLazy(tests.TestCase):
246
248
commands.Command.hooks.install_named_hook(
247
249
"extend_command", hook_calls.append, None)
248
250
# create a command, should not fire
249
252
class cmd_test_extend_command_hook(commands.Command):
250
253
__doc__ = """A sample command."""
251
254
self.assertEqual([], hook_calls)
252
255
# -- as a builtin
253
256
# register the command class, should not fire
255
commands.builtin_command_registry.register(cmd_test_extend_command_hook)
258
commands.builtin_command_registry.register(
259
cmd_test_extend_command_hook)
256
260
self.assertEqual([], hook_calls)
257
261
# and ask for the object, should fire
258
262
cmd = commands.get_cmd_object('test-extend-command-hook')
262
266
self.assertSubset([cmd], hook_calls)
263
267
del hook_calls[:]
265
commands.builtin_command_registry.remove('test-extend-command-hook')
269
commands.builtin_command_registry.remove(
270
'test-extend-command-hook')
266
271
# -- as a plugin lazy registration
268
273
# register the command class, should not fire
284
289
commands.install_bzr_command_hooks()
286
292
class ACommand(commands.Command):
287
293
__doc__ = """A sample command."""
288
295
def get_cmd(cmd_or_None, cmd_name):
289
296
hook_calls.append(('called', cmd_or_None, cmd_name))
290
297
if cmd_name in ('foo', 'info'):
319
326
def test_not_found_no_suggestion(self):
320
327
e = self.assertRaises(errors.BzrCommandError,
321
commands.get_cmd_object, 'idontexistand')
328
commands.get_cmd_object, 'idontexistand')
322
329
self.assertEqual('unknown command "idontexistand"', str(e))
324
331
def test_not_found_with_suggestion(self):
325
332
e = self.assertRaises(errors.BzrCommandError,
326
commands.get_cmd_object, 'statue')
333
commands.get_cmd_object, 'statue')
327
334
self.assertEqual('unknown command "statue". Perhaps you meant "status"',
331
338
class TestGetMissingCommandHook(tests.TestCase):
333
340
def hook_missing(self):
334
341
"""Hook get_missing_command for testing."""
335
342
self.hook_calls = []
336
344
class ACommand(commands.Command):
337
345
__doc__ = """A sample command."""
338
347
def get_missing_cmd(cmd_name):
339
348
self.hook_calls.append(('called', cmd_name))
340
349
if cmd_name in ('foo', 'info'):
377
386
# The list_commands() hook fires when all_command_names() is invoked.
379
388
commands.install_bzr_command_hooks()
380
390
def list_my_commands(cmd_names):
381
391
hook_calls.append('called')
382
392
cmd_names.update(['foo', 'bar'])
391
401
self.assertEqual(['called'], hook_calls)
392
402
self.assertSubset(['foo', 'bar'], cmds)
394
405
class TestPreAndPostCommandHooks(tests.TestCase):
395
406
class TestError(Exception):
396
407
__doc__ = """A test exception."""