40
38
"""Option parser"""
41
39
eq = self.assertEquals
42
40
eq(parse_args(cmd_commit(), ['--help']),
43
([], {'fixes': [], 'help': True}))
44
42
eq(parse_args(cmd_commit(), ['--message=biter']),
45
([], {'fixes': [], 'message': 'biter'}))
43
([], {'message': 'biter'}))
44
## eq(parse_args(cmd_log(), '-r 500'.split()),
45
## ([], {'revision': RevisionSpec_int(500)}))
47
47
def test_no_more_opts(self):
48
48
"""Terminated options"""
49
49
self.assertEquals(parse_args(cmd_commit(), ['--', '-file-with-dashes']),
50
(['-file-with-dashes'], {'fixes': []}))
50
(['-file-with-dashes'], {}))
52
52
def test_option_help(self):
53
53
"""Options have help strings."""
54
out, err = self.run_bzr(['commit', '--help'])
54
out, err = self.run_bzr_captured(['commit', '--help'])
55
55
self.assertContainsRe(out, r'--file(.|\n)*file containing commit'
57
57
self.assertContainsRe(out, r'-h.*--help')
59
59
def test_option_help_global(self):
60
60
"""Global options have help strings."""
61
out, err = self.run_bzr(['help', 'status'])
61
out, err = self.run_bzr_captured(['help', 'status'])
62
62
self.assertContainsRe(out, r'--show-ids.*show internal object')
64
64
def test_option_arg_help(self):
65
65
"""Help message shows option arguments."""
66
out, err = self.run_bzr(['help', 'commit'])
66
out, err = self.run_bzr_captured(['help', 'commit'])
67
67
self.assertEquals(err, '')
68
68
self.assertContainsRe(out, r'--file[ =]MSGFILE')
70
70
def test_unknown_short_opt(self):
71
out, err = self.run_bzr(['help', '-r'], retcode=3)
71
out, err = self.run_bzr_captured(['help', '-r'], retcode=3)
72
72
self.assertContainsRe(err, r'no such option')
74
74
def test_get_short_name(self):
113
113
def test_allow_dash(self):
114
114
"""Test that we can pass a plain '-' as an argument."""
116
(['-'], {'fixes': []}), parse_args(cmd_commit(), ['-']))
115
self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
118
117
def parse(self, options, args):
119
118
parser = option.get_optparser(dict((o.name, o) for o in options))
232
231
('two', None, None, 'two help'),
236
class TestListOptions(TestCase):
237
"""Tests for ListOption, used to specify lists on the command-line."""
239
def parse(self, options, args):
240
parser = option.get_optparser(dict((o.name, o) for o in options))
241
return parser.parse_args(args)
243
def test_list_option(self):
244
options = [option.ListOption('hello', type=str)]
245
opts, args = self.parse(options, ['--hello=world', '--hello=sailor'])
246
self.assertEqual(['world', 'sailor'], opts.hello)
248
def test_list_option_no_arguments(self):
249
options = [option.ListOption('hello', type=str)]
250
opts, args = self.parse(options, [])
251
self.assertEqual([], opts.hello)
253
def test_list_option_with_int_type(self):
254
options = [option.ListOption('hello', type=int)]
255
opts, args = self.parse(options, ['--hello=2', '--hello=3'])
256
self.assertEqual([2, 3], opts.hello)
258
def test_list_option_with_int_type_can_be_reset(self):
259
options = [option.ListOption('hello', type=int)]
260
opts, args = self.parse(options, ['--hello=2', '--hello=3',
261
'--hello=-', '--hello=5'])
262
self.assertEqual([5], opts.hello)
264
def test_list_option_can_be_reset(self):
265
"""Passing an option of '-' to a list option should reset the list."""
266
options = [option.ListOption('hello', type=str)]
267
opts, args = self.parse(
268
options, ['--hello=a', '--hello=b', '--hello=-', '--hello=c'])
269
self.assertEqual(['c'], opts.hello)
234
# >>> parse_args('log -r 500'.split())
235
# (['log'], {'revision': [<RevisionSpec_int 500>]})
236
# >>> parse_args('log -r500..600'.split())
237
# (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
238
# >>> parse_args('log -vr500..600'.split())
239
# (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
240
# >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
241
# (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})