241
241
class TestOptionDefinitions(TestCase):
242
242
"""Tests for options in the Bazaar codebase."""
244
def get_all_options(self):
245
"""Return a list of all options used by Bazaar, both global and command.
247
The list returned contains elements of (scope, option) where 'scope'
248
is either None for global options, or a command name.
250
This includes options provided by plugins.
252
g = [(None, opt) for name, opt
253
in sorted(option.Option.OPTIONS.items())]
244
def get_builtin_command_options(self):
254
246
for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
255
247
cmd = cmd_class()
256
248
for opt_name, opt in sorted(cmd.options().items()):
257
249
g.append((cmd_name, opt))
260
def test_get_all_options(self):
261
all = self.get_all_options()
262
self.assertTrue(len(all) > 100,
263
"too few options found: %r" % all)
265
252
def test_global_options_used(self):
266
253
# In the distant memory, options could only be declared globally. Now
267
254
# we prefer to declare them in the command, unless like -r they really
282
269
used_globals.setdefault(option_or_name, []).append(cmd_name)
283
270
unused_globals = set(g.keys()) - set(used_globals.keys())
284
for option_name in sorted(unused_globals):
285
msgs.append("unused global option %r" % option_name)
286
for option_name, cmds in sorted(used_globals.items()):
288
msgs.append("global option %r is only used by %r"
289
% (option_name, cmds))
271
# not enforced because there might be plugins that use these globals
272
## for option_name in sorted(unused_globals):
273
## msgs.append("unused global option %r" % option_name)
274
## for option_name, cmds in sorted(used_globals.items()):
275
## if len(cmds) <= 1:
276
## msgs.append("global option %r is only used by %r"
277
## % (option_name, cmds))
291
279
self.fail("problems with global option definitions:\n"
292
280
+ '\n'.join(msgs))
297
285
# period and be all on a single line, because the display code will
299
287
option_re = re.compile(r'^[A-Z][^\n]+\.$')
300
for scope, option in self.get_all_options():
288
for scope, option in self.get_builtin_command_options():
301
289
if not option.help:
302
290
msgs.append('%-16s %-16s %s' %
303
291
((scope or 'GLOBAL'), option.name, 'NO HELP'))