14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from bzrlib.tests import TestCase, TestCaseWithTransport, Feature
18
from bzrlib import commands
19
from StringIO import StringIO
20
from ..bashcomp import *
20
from bzrlib import commands, tests
21
from bzrlib.tests import features
22
from bzrlib.plugins.bash_completion.bashcomp import *
26
class _BashFeature(Feature):
27
"""Feature testing whether a bash executable is available."""
29
bash_paths = ['/bin/bash', '/usr/bin/bash']
32
super(_BashFeature, self).__init__()
36
if self.bash_path is not None:
37
return self.bash_path is not False
38
for path in self.bash_paths:
39
if os.access(path, os.X_OK):
42
self.bash_path = False
45
def feature_name(self):
48
BashFeature = _BashFeature()
28
51
class BashCompletionMixin(object):
29
52
"""Component for testing execution of a bash completion script."""
31
_test_needs_features = [features.bash_feature]
54
_test_needs_features = [BashFeature]
34
56
def complete(self, words, cword=-1):
35
57
"""Perform a bash completion.
87
108
% (surplus, res, self.completion_result))
89
110
def get_script(self):
90
commands.install_bzr_command_hooks()
93
cg = BashCodeGen(data)
98
class TestBashCompletion(tests.TestCase, BashCompletionMixin):
112
bash_completion_function(out, function_only=True)
113
return out.getvalue()
116
class TestBashCompletion(TestCase, BashCompletionMixin):
99
117
"""Test bash completions that don't execute bzr."""
119
def __init__(self, methodName='testMethod'):
120
super(TestBashCompletion, self).__init__(methodName)
124
super(TestBashCompletion, self).setUp()
125
commands.install_bzr_command_hooks()
101
127
def test_simple_scipt(self):
102
128
"""Ensure that the test harness works as expected"""
103
129
self.script = """
146
172
self.assertCompletionOmits('1.9')
149
class TestBashCompletionInvoking(tests.TestCaseWithTransport,
150
BashCompletionMixin):
175
class TestBashCompletionInvoking(TestCaseWithTransport, BashCompletionMixin):
151
176
"""Test bash completions that might execute bzr.
153
178
Only the syntax ``$(bzr ...`` is supported so far. The bzr command
154
179
will be replaced by the bzr instance running this selftest.
182
def __init__(self, methodName='testMethod'):
183
super(TestBashCompletionInvoking, self).__init__(methodName)
158
187
super(TestBashCompletionInvoking, self).setUp()
159
if sys.platform == 'win32':
160
raise tests.KnownFailure(
161
'see bug #709104, completion is broken on windows')
188
commands.install_bzr_command_hooks()
163
190
def get_script(self):
164
191
s = super(TestBashCompletionInvoking, self).get_script()
165
192
return s.replace("$(bzr ", "$('%s' " % self.get_bzr_path())
167
194
def test_revspec_tag_all(self):
168
self.requireFeature(features.sed_feature)
169
195
wt = self.make_branch_and_tree('.', format='dirstate-tags')
170
196
wt.branch.tags.set_tag('tag1', 'null:')
171
197
wt.branch.tags.set_tag('tag2', 'null:')
174
200
self.assertCompletionEquals('tag1', 'tag2', '3tag')
176
202
def test_revspec_tag_prefix(self):
177
self.requireFeature(features.sed_feature)
178
203
wt = self.make_branch_and_tree('.', format='dirstate-tags')
179
204
wt.branch.tags.set_tag('tag1', 'null:')
180
205
wt.branch.tags.set_tag('tag2', 'null:')
182
207
self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
183
208
self.assertCompletionEquals('tag1', 'tag2')
185
def test_revspec_tag_spaces(self):
186
self.requireFeature(features.sed_feature)
187
wt = self.make_branch_and_tree('.', format='dirstate-tags')
188
wt.branch.tags.set_tag('tag with spaces', 'null:')
189
self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
190
self.assertCompletionEquals(r'tag\ with\ spaces')
191
self.complete(['bzr', 'log', '-r', '"tag:t'])
192
self.assertCompletionEquals('tag:tag with spaces')
193
self.complete(['bzr', 'log', '-r', "'tag:t"])
194
self.assertCompletionEquals('tag:tag with spaces')
196
def test_revspec_tag_endrange(self):
197
self.requireFeature(features.sed_feature)
198
wt = self.make_branch_and_tree('.', format='dirstate-tags')
199
wt.branch.tags.set_tag('tag1', 'null:')
200
wt.branch.tags.set_tag('tag2', 'null:')
201
self.complete(['bzr', 'log', '-r', '3..tag', ':', 't'])
202
self.assertCompletionEquals('tag1', 'tag2')
203
self.complete(['bzr', 'log', '-r', '"3..tag:t'])
204
self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
205
self.complete(['bzr', 'log', '-r', "'3..tag:t"])
206
self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
209
class TestBashCodeGen(tests.TestCase):
211
class TestBashCodeGen(TestCase):
211
213
def test_command_names(self):
212
214
data = CompletionData()
274
276
\t\t# plugin "plugger 1.0"
275
277
\t\t# Some error message
276
\t\tcmdOpts=( --bar=that --bar=this --foo )
278
\t\tcmdOpts='--bar=that --bar=this --foo'
277
279
\t\tcase $curOpt in
278
\t\t\t--bar) optEnums=( that this ) ;;
280
\t\t\t--bar) optEnums='that this' ;;
281
283
''', cg.command_case(cmd))
284
class TestDataCollector(tests.TestCase):
286
class TestDataCollector(TestCase):
287
289
super(TestDataCollector, self).setUp()
299
301
self.assertSubset(['init', 'init-repo', 'init-repository'],
300
302
dc.data.all_command_aliases())
302
def test_commands_from_plugins(self):
305
self.assertSubset(['bash-completion'],
306
dc.data.all_command_aliases())
308
304
def test_commit_dashm(self):
309
305
dc = DataCollector()
310
306
cmd = dc.command('commit')