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
18
20
from bzrlib import commands, tests
21
from bzrlib.tests import features
19
22
from bzrlib.plugins.bash_completion.bashcomp import *
25
28
class BashCompletionMixin(object):
26
29
"""Component for testing execution of a bash completion script."""
28
_test_needs_features = [tests.features.bash_feature]
31
_test_needs_features = [features.bash_feature]
30
34
def complete(self, words, cword=-1):
31
35
"""Perform a bash completion.
94
98
class TestBashCompletion(tests.TestCase, BashCompletionMixin):
95
99
"""Test bash completions that don't execute bzr."""
97
def __init__(self, methodName='testMethod'):
98
super(TestBashCompletion, self).__init__(methodName)
101
101
def test_simple_scipt(self):
102
102
"""Ensure that the test harness works as expected"""
103
103
self.script = """
154
154
will be replaced by the bzr instance running this selftest.
157
def __init__(self, methodName='testMethod'):
158
super(TestBashCompletionInvoking, self).__init__(methodName)
158
super(TestBashCompletionInvoking, self).setUp()
159
if sys.platform == 'win32':
160
raise tests.KnownFailure(
161
'see bug #709104, completion is broken on windows')
161
163
def get_script(self):
162
164
s = super(TestBashCompletionInvoking, self).get_script()
163
165
return s.replace("$(bzr ", "$('%s' " % self.get_bzr_path())
165
167
def test_revspec_tag_all(self):
166
self.requireFeature(tests.features.sed_feature)
168
self.requireFeature(features.sed_feature)
167
169
wt = self.make_branch_and_tree('.', format='dirstate-tags')
168
170
wt.branch.tags.set_tag('tag1', 'null:')
169
171
wt.branch.tags.set_tag('tag2', 'null:')
172
174
self.assertCompletionEquals('tag1', 'tag2', '3tag')
174
176
def test_revspec_tag_prefix(self):
175
self.requireFeature(tests.features.sed_feature)
177
self.requireFeature(features.sed_feature)
176
178
wt = self.make_branch_and_tree('.', format='dirstate-tags')
177
179
wt.branch.tags.set_tag('tag1', 'null:')
178
180
wt.branch.tags.set_tag('tag2', 'null:')
180
182
self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
181
183
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')
184
209
class TestBashCodeGen(tests.TestCase):
249
274
\t\t# plugin "plugger 1.0"
250
275
\t\t# Some error message
251
\t\tcmdOpts='--bar=that --bar=this --foo'
276
\t\tcmdOpts=( --bar=that --bar=this --foo )
252
277
\t\tcase $curOpt in
253
\t\t\t--bar) optEnums='that this' ;;
278
\t\t\t--bar) optEnums=( that this ) ;;
256
281
''', cg.command_case(cmd))
274
299
self.assertSubset(['init', 'init-repo', 'init-repository'],
275
300
dc.data.all_command_aliases())
302
def test_commands_from_plugins(self):
305
self.assertSubset(['bash-completion'],
306
dc.data.all_command_aliases())
277
308
def test_commit_dashm(self):
278
309
dc = DataCollector()
279
310
cmd = dc.command('commit')