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