Rev 2605: Add failing test that global options are all used. in http://sourcefrog.net/bzr/check-options
Martin Pool
mbp at sourcefrog.net
Wed Jul 11 04:48:23 BST 2007
At http://sourcefrog.net/bzr/check-options
------------------------------------------------------------
revno: 2605
revision-id: mbp at sourcefrog.net-20070711034822-w0c7cnxnuo7naay5
parent: mbp at sourcefrog.net-20070711034634-44v65lrdqsdh9k2s
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: check-options
timestamp: Wed 2007-07-11 13:48:22 +1000
message:
Add failing test that global options are all used.
modified:
bzrlib/option.py option.py-20051014052914-661fb36e76e7362f
bzrlib/tests/test_options.py testoptions.py-20051014093702-96457cfc86319a8f
=== modified file 'bzrlib/option.py'
--- a/bzrlib/option.py 2007-07-11 02:32:38 +0000
+++ b/bzrlib/option.py 2007-07-11 03:48:22 +0000
@@ -418,7 +418,6 @@
help='Use moderately short log format. Same as --log-format short.')
_global_option('line', help='Use log format with one line per revision. Same as --log-format line.')
_global_option('root', type=str)
-_global_option('no-backup')
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
_merge_type_registry, value_switches=True,
title='Merge algorithm')
=== modified file 'bzrlib/tests/test_options.py'
--- a/bzrlib/tests/test_options.py 2007-07-11 02:32:38 +0000
+++ b/bzrlib/tests/test_options.py 2007-07-11 03:48:22 +0000
@@ -296,6 +296,31 @@
self.assertTrue(len(all) > 100,
"too few options found: %r" % all)
+ def test_global_options_used(self):
+ # In the distant memory, options could only be declared globally. Now
+ # we prefer to declare them in the command, unless like -r they really
+ # are used very widely with the exact same meaning. So this checks
+ # for any that should be garbage collected.
+ g = dict(option.Option.OPTIONS.items())
+ used_globals = set()
+ msgs = []
+ for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
+ for option_or_name in sorted(cmd_class.takes_options):
+ if not isinstance(option_or_name, basestring):
+ self.assertIsInstance(option_or_name, option.Option)
+ elif not option_or_name in g:
+ msgs.append("apparent reference to undefined "
+ "global option %r from %r"
+ % (option_or_name, cmd_class))
+ else:
+ used_globals.add(option_or_name)
+ unused_globals = set(g.keys()) - used_globals
+ for option_name in sorted(unused_globals):
+ msgs.append("unused global option %r" % option_name)
+ if msgs:
+ self.fail("problems with global option definitions:\n"
+ + '\n'.join(msgs))
+
def test_option_grammar(self):
msgs = []
# Option help should be written in sentence form, and have a final
@@ -304,9 +329,10 @@
option_re = re.compile(r'^[A-Z][^\n]+\.$')
for scope, option in self.get_all_options():
if not option.help:
- # TODO: Also complain about options that have no help message?
- continue
- if not option_re.match(option.help):
+ # msgs.append('%-16s %-16s %s' %
+ # ((scope or 'GLOBAL'), option.name, 'NO HELP'))
+ pass
+ elif not option_re.match(option.help):
msgs.append('%-16s %-16s %s' %
((scope or 'GLOBAL'), option.name, option.help))
if msgs:
More information about the bazaar-commits
mailing list