~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_options.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 06:52:39 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730065239-03b4ac02d9f56202
branding: change Bazaar-NG to Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
 
 
3
from bzrlib.tests import TestCase
 
4
from bzrlib.commands import Command, parse_args
 
5
from bzrlib.builtins import cmd_commit, cmd_log, cmd_status
 
6
 
 
7
# TODO: might be nice to just parse them into a structured form and test
 
8
# against that, rather than running the whole command.
 
9
 
 
10
class OptionTests(TestCase):
 
11
    """Command-line option tests"""
 
12
 
 
13
    def test_parse_args(self):
 
14
        """Option parser"""
 
15
        eq = self.assertEquals
 
16
        eq(parse_args(cmd_commit(), ['--help']),
 
17
           ([], {'help': 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
 
 
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
 
 
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')
 
32
        self.assertContainsRe(out, r'--help.*-h')
 
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
 
 
45
    def test_unknown_short_opt(self):
 
46
        out, err = self.run_bzr_captured(['help', '-r'], retcode=3)
 
47
        self.assertContainsRe(err, r'unknown option')
 
48
 
 
49
    def test_allow_dash(self):
 
50
        """Test that we can pass a plain '-' as an argument."""
 
51
        self.assertEqual((['-'], {}), parse_args(cmd_commit(), ['-']))
 
52
 
 
53
 
 
54
#     >>> parse_args('log -r 500'.split())
 
55
#     (['log'], {'revision': [<RevisionSpec_int 500>]})
 
56
#     >>> parse_args('log -r500..600'.split())
 
57
#     (['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
58
#     >>> parse_args('log -vr500..600'.split())
 
59
#     (['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
 
60
#     >>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
 
61
#     (['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})