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 ...sixish import PY3
26
from ..test_plugins import (
31
class TestPluginHelp(BaseTestPlugins):
33
def run_bzr_utf8_out(self, *args, **kwargs):
34
out, _ = self.run_bzr(*args, **kwargs)
38
return out.decode('utf-8')
40
def split_help_commands(self):
43
out = self.run_bzr_utf8_out('--no-plugins help commands')
44
for line in out.splitlines():
45
if not line.startswith(' '):
46
current = line.split()[0]
47
help[current] = help.get(current, '') + line
51
def test_plugin_help_builtins_unaffected(self):
52
# Check we don't get false positives
53
help_commands = self.split_help_commands()
54
for cmd_name in commands.builtin_command_names():
55
if cmd_name in commands.plugin_command_names():
58
help = commands.get_cmd_object(cmd_name).get_help_text()
59
except NotImplementedError:
60
# some commands have no help
63
self.assertNotContainsRe(help, 'plugin "[^"]*"')
65
if cmd_name in help_commands:
66
# some commands are hidden
67
help = help_commands[cmd_name]
68
self.assertNotContainsRe(help, 'plugin "[^"]*"')
70
def test_plugin_help_shows_plugin(self):
71
# Create a test plugin
72
os.mkdir('plugin_test')
74
"from breezy import commands\n"
75
"class cmd_myplug(commands.Command):\n"
76
" __doc__ = '''Just a simple test plugin.'''\n"
77
" aliases = ['mplg']\n"
79
" print ('Hello from my plugin')\n"
81
self.create_plugin('myplug', source, 'plugin_test')
84
self.load_with_paths(['plugin_test'])
85
myplug = self.plugins['myplug'].module
86
commands.register_command(myplug.cmd_myplug)
87
self.addCleanup(commands.plugin_cmds.remove, 'myplug')
88
help = self.run_bzr_utf8_out('help myplug')
89
self.assertContainsRe(help, 'plugin "myplug"')
90
help = self.split_help_commands()['myplug']
91
self.assertContainsRe(help, '\\[myplug\\]')