~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_help.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-28 06:58:22 UTC
  • mfrom: (2379.2.3 hpss-chroot)
  • Revision ID: pqm@pqm.ubuntu.com-20070328065822-999550a858a3ced3
(robertc) Fix chroot urls to not expose the url of the transport they are protecting, allowing regular url operations to work on them. (Robert Collins, Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr help.
19
19
"""
20
20
 
21
21
 
22
 
from bzrlib import (
23
 
    config,
24
 
    i18n,
25
 
    tests,
26
 
    )
27
 
 
28
 
from bzrlib.tests.test_i18n import ZzzTranslations
29
 
 
30
 
 
31
 
class TestHelp(tests.TestCaseWithTransport):
 
22
from bzrlib.tests.blackbox import ExternalBase
 
23
 
 
24
 
 
25
class TestHelp(ExternalBase):
32
26
 
33
27
    def test_help_basic(self):
34
28
        for cmd in ['--help', 'help', '-h', '-?']:
35
 
            output = self.run_bzr(cmd)[0]
 
29
            output = self.runbzr(cmd)[0]
36
30
            line1 = output.split('\n')[0]
37
31
            if not line1.startswith('Bazaar'):
38
32
                self.fail("bad output from bzr %s:\n%r" % (cmd, output))
40
34
 
41
35
    def test_help_topics(self):
42
36
        """Smoketest for 'bzr help topics'"""
43
 
        out, err = self.run_bzr('help topics')
 
37
        out, err = self.run_bzr('help', 'topics')
44
38
        self.assertContainsRe(out, 'basic')
45
39
        self.assertContainsRe(out, 'topics')
46
40
        self.assertContainsRe(out, 'commands')
48
42
 
49
43
    def test_help_revisionspec(self):
50
44
        """Smoke test for 'bzr help revisionspec'"""
51
 
        out, err = self.run_bzr('help revisionspec')
 
45
        out, err = self.run_bzr('help', 'revisionspec')
52
46
        self.assertContainsRe(out, 'revno:')
53
47
        self.assertContainsRe(out, 'date:')
54
48
        self.assertContainsRe(out, 'revid:')
59
53
 
60
54
    def test_help_checkouts(self):
61
55
        """Smoke test for 'bzr help checkouts'"""
62
 
        out, err = self.run_bzr('help checkouts')
 
56
        out, err = self.runbzr('help checkouts')
63
57
        self.assertContainsRe(out, 'checkout')
64
58
        self.assertContainsRe(out, 'lightweight')
65
59
 
66
 
    def test_help_urlspec(self):
67
 
        """Smoke test for 'bzr help urlspec'"""
68
 
        out, err = self.run_bzr('help urlspec')
69
 
        self.assertContainsRe(out, 'aftp://')
70
 
        self.assertContainsRe(out, 'bzr://')
71
 
        self.assertContainsRe(out, 'bzr\+ssh://')
72
 
        self.assertContainsRe(out, 'file://')
73
 
        self.assertContainsRe(out, 'ftp://')
74
 
        self.assertContainsRe(out, 'http://')
75
 
        self.assertContainsRe(out, 'https://')
76
 
        self.assertContainsRe(out, 'sftp://')
77
 
 
78
 
    def test_help_repositories(self):
79
 
        """Smoke test for 'bzr help repositories'"""
80
 
        out, err = self.run_bzr('help repositories')
81
 
        from bzrlib.help_topics import help_as_plain_text, _repositories
82
 
        expected = help_as_plain_text(_repositories)
83
 
        self.assertEqual(expected, out)
84
 
 
85
 
    def test_help_working_trees(self):
86
 
        """Smoke test for 'bzr help working-trees'"""
87
 
        out, err = self.run_bzr('help working-trees')
88
 
        from bzrlib.help_topics import help_as_plain_text, _working_trees
89
 
        expected = help_as_plain_text(_working_trees)
90
 
        self.assertEqual(expected, out)
91
 
 
92
 
    def test_help_status_flags(self):
93
 
        """Smoke test for 'bzr help status-flags'"""
94
 
        out, err = self.run_bzr('help status-flags')
95
 
        from bzrlib.help_topics import help_as_plain_text, _status_flags
96
 
        expected = help_as_plain_text(_status_flags)
97
 
        self.assertEqual(expected, out)
98
 
 
99
60
    def test_help_commands(self):
100
 
        dash_help  = self.run_bzr('--help commands')[0]
101
 
        commands   = self.run_bzr('help commands')[0]
102
 
        hidden = self.run_bzr('help hidden-commands')[0]
103
 
        long_help  = self.run_bzr('help --long')[0]
104
 
        qmark_long = self.run_bzr('? --long')[0]
105
 
        qmark_cmds = self.run_bzr('? commands')[0]
106
 
        self.assertEqual(dash_help, commands)
107
 
        self.assertEqual(dash_help, long_help)
108
 
        self.assertEqual(dash_help, qmark_long)
109
 
        self.assertEqual(dash_help, qmark_cmds)
110
 
 
111
 
    def test_help_width_zero(self):
112
 
        self.overrideEnv('BZR_COLUMNS', '0')
113
 
        self.run_bzr('help commands')
 
61
        dash_help  = self.runbzr('--help commands')[0]
 
62
        commands   = self.runbzr('help commands')[0]
 
63
        hidden = self.runbzr('help hidden-commands')[0]
 
64
        long_help  = self.runbzr('help --long')[0]
 
65
        qmark_long = self.runbzr('? --long')[0]
 
66
        qmark_cmds = self.runbzr('? commands')[0]
 
67
        self.assertEquals(dash_help, commands)
 
68
        self.assertEquals(dash_help, long_help)
 
69
        self.assertEquals(dash_help, qmark_long)
 
70
        self.assertEquals(dash_help, qmark_cmds)
114
71
 
115
72
    def test_hidden(self):
116
 
        help_commands = self.run_bzr('help commands')[0]
117
 
        help_hidden = self.run_bzr('help hidden-commands')[0]
118
 
 
119
 
        def extract_cmd_names(help_output):
120
 
            # keep only the command names to avoid matching on help text (there
121
 
            # is a high risk to fail a test when a plugin get installed
122
 
            # otherwise)
123
 
            cmds = []
124
 
            for line in help_output.split('\n'):
125
 
                if line.startswith(' '):
126
 
                    continue # help on more than one line
127
 
                cmd = line.split(' ')[0]
128
 
                if line:
129
 
                    cmds.append(cmd)
130
 
            return cmds
131
 
        commands = extract_cmd_names(help_commands)
132
 
        hidden = extract_cmd_names(help_hidden)
 
73
        commands = self.runbzr('help commands')[0]
 
74
        hidden = self.runbzr('help hidden-commands')[0]
133
75
        self.assertTrue('commit' in commands)
134
76
        self.assertTrue('commit' not in hidden)
135
77
        self.assertTrue('rocks' in hidden)
136
78
        self.assertTrue('rocks' not in commands)
137
79
 
138
80
    def test_help_detail(self):
139
 
        dash_h  = self.run_bzr('diff -h')[0]
140
 
        help_x  = self.run_bzr('help diff')[0]
141
 
        self.assertEqual(dash_h, help_x)
142
 
        self.assertContainsRe(help_x, "Purpose:")
143
 
        self.assertContainsRe(help_x, "Usage:")
144
 
        self.assertContainsRe(help_x, "Options:")
145
 
        self.assertContainsRe(help_x, "Description:")
146
 
        self.assertContainsRe(help_x, "Examples:")
147
 
        self.assertContainsRe(help_x, "See also:")
148
 
        self.assertContainsRe(help_x, "Aliases:")
149
 
 
150
 
    def test_help_usage(self):
151
 
        usage  = self.run_bzr('diff --usage')[0]
152
 
        self.assertContainsRe(usage, "Purpose:")
153
 
        self.assertContainsRe(usage, "Usage:")
154
 
        self.assertContainsRe(usage, "Options:")
155
 
        self.assertNotContainsRe(usage, "Description:")
156
 
        self.assertNotContainsRe(usage, "Examples:")
157
 
        self.assertContainsRe(usage, "See also:")
158
 
        self.assertContainsRe(usage, "Aliases:")
 
81
        dash_h  = self.runbzr('commit -h')[0]
 
82
        help_x  = self.runbzr('help commit')[0]
 
83
        qmark_x = self.runbzr('help commit')[0]
 
84
        self.assertEquals(dash_h, help_x)
 
85
        self.assertEquals(dash_h, qmark_x)
159
86
 
160
87
    def test_help_help(self):
161
 
        help = self.run_bzr('help help')[0]
162
 
        qmark = self.run_bzr('? ?')[0]
163
 
        self.assertEqual(help, qmark)
 
88
        help = self.runbzr('help help')[0]
 
89
        qmark = self.runbzr('? ?')[0]
 
90
        self.assertEquals(help, qmark)
164
91
        for line in help.split('\n'):
165
92
            if '--long' in line:
166
 
                self.assertContainsRe(line,
167
 
                    r'Show help on all commands\.')
168
 
 
169
 
    def test_help_with_aliases(self):
170
 
        original = self.run_bzr('help cat')[0]
171
 
 
172
 
        conf = config.GlobalConfig.from_string('''[ALIASES]
173
 
c=cat
174
 
cat=cat
175
 
''', save=True)
176
 
 
177
 
        expected = original + "'bzr cat' is an alias for 'bzr cat'.\n"
178
 
        self.assertEqual(expected, self.run_bzr('help cat')[0])
179
 
 
180
 
        self.assertEqual("'bzr c' is an alias for 'bzr cat'.\n",
181
 
                         self.run_bzr('help c')[0])
182
 
 
183
 
 
184
 
class TestTranslatedHelp(tests.TestCaseWithTransport):
185
 
    """Tests for display of translated help topics"""
186
 
 
187
 
    def setUp(self):
188
 
        super(TestTranslatedHelp, self).setUp()
189
 
        self.overrideAttr(i18n, '_translations', ZzzTranslations())
190
 
 
191
 
    def test_help_command_utf8(self):
192
 
        out, err = self.run_bzr(["help", "push"], encoding="utf-8")
193
 
        self.assertContainsRe(out, "zz\xc3\xa5{{:See also:")
194
 
 
195
 
    def test_help_switch_utf8(self):
196
 
        out, err = self.run_bzr(["push", "--help"], encoding="utf-8")
197
 
        self.assertContainsRe(out, "zz\xc3\xa5{{:See also:")
198
 
 
199
 
    def test_help_command_ascii(self):
200
 
        out, err = self.run_bzr(["help", "push"], encoding="ascii")
201
 
        self.assertContainsRe(out, "zz\\?{{:See also:")
202
 
 
203
 
    def test_help_switch_ascii(self):
204
 
        out, err = self.run_bzr(["push", "--help"], encoding="ascii")
205
 
        self.assertContainsRe(out, "zz\\?{{:See also:")
 
93
                self.assertTrue('show help on all commands' in line)
 
94