/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugins/bash_completion/tests/test_bashcomp.py

merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
 
17
import sys
 
18
 
17
19
import bzrlib
18
20
from bzrlib import commands, tests
 
21
from bzrlib.tests import features
19
22
from bzrlib.plugins.bash_completion.bashcomp import *
20
23
 
21
24
import os
25
28
class BashCompletionMixin(object):
26
29
    """Component for testing execution of a bash completion script."""
27
30
 
28
 
    _test_needs_features = [tests.features.bash_feature]
 
31
    _test_needs_features = [features.bash_feature]
 
32
    script = None
29
33
 
30
34
    def complete(self, words, cword=-1):
31
35
        """Perform a bash completion.
35
39
        """
36
40
        if self.script is None:
37
41
            self.script = self.get_script()
38
 
        proc = subprocess.Popen([tests.features.bash_feature.path,
 
42
        proc = subprocess.Popen([features.bash_feature.path,
39
43
                                 '--noprofile'],
40
44
                                stdin=subprocess.PIPE,
41
45
                                stdout=subprocess.PIPE,
94
98
class TestBashCompletion(tests.TestCase, BashCompletionMixin):
95
99
    """Test bash completions that don't execute bzr."""
96
100
 
97
 
    def __init__(self, methodName='testMethod'):
98
 
        super(TestBashCompletion, self).__init__(methodName)
99
 
        self.script = None
100
 
 
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.
155
155
    """
156
156
 
157
 
    def __init__(self, methodName='testMethod'):
158
 
        super(TestBashCompletionInvoking, self).__init__(methodName)
159
 
        self.script = None
 
157
    def setUp(self):
 
158
        super(TestBashCompletionInvoking, self).setUp()
 
159
        if sys.platform == 'win32':
 
160
            raise tests.KnownFailure(
 
161
                'see bug #709104, completion is broken on windows')
160
162
 
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())
164
166
 
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')
173
175
 
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')
182
184
 
 
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')
 
195
 
 
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')
 
207
 
183
208
 
184
209
class TestBashCodeGen(tests.TestCase):
185
210
 
226
251
        cg = BashCodeGen(data)
227
252
        self.assertEqualDiff('''\
228
253
\tbar|baz)
229
 
\t\tcmdOpts='--opt'
 
254
\t\tcmdOpts=( --opt )
230
255
\t\t;;
231
256
\tfoo)
232
 
\t\tcmdOpts=''
 
257
\t\tcmdOpts=(  )
233
258
\t\t;;
234
259
''', cg.command_cases())
235
260
 
248
273
\tcmd)
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 ) ;;
254
279
\t\tesac
255
280
\t\t;;
256
281
''', cg.command_case(cmd))
274
299
        self.assertSubset(['init', 'init-repo', 'init-repository'],
275
300
                           dc.data.all_command_aliases())
276
301
 
 
302
    def test_commands_from_plugins(self):
 
303
        dc = DataCollector()
 
304
        dc.commands()
 
305
        self.assertSubset(['bash-completion'],
 
306
                           dc.data.all_command_aliases())
 
307
 
277
308
    def test_commit_dashm(self):
278
309
        dc = DataCollector()
279
310
        cmd = dc.command('commit')