43
43
# XXX: Using cmd_commit makes these tests overly sensitive to changes
44
44
# to cmd_commit, when they are meant to be about option parsing in
46
self.assertEqual(parse_args(cmd_commit(), ['--help']),
47
([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}))
48
self.assertEqual(parse_args(cmd_commit(), ['--message=biter']),
49
([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}))
47
([], {'author': [], 'exclude': [], 'fixes': [], 'help': True}),
48
parse_args(cmd_commit(), ['--help']))
50
([], {'author': [], 'exclude': [], 'fixes': [], 'message': 'biter'}),
51
parse_args(cmd_commit(), ['--message=biter']))
51
53
def test_no_more_opts(self):
52
54
"""Terminated options"""
53
self.assertEqual(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
54
(['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}))
56
(['-file-with-dashes'], {'author': [], 'exclude': [], 'fixes': []}),
57
parse_args(cmd_commit(), ['--', '-file-with-dashes']))
56
59
def test_option_help(self):
57
60
"""Options have help strings."""
65
68
out, err = self.run_bzr('help status')
66
69
self.assertContainsRe(out, r'--show-ids.*Show internal object.')
71
def test_option_help_global_hidden(self):
72
"""Hidden global options have no help strings."""
73
out, err = self.run_bzr('help log')
74
self.assertNotContainsRe(out, r'--message')
68
76
def test_option_arg_help(self):
69
77
"""Help message shows option arguments."""
70
78
out, err = self.run_bzr('help commit')
334
342
def get_builtin_command_options(self):
336
for cmd_name in sorted(commands.all_command_names()):
344
commands.install_bzr_command_hooks()
345
for cmd_name in sorted(commands.builtin_command_names()):
337
346
cmd = commands.get_cmd_object(cmd_name)
338
347
for opt_name, opt in sorted(cmd.options().items()):
339
348
g.append((cmd_name, opt))
342
def test_global_options_used(self):
343
# In the distant memory, options could only be declared globally. Now
344
# we prefer to declare them in the command, unless like -r they really
345
# are used very widely with the exact same meaning. So this checks
346
# for any that should be garbage collected.
347
g = dict(option.Option.OPTIONS.items())
350
for cmd_name in sorted(commands.all_command_names()):
351
cmd = commands.get_cmd_object(cmd_name)
352
for option_or_name in sorted(cmd.takes_options):
353
if not isinstance(option_or_name, basestring):
354
self.assertIsInstance(option_or_name, option.Option)
355
elif not option_or_name in g:
356
msgs.append("apparent reference to undefined "
357
"global option %r from %r"
358
% (option_or_name, cmd))
360
used_globals.setdefault(option_or_name, []).append(cmd_name)
361
unused_globals = set(g.keys()) - set(used_globals.keys())
362
# not enforced because there might be plugins that use these globals
363
## for option_name in sorted(unused_globals):
364
## msgs.append("unused global option %r" % option_name)
365
## for option_name, cmds in sorted(used_globals.items()):
366
## if len(cmds) <= 1:
367
## msgs.append("global option %r is only used by %r"
368
## % (option_name, cmds))
370
self.fail("problems with global option definitions:\n"
373
352
def test_option_grammar(self):
375
354
# Option help should be written in sentence form, and have a final
376
# period and be all on a single line, because the display code will
378
option_re = re.compile(r'^[A-Z][^\n]+\.$')
355
# period with an optional bracketed suffix. All the text should be on
356
# one line, because the display code will wrap it.
357
option_re = re.compile(r'^[A-Z][^\n]+\.(?: \([^\n]+\))?$')
379
358
for scope, opt in self.get_builtin_command_options():
381
msgs.append('%-16s %-16s %s' %
382
((scope or 'GLOBAL'), opt.name, 'NO HELP'))
383
elif not option_re.match(opt.help):
384
msgs.append('%-16s %-16s %s' %
385
((scope or 'GLOBAL'), opt.name, opt.help))
359
for name, _, _, helptxt in opt.iter_switches():
361
name = "/".join([opt.name, name])
363
msgs.append('%-16s %-16s %s' %
364
((scope or 'GLOBAL'), name, 'NO HELP'))
365
elif not option_re.match(helptxt):
366
if name.startswith("format/"):
367
# Don't complain about the odd format registry help
369
msgs.append('%-16s %-16s %s' %
370
((scope or 'GLOBAL'), name, helptxt))
387
372
self.fail("The following options don't match the style guide:\n"
388
373
+ '\n'.join(msgs))
376
class TestOptionMisc(TestCase):
390
378
def test_is_hidden(self):
391
379
registry = controldir.ControlDirFormatRegistry()
392
380
bzrdir.register_metadir(registry, 'hidden', 'HiddenFormat',