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
18
18
"""Black-box tests for bzr help.
28
from bzrlib.tests.test_i18n import ZzzTranslations
31
class TestHelp(tests.TestCaseWithTransport):
23
from bzrlib.tests.blackbox import ExternalBase
24
from bzrlib.config import (ensure_config_dir_exists, config_filename)
27
class TestHelp(ExternalBase):
33
29
def test_help_basic(self):
34
30
for cmd in ['--help', 'help', '-h', '-?']:
62
58
out, err = self.run_bzr('help checkouts')
63
59
self.assertContainsRe(out, 'checkout')
64
60
self.assertContainsRe(out, 'lightweight')
66
62
def test_help_urlspec(self):
67
63
"""Smoke test for 'bzr help urlspec'"""
68
64
out, err = self.run_bzr('help urlspec')
108
104
self.assertEquals(dash_help, qmark_long)
109
105
self.assertEquals(dash_help, qmark_cmds)
111
def test_help_width_zero(self):
112
self.overrideEnv('BZR_COLUMNS', '0')
113
self.run_bzr('help commands')
115
107
def test_hidden(self):
116
help_commands = self.run_bzr('help commands')[0]
117
help_hidden = self.run_bzr('help hidden-commands')[0]
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
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]
131
commands = extract_cmd_names(help_commands)
132
hidden = extract_cmd_names(help_hidden)
108
commands = self.run_bzr('help commands')[0]
109
hidden = self.run_bzr('help hidden-commands')[0]
133
110
self.assertTrue('commit' in commands)
134
111
self.assertTrue('commit' not in hidden)
135
112
self.assertTrue('rocks' in hidden)
136
113
self.assertTrue('rocks' not in commands)
138
115
def test_help_detail(self):
139
dash_h = self.run_bzr('diff -h')[0]
140
help_x = self.run_bzr('help diff')[0]
116
dash_h = self.run_bzr('commit -h')[0]
117
help_x = self.run_bzr('help commit')[0]
118
qmark_x = self.run_bzr('help commit')[0]
141
119
self.assertEquals(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:")
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:")
120
self.assertEquals(dash_h, qmark_x)
160
122
def test_help_help(self):
161
123
help = self.run_bzr('help help')[0]
169
131
def test_help_with_aliases(self):
170
132
original = self.run_bzr('help cat')[0]
172
conf = config.GlobalConfig.from_string('''[ALIASES]
134
ensure_config_dir_exists()
135
CONFIG=("[ALIASES]\n"
139
open(config_filename(),'wb').write(CONFIG)
177
141
expected = original + "'bzr cat' is an alias for 'bzr cat'.\n"
178
142
self.assertEqual(expected, self.run_bzr('help cat')[0])
180
144
self.assertEqual("'bzr c' is an alias for 'bzr cat'.\n",
181
145
self.run_bzr('help c')[0])
184
class TestTranslatedHelp(tests.TestCaseWithTransport):
185
"""Tests for display of translated help topics"""
188
super(TestTranslatedHelp, self).setUp()
189
self.overrideAttr(i18n, '_translations', ZzzTranslations())
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:")
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:")
199
def test_help_command_ascii(self):
200
out, err = self.run_bzr(["help", "push"], encoding="ascii")
201
self.assertContainsRe(out, "zz\\?{{:See also:")
203
def test_help_switch_ascii(self):
204
out, err = self.run_bzr(["push", "--help"], encoding="ascii")
205
self.assertContainsRe(out, "zz\\?{{:See also:")