14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
19
from bzrlib import (
267
270
opts, args = self.parse(
268
271
options, ['--hello=a', '--hello=b', '--hello=-', '--hello=c'])
269
272
self.assertEqual(['c'], opts.hello)
275
class TestOptionDefinitions(TestCase):
276
"""Tests for options in the Bazaar codebase."""
278
def get_all_options(self):
279
"""Return a list of all options used by Bazaar, both global and command.
281
The list returned contains elements of (scope, option) where 'scope'
282
is either None for global options, or a command name.
284
This includes options provided by plugins.
286
g = [(None, opt) for name, opt
287
in sorted(option.Option.OPTIONS.items())]
288
for cmd_name, cmd_class in sorted(commands.get_all_cmds()):
290
for opt_name, opt in sorted(cmd.options().items()):
291
g.append((cmd_name, opt))
294
def test_get_all_options(self):
295
all = self.get_all_options()
296
self.assertTrue(len(all) > 100,
297
"too few options found: %r" % all)
299
def test_option_grammar(self):
301
option_re = re.compile(r'^[A-Z]')
302
for scope, option in self.get_all_options():
304
# TODO: Also complain about options that have no help message?
306
if not option_re.match(option.help):
307
msgs.append('%-16s %-16s %s' %
308
((scope or 'GLOBAL'), option.name, option.help))
310
self.fail("The following options don't match the style guide:\n"
313
# TODO: Scan for global options that aren't used by any command?
315
# TODO: Check that there are two spaces between sentences.