~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2010-06-17 08:53:15 UTC
  • mfrom: (5300 +trunk)
  • mto: (5303.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5305.
  • Revision ID: bialix@ukr.net-20100617085315-hr8186zck57zn35s
merge bzr.dev; fix NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import bzrlib
18
18
from bzrlib import commands, tests
 
19
from bzrlib.tests import features
19
20
from bzrlib.plugins.bash_completion.bashcomp import *
20
21
 
21
22
import os
25
26
class BashCompletionMixin(object):
26
27
    """Component for testing execution of a bash completion script."""
27
28
 
28
 
    _test_needs_features = [tests.features.bash_feature]
 
29
    _test_needs_features = [features.bash_feature]
29
30
 
30
31
    def complete(self, words, cword=-1):
31
32
        """Perform a bash completion.
35
36
        """
36
37
        if self.script is None:
37
38
            self.script = self.get_script()
38
 
        proc = subprocess.Popen([tests.features.bash_feature.path,
 
39
        proc = subprocess.Popen([features.bash_feature.path,
39
40
                                 '--noprofile'],
40
41
                                stdin=subprocess.PIPE,
41
42
                                stdout=subprocess.PIPE,
163
164
        return s.replace("$(bzr ", "$('%s' " % self.get_bzr_path())
164
165
 
165
166
    def test_revspec_tag_all(self):
166
 
        self.requireFeature(tests.features.sed_feature)
 
167
        self.requireFeature(features.sed_feature)
167
168
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
168
169
        wt.branch.tags.set_tag('tag1', 'null:')
169
170
        wt.branch.tags.set_tag('tag2', 'null:')
172
173
        self.assertCompletionEquals('tag1', 'tag2', '3tag')
173
174
 
174
175
    def test_revspec_tag_prefix(self):
175
 
        self.requireFeature(tests.features.sed_feature)
 
176
        self.requireFeature(features.sed_feature)
176
177
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
177
178
        wt.branch.tags.set_tag('tag1', 'null:')
178
179
        wt.branch.tags.set_tag('tag2', 'null:')
180
181
        self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
181
182
        self.assertCompletionEquals('tag1', 'tag2')
182
183
 
 
184
    def test_revspec_tag_spaces(self):
 
185
        self.requireFeature(features.sed_feature)
 
186
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
 
187
        wt.branch.tags.set_tag('tag with spaces', 'null:')
 
188
        self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
 
189
        self.assertCompletionEquals(r'tag\ with\ spaces')
 
190
        self.complete(['bzr', 'log', '-r', '"tag:t'])
 
191
        self.assertCompletionEquals('tag:tag with spaces')
 
192
        self.complete(['bzr', 'log', '-r', "'tag:t"])
 
193
        self.assertCompletionEquals('tag:tag with spaces')
 
194
 
 
195
    def test_revspec_tag_endrange(self):
 
196
        self.requireFeature(features.sed_feature)
 
197
        wt = self.make_branch_and_tree('.', format='dirstate-tags')
 
198
        wt.branch.tags.set_tag('tag1', 'null:')
 
199
        wt.branch.tags.set_tag('tag2', 'null:')
 
200
        self.complete(['bzr', 'log', '-r', '3..tag', ':', 't'])
 
201
        self.assertCompletionEquals('tag1', 'tag2')
 
202
        self.complete(['bzr', 'log', '-r', '"3..tag:t'])
 
203
        self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
 
204
        self.complete(['bzr', 'log', '-r', "'3..tag:t"])
 
205
        self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
 
206
 
183
207
 
184
208
class TestBashCodeGen(tests.TestCase):
185
209
 
226
250
        cg = BashCodeGen(data)
227
251
        self.assertEqualDiff('''\
228
252
\tbar|baz)
229
 
\t\tcmdOpts='--opt'
 
253
\t\tcmdOpts=( --opt )
230
254
\t\t;;
231
255
\tfoo)
232
 
\t\tcmdOpts=''
 
256
\t\tcmdOpts=(  )
233
257
\t\t;;
234
258
''', cg.command_cases())
235
259
 
248
272
\tcmd)
249
273
\t\t# plugin "plugger 1.0"
250
274
\t\t# Some error message
251
 
\t\tcmdOpts='--bar=that --bar=this --foo'
 
275
\t\tcmdOpts=( --bar=that --bar=this --foo )
252
276
\t\tcase $curOpt in
253
 
\t\t\t--bar) optEnums='that this' ;;
 
277
\t\t\t--bar) optEnums=( that this ) ;;
254
278
\t\tesac
255
279
\t\t;;
256
280
''', cg.command_case(cmd))
274
298
        self.assertSubset(['init', 'init-repo', 'init-repository'],
275
299
                           dc.data.all_command_aliases())
276
300
 
 
301
    def test_commands_from_plugins(self):
 
302
        dc = DataCollector()
 
303
        dc.commands()
 
304
        self.assertSubset(['bash-completion'],
 
305
                           dc.data.all_command_aliases())
 
306
 
277
307
    def test_commit_dashm(self):
278
308
        dc = DataCollector()
279
309
        cmd = dc.command('commit')