~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
16
17
18
"""Black-box tests for bzr help.
19
"""
20
21
2485.1.2 by James Westby
Update with comments from review, thanks to John and Aaron.
22
import bzrlib
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
23
from bzrlib.tests import TestCaseWithTransport
2743.2.4 by Daniel Watkins
Added blackbox tests to ensure aliases are displayed in help correctly.
24
from bzrlib.config import (ensure_config_dir_exists, config_filename)
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
25
26
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
27
class TestHelp(TestCaseWithTransport):
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
28
29
    def test_help_basic(self):
1616.1.15 by Martin Pool
Handle 'bzr ?', etc.
30
        for cmd in ['--help', 'help', '-h', '-?']:
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
31
            output = self.run_bzr(cmd)[0]
1616.1.15 by Martin Pool
Handle 'bzr ?', etc.
32
            line1 = output.split('\n')[0]
1861.2.6 by Alexander Belchenko
branding: change Bazaar-NG to Bazaar
33
            if not line1.startswith('Bazaar'):
1616.1.15 by Martin Pool
Handle 'bzr ?', etc.
34
                self.fail("bad output from bzr %s:\n%r" % (cmd, output))
1616.1.13 by Martin Pool
Fix 'bzr -h' to show help (#35940)
35
        # see https://launchpad.net/products/bzr/+bug/35940, -h doesn't work
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
36
2023.1.1 by ghigo
add topics help
37
    def test_help_topics(self):
38
        """Smoketest for 'bzr help topics'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
39
        out, err = self.run_bzr('help topics')
2023.1.1 by ghigo
add topics help
40
        self.assertContainsRe(out, 'basic')
41
        self.assertContainsRe(out, 'topics')
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
42
        self.assertContainsRe(out, 'commands')
43
        self.assertContainsRe(out, 'revisionspec')
2023.1.1 by ghigo
add topics help
44
45
    def test_help_revisionspec(self):
46
        """Smoke test for 'bzr help revisionspec'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        out, err = self.run_bzr('help revisionspec')
2023.1.1 by ghigo
add topics help
48
        self.assertContainsRe(out, 'revno:')
49
        self.assertContainsRe(out, 'date:')
2070.4.7 by ghigo
Updates on the basis of the Richard Wilbur suggestions
50
        self.assertContainsRe(out, 'revid:')
51
        self.assertContainsRe(out, 'last:')
52
        self.assertContainsRe(out, 'before:')
53
        self.assertContainsRe(out, 'ancestor:')
54
        self.assertContainsRe(out, 'branch:')
2023.1.1 by ghigo
add topics help
55
2245.7.1 by James Westby
Add a help topic describing checkouts and how they work.
56
    def test_help_checkouts(self):
57
        """Smoke test for 'bzr help checkouts'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
58
        out, err = self.run_bzr('help checkouts')
2245.7.1 by James Westby
Add a help topic describing checkouts and how they work.
59
        self.assertContainsRe(out, 'checkout')
60
        self.assertContainsRe(out, 'lightweight')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
61
2241.2.11 by ghigo
On the basis of Robert Collins and John Arbash Meinel
62
    def test_help_urlspec(self):
63
        """Smoke test for 'bzr help urlspec'"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
64
        out, err = self.run_bzr('help urlspec')
2241.2.11 by ghigo
On the basis of Robert Collins and John Arbash Meinel
65
        self.assertContainsRe(out, 'aftp://')
66
        self.assertContainsRe(out, 'bzr://')
67
        self.assertContainsRe(out, 'bzr\+ssh://')
68
        self.assertContainsRe(out, 'file://')
69
        self.assertContainsRe(out, 'ftp://')
70
        self.assertContainsRe(out, 'http://')
71
        self.assertContainsRe(out, 'https://')
72
        self.assertContainsRe(out, 'sftp://')
73
2401.2.1 by James Westby
Add a help topic for repositories.
74
    def test_help_repositories(self):
75
        """Smoke test for 'bzr help repositories'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
76
        out, err = self.run_bzr('help repositories')
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
77
        from bzrlib.help_topics import help_as_plain_text, _repositories
78
        expected = help_as_plain_text(_repositories)
79
        self.assertEqual(expected, out)
2401.2.1 by James Westby
Add a help topic for repositories.
80
2401.2.2 by James Westby
Add a working-trees help topic.
81
    def test_help_working_trees(self):
82
        """Smoke test for 'bzr help working-trees'"""
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
83
        out, err = self.run_bzr('help working-trees')
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
84
        from bzrlib.help_topics import help_as_plain_text, _working_trees
85
        expected = help_as_plain_text(_working_trees)
86
        self.assertEqual(expected, out)
2401.2.2 by James Westby
Add a working-trees help topic.
87
2520.1.2 by Daniel Watkins
Added test for 'help status-flags'.
88
    def test_help_status_flags(self):
89
        """Smoke test for 'bzr help status-flags'"""
2571.1.2 by Ian Clatworthy
Fix PQM failure - use new test API
90
        out, err = self.run_bzr('help status-flags')
2666.1.1 by Ian Clatworthy
Bazaar User Reference generated from online help
91
        from bzrlib.help_topics import help_as_plain_text, _status_flags
92
        expected = help_as_plain_text(_status_flags)
93
        self.assertEqual(expected, out)
2520.1.2 by Daniel Watkins
Added test for 'help status-flags'.
94
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
95
    def test_help_commands(self):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
96
        dash_help  = self.run_bzr('--help commands')[0]
97
        commands   = self.run_bzr('help commands')[0]
98
        hidden = self.run_bzr('help hidden-commands')[0]
99
        long_help  = self.run_bzr('help --long')[0]
100
        qmark_long = self.run_bzr('? --long')[0]
101
        qmark_cmds = self.run_bzr('? commands')[0]
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
102
        self.assertEquals(dash_help, commands)
103
        self.assertEquals(dash_help, long_help)
104
        self.assertEquals(dash_help, qmark_long)
105
        self.assertEquals(dash_help, qmark_cmds)
106
1551.9.13 by Aaron Bentley
add "hidden" topic
107
    def test_hidden(self):
4960.1.1 by Vincent Ladeuil
Fix brittle test.
108
        help_commands = self.run_bzr('help commands')[0]
109
        help_hidden = self.run_bzr('help hidden-commands')[0]
110
111
        def extract_cmd_names(help_output):
112
            # keep only the command names to avoid matching on help text (there
113
            # is a high risk to fail a test when a plugin get installed
114
            # otherwise)
115
            cmds = []
116
            for line in help_output.split('\n'):
117
                if line.startswith(' '):
118
                    continue # help on more than one line
119
                cmd = line.split(' ')[0]
120
                if line:
121
                    cmds.append(cmd)
122
            return cmds
123
        commands = extract_cmd_names(help_commands)
124
        hidden = extract_cmd_names(help_hidden)
1551.9.13 by Aaron Bentley
add "hidden" topic
125
        self.assertTrue('commit' in commands)
126
        self.assertTrue('commit' not in hidden)
127
        self.assertTrue('rocks' in hidden)
128
        self.assertTrue('rocks' not in commands)
129
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
130
    def test_help_detail(self):
3984.4.5 by Ian Clatworthy
help xxx is full help; xxx -h is concise help
131
        dash_h  = self.run_bzr('diff -h')[0]
132
        help_x  = self.run_bzr('help diff')[0]
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
133
        self.assertEquals(dash_h, help_x)
3984.4.5 by Ian Clatworthy
help xxx is full help; xxx -h is concise help
134
        self.assertContainsRe(help_x, "Purpose:")
135
        self.assertContainsRe(help_x, "Usage:")
136
        self.assertContainsRe(help_x, "Options:")
137
        self.assertContainsRe(help_x, "Description:")
138
        self.assertContainsRe(help_x, "Examples:")
139
        self.assertContainsRe(help_x, "See also:")
140
        self.assertContainsRe(help_x, "Aliases:")
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
141
3984.4.6 by Ian Clatworthy
Show usage on --usage, not -h
142
    def test_help_usage(self):
143
        usage  = self.run_bzr('diff --usage')[0]
144
        self.assertContainsRe(usage, "Purpose:")
145
        self.assertContainsRe(usage, "Usage:")
146
        self.assertContainsRe(usage, "Options:")
147
        self.assertNotContainsRe(usage, "Description:")
148
        self.assertNotContainsRe(usage, "Examples:")
149
        self.assertContainsRe(usage, "See also:")
150
        self.assertContainsRe(usage, "Aliases:")
151
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
152
    def test_help_help(self):
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
153
        help = self.run_bzr('help help')[0]
154
        qmark = self.run_bzr('? ?')[0]
1553.4.3 by Michael Ellerman
Add custom description for help's --long option, this fixes bug #31217.
155
        self.assertEquals(help, qmark)
156
        for line in help.split('\n'):
157
            if '--long' in line:
2598.1.4 by Martin Pool
Fix up tests for option help cleanups
158
                self.assertContainsRe(line,
159
                    r'Show help on all commands\.')
2743.2.4 by Daniel Watkins
Added blackbox tests to ensure aliases are displayed in help correctly.
160
161
    def test_help_with_aliases(self):
162
        original = self.run_bzr('help cat')[0]
163
164
        ensure_config_dir_exists()
165
        CONFIG=("[ALIASES]\n"
166
        "c=cat\n"
167
        "cat=cat\n")
168
169
        open(config_filename(),'wb').write(CONFIG)
170
171
        expected = original + "'bzr cat' is an alias for 'bzr cat'.\n"
172
        self.assertEqual(expected, self.run_bzr('help cat')[0])
173
174
        self.assertEqual("'bzr c' is an alias for 'bzr cat'.\n",
2743.2.6 by Daniel Watkins
Cleaned up indentation in test.
175
                         self.run_bzr('help c')[0])