49
49
input += ('COMP_WORDS=( %s )\n' %
50
50
' '.join(["'"+w.replace("'", "'\\''")+"'" for w in words]))
51
51
input += 'COMP_CWORD=%d\n' % cword
52
input += '%s\n' % getattr(self, 'script_name', '_bzr')
52
input += '%s\n' % getattr(self, 'script_name', '_brz')
53
53
input += 'echo ${#COMPREPLY[*]}\n'
54
54
input += "IFS=$'\\n'\n"
55
55
input += 'echo "${COMPREPLY[*]}"\n'
97
97
class TestBashCompletion(tests.TestCase, BashCompletionMixin):
98
"""Test bash completions that don't execute bzr."""
98
"""Test bash completions that don't execute brz."""
100
100
def test_simple_scipt(self):
101
101
"""Ensure that the test harness works as expected"""
102
102
self.script = """
105
105
# add all words in reverse order, with some markup around them
106
106
for ((i = ${#COMP_WORDS[@]}; i > 0; --i)); do
114
114
self.assertCompletionEquals("-'baz+", '-"bar+', '-foo+', '+"bar-')
116
116
def test_cmd_ini(self):
117
self.complete(['bzr', 'ini'])
117
self.complete(['brz', 'ini'])
118
118
self.assertCompletionContains('init', 'init-repo', 'init-repository')
119
119
self.assertCompletionOmits('commit')
121
121
def test_init_opts(self):
122
self.complete(['bzr', 'init', '-'])
122
self.complete(['brz', 'init', '-'])
123
123
self.assertCompletionContains('-h', '--2a', '--format=2a')
125
125
def test_global_opts(self):
126
self.complete(['bzr', '-', 'init'], cword=1)
126
self.complete(['brz', '-', 'init'], cword=1)
127
127
self.assertCompletionContains('--no-plugins', '--builtin')
129
129
def test_commit_dashm(self):
130
self.complete(['bzr', 'commit', '-m'])
130
self.complete(['brz', 'commit', '-m'])
131
131
self.assertCompletionEquals('-m')
133
133
def test_status_negated(self):
134
self.complete(['bzr', 'status', '--n'])
134
self.complete(['brz', 'status', '--n'])
135
135
self.assertCompletionContains('--no-versioned', '--no-verbose')
137
137
def test_init_format_any(self):
138
self.complete(['bzr', 'init', '--format', '=', 'directory'], cword=3)
138
self.complete(['brz', 'init', '--format', '=', 'directory'], cword=3)
139
139
self.assertCompletionContains('1.9', '2a')
141
141
def test_init_format_2(self):
142
self.complete(['bzr', 'init', '--format', '=', '2', 'directory'],
142
self.complete(['brz', 'init', '--format', '=', '2', 'directory'],
144
144
self.assertCompletionContains('2a')
145
145
self.assertCompletionOmits('1.9')
148
148
class TestBashCompletionInvoking(tests.TestCaseWithTransport,
149
149
BashCompletionMixin):
150
"""Test bash completions that might execute bzr.
150
"""Test bash completions that might execute brz.
152
Only the syntax ``$(bzr ...`` is supported so far. The bzr command
153
will be replaced by the bzr instance running this selftest.
152
Only the syntax ``$(brz ...`` is supported so far. The brz command
153
will be replaced by the brz instance running this selftest.
169
169
wt.branch.tags.set_tag('tag1', 'null:')
170
170
wt.branch.tags.set_tag('tag2', 'null:')
171
171
wt.branch.tags.set_tag('3tag', 'null:')
172
self.complete(['bzr', 'log', '-r', 'tag', ':'])
172
self.complete(['brz', 'log', '-r', 'tag', ':'])
173
173
self.assertCompletionEquals('tag1', 'tag2', '3tag')
175
175
def test_revspec_tag_prefix(self):
178
178
wt.branch.tags.set_tag('tag1', 'null:')
179
179
wt.branch.tags.set_tag('tag2', 'null:')
180
180
wt.branch.tags.set_tag('3tag', 'null:')
181
self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
181
self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
182
182
self.assertCompletionEquals('tag1', 'tag2')
184
184
def test_revspec_tag_spaces(self):
185
185
self.requireFeature(features.sed_feature)
186
186
wt = self.make_branch_and_tree('.', format='dirstate-tags')
187
187
wt.branch.tags.set_tag('tag with spaces', 'null:')
188
self.complete(['bzr', 'log', '-r', 'tag', ':', 't'])
188
self.complete(['brz', 'log', '-r', 'tag', ':', 't'])
189
189
self.assertCompletionEquals(r'tag\ with\ spaces')
190
self.complete(['bzr', 'log', '-r', '"tag:t'])
190
self.complete(['brz', 'log', '-r', '"tag:t'])
191
191
self.assertCompletionEquals('tag:tag with spaces')
192
self.complete(['bzr', 'log', '-r', "'tag:t"])
192
self.complete(['brz', 'log', '-r', "'tag:t"])
193
193
self.assertCompletionEquals('tag:tag with spaces')
195
195
def test_revspec_tag_endrange(self):
197
197
wt = self.make_branch_and_tree('.', format='dirstate-tags')
198
198
wt.branch.tags.set_tag('tag1', 'null:')
199
199
wt.branch.tags.set_tag('tag2', 'null:')
200
self.complete(['bzr', 'log', '-r', '3..tag', ':', 't'])
200
self.complete(['brz', 'log', '-r', '3..tag', ':', 't'])
201
201
self.assertCompletionEquals('tag1', 'tag2')
202
self.complete(['bzr', 'log', '-r', '"3..tag:t'])
202
self.complete(['brz', 'log', '-r', '"3..tag:t'])
203
203
self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
204
self.complete(['bzr', 'log', '-r', "'3..tag:t"])
204
self.complete(['brz', 'log', '-r', "'3..tag:t"])
205
205
self.assertCompletionEquals('3..tag:tag1', '3..tag:tag2')
221
221
self.assertEqual('', BashCodeGen(data, debug=False).debug_output())
222
222
self.assertTrue(BashCodeGen(data, debug=True).debug_output())
224
def test_bzr_version(self):
224
def test_brz_version(self):
225
225
data = CompletionData()
226
226
cg = BashCodeGen(data)
227
self.assertEqual('%s.' % bzrlib.version_string, cg.bzr_version())
227
self.assertEqual('%s.' % breezy.version_string, cg.brz_version())
228
228
data.plugins['foo'] = PluginData('foo', '1.0')
229
229
data.plugins['bar'] = PluginData('bar', '2.0')
230
230
cg = BashCodeGen(data)
231
231
self.assertEqual('''\
232
232
%s and the following plugins:
234
# foo 1.0''' % bzrlib.version_string, cg.bzr_version())
234
# foo 1.0''' % breezy.version_string, cg.brz_version())
236
236
def test_global_options(self):
237
237
data = CompletionData()