1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
2
# Copyright (C) 2017-2018 Breezy developers
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Blackbox tests for plugins behaviour and commands."""
25
from ..test_plugins import (
30
class TestPluginHelp(BaseTestPlugins):
32
def run_bzr_utf8_out(self, *args, **kwargs):
33
out, _ = self.run_bzr(*args, **kwargs)
36
def split_help_commands(self):
39
out = self.run_bzr_utf8_out('--no-plugins help commands')
40
for line in out.splitlines():
41
if not line.startswith(' '):
42
current = line.split()[0]
43
help[current] = help.get(current, '') + line
47
def test_plugin_help_builtins_unaffected(self):
48
# Check we don't get false positives
49
help_commands = self.split_help_commands()
50
for cmd_name in commands.builtin_command_names():
51
if cmd_name in commands.plugin_command_names():
54
help = commands.get_cmd_object(cmd_name).get_help_text()
55
except NotImplementedError:
56
# some commands have no help
59
self.assertNotContainsRe(help, 'plugin "[^"]*"')
61
if cmd_name in help_commands:
62
# some commands are hidden
63
help = help_commands[cmd_name]
64
self.assertNotContainsRe(help, 'plugin "[^"]*"')
66
def test_plugin_help_shows_plugin(self):
67
# Create a test plugin
68
os.mkdir('plugin_test')
70
"from breezy import commands\n"
71
"class cmd_myplug(commands.Command):\n"
72
" __doc__ = '''Just a simple test plugin.'''\n"
73
" aliases = ['mplg']\n"
75
" print ('Hello from my plugin')\n"
77
self.create_plugin('myplug', source, 'plugin_test')
80
self.load_with_paths(['plugin_test'])
81
myplug = self.plugins['myplug'].module
82
commands.register_command(myplug.cmd_myplug)
83
self.addCleanup(commands.plugin_cmds.remove, 'myplug')
84
help = self.run_bzr_utf8_out('help myplug')
85
self.assertContainsRe(help, 'plugin "myplug"')
86
help = self.split_help_commands()['myplug']
87
self.assertContainsRe(help, '\\[myplug\\]')