1185.16.48
by mbp at sourcefrog
- more refactoring of and tests for option parsing |
1 |
# (C) 2005 Canonical
|
2 |
||
1185.31.25
by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py |
3 |
from bzrlib.tests import TestCase |
1185.16.48
by mbp at sourcefrog
- more refactoring of and tests for option parsing |
4 |
from bzrlib.commands import Command, parse_args |
5 |
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status |
|
6 |
||
7 |
||
8 |
class OptionTests(TestCase): |
|
9 |
"""Command-line option tests"""
|
|
10 |
||
11 |
def test_parse_args(self): |
|
12 |
"""Option parser"""
|
|
13 |
eq = self.assertEquals |
|
14 |
eq(parse_args(cmd_commit(), ['--help']), |
|
15 |
([], {'help': True})) |
|
16 |
eq(parse_args(cmd_status(), ['--all']), |
|
17 |
([], {'all': True})) |
|
18 |
eq(parse_args(cmd_commit(), ['--message=biter']), |
|
19 |
([], {'message': 'biter'})) |
|
20 |
## eq(parse_args(cmd_log(), '-r 500'.split()),
|
|
21 |
## ([], {'revision': RevisionSpec_int(500)}))
|
|
22 |
||
1185.16.49
by mbp at sourcefrog
- more refactoring and tests of commandline |
23 |
def test_no_more_opts(self): |
24 |
"""Terminated options"""
|
|
25 |
self.assertEquals(parse_args(cmd_commit(), ['--', '-file-with-dashes']), |
|
26 |
(['-file-with-dashes'], {})) |
|
27 |
||
1185.16.48
by mbp at sourcefrog
- more refactoring of and tests for option parsing |
28 |
def test_option_help(self): |
29 |
"""Options have help strings."""
|
|
30 |
out, err = self.run_bzr_captured(['commit', '--help']) |
|
31 |
self.assertContainsRe(out, r'--file.*file containing commit message') |
|
1185.25.3
by Aaron Bentley
Restored short options in help |
32 |
self.assertContainsRe(out, r'--help.*-h') |
1185.16.48
by mbp at sourcefrog
- more refactoring of and tests for option parsing |
33 |
|
34 |
def test_option_help_global(self): |
|
35 |
"""Global options have help strings."""
|
|
36 |
out, err = self.run_bzr_captured(['help', 'status']) |
|
37 |
self.assertContainsRe(out, r'--show-ids.*show internal object') |
|
38 |
||
39 |
def test_option_arg_help(self): |
|
40 |
"""Help message shows option arguments."""
|
|
41 |
out, err = self.run_bzr_captured(['help', 'commit']) |
|
42 |
self.assertEquals(err, '') |
|
43 |
self.assertContainsRe(out, r'--file[ =]MSGFILE') |
|
44 |
||
1185.35.24
by Aaron Bentley
Fixed handling of short options not accepted by the command |
45 |
def test_unknown_short_opt(self): |
46 |
out, err = self.run_bzr_captured(['help', '-r'], retcode=3) |
|
47 |
self.assertContainsRe(err, r'unknown short option') |
|
48 |
||
1185.16.48
by mbp at sourcefrog
- more refactoring of and tests for option parsing |
49 |
|
50 |
# >>> parse_args('log -r 500'.split())
|
|
51 |
# (['log'], {'revision': [<RevisionSpec_int 500>]})
|
|
52 |
# >>> parse_args('log -r500..600'.split())
|
|
53 |
# (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
|
|
54 |
# >>> parse_args('log -vr500..600'.split())
|
|
55 |
# (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
|
|
56 |
# >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
|
|
57 |
# (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})
|