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 (
52
55
def test_option_help(self):
53
56
"""Options have help strings."""
54
57
out, err = self.run_bzr('commit --help')
55
self.assertContainsRe(out, r'--file(.|\n)*file containing commit'
58
self.assertContainsRe(out,
59
r'--file(.|\n)*Take commit message from this file\.')
57
60
self.assertContainsRe(out, r'-h.*--help')
59
62
def test_option_help_global(self):
60
63
"""Global options have help strings."""
61
64
out, err = self.run_bzr('help status')
62
self.assertContainsRe(out, r'--show-ids.*show internal object')
65
self.assertContainsRe(out, r'--show-ids.*Show internal object.')
64
67
def test_option_arg_help(self):
65
68
"""Help message shows option arguments."""
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 help should be written in sentence form, and have a final
302
# period and be all on a single line, because the display code will
304
option_re = re.compile(r'^[A-Z][^\n]+\.$')
305
for scope, option in self.get_all_options():
307
# TODO: Also complain about options that have no help message?
309
if not option_re.match(option.help):
310
msgs.append('%-16s %-16s %s' %
311
((scope or 'GLOBAL'), option.name, option.help))
313
self.fail("The following options don't match the style guide:\n"
316
# TODO: Scan for global options that aren't used by any command?
318
# TODO: Check that there are two spaces between sentences.