1
# Copyright (C) 2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
"""Black-box tests for bzr config."""
27
from bzrlib.tests import (
29
test_config as _t_config,
32
class TestWithoutConfig(tests.TestCaseWithTransport):
34
def test_config_all(self):
35
out, err = self.run_bzr(['config'])
36
self.assertEquals('', out)
37
self.assertEquals('', err)
39
def test_remove_unknown_option(self):
40
self.run_bzr_error(['The "file" configuration option does not exist',],
41
['config', '--remove', 'file'])
43
def test_all_remove_exclusive(self):
44
self.run_bzr_error(['--all and --remove are mutually exclusive.',],
45
['config', '--remove', '--all'])
47
def test_all_set_exclusive(self):
48
self.run_bzr_error(['Only one option can be set.',],
49
['config', '--all', 'hello=world'])
51
def test_remove_no_option(self):
52
self.run_bzr_error(['--remove expects an option to remove.',],
53
['config', '--remove'])
55
def test_unknown_option(self):
56
self.run_bzr_error(['The "file" configuration option does not exist',],
59
def test_unexpected_regexp(self):
61
['The "\*file" configuration option does not exist',],
64
def test_wrong_regexp(self):
66
['Invalid pattern\(s\) found. "\*file" nothing to repeat',],
67
['config', '--all', '*file'])
71
class TestConfigDisplay(tests.TestCaseWithTransport):
74
super(TestConfigDisplay, self).setUp()
75
_t_config.create_configs(self)
77
def test_multiline_all_values(self):
78
self.bazaar_config.set_user_option('multiline', '1\n2\n')
79
script.run_script(self, """\
87
def test_multiline_value_only(self):
88
self.bazaar_config.set_user_option('multiline', '1\n2\n')
89
script.run_script(self, """\
90
$ bzr config -d tree multiline
96
def test_list_all_values(self):
97
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
98
script.run_script(self, '''\
101
list = 1, a, "with, a comma"
104
def test_list_value_only(self):
105
self.bazaar_config.set_user_option('list', [1, 'a', 'with, a comma'])
106
script.run_script(self, '''\
107
$ bzr config -d tree list
108
1, a, "with, a comma"
111
def test_bazaar_config(self):
112
self.bazaar_config.set_user_option('hello', 'world')
113
script.run_script(self, '''\
119
def test_locations_config_for_branch(self):
120
self.locations_config.set_user_option('hello', 'world')
121
self.branch_config.set_user_option('hello', 'you')
122
script.run_script(self, '''\
131
def test_locations_config_outside_branch(self):
132
self.bazaar_config.set_user_option('hello', 'world')
133
self.locations_config.set_user_option('hello', 'world')
134
script.run_script(self, '''\
140
class TestConfigDisplayWithPolicy(tests.TestCaseWithTransport):
142
def test_location_with_policy(self):
143
# LocationConfig is the only one dealing with policies so far.
144
self.make_branch_and_tree('tree')
148
url:policy = appendpath
151
""" % {'dir': self.test_dir}
152
# We don't use the config directly so we save it to disk
153
config.LocationConfig.from_string(config_text, 'tree', save=True)
154
# policies are displayed with their options since they are part of
155
# their definition, likewise the path is not appended, we are just
156
# presenting the relevant portions of the config files
157
script.run_script(self, '''\
158
$ bzr config -d tree --all url
164
url:policy = appendpath
168
class TestConfigActive(tests.TestCaseWithTransport):
171
super(TestConfigActive, self).setUp()
172
_t_config.create_configs_with_file_option(self)
174
def test_active_in_locations(self):
175
script.run_script(self, '''\
176
$ bzr config -d tree file
180
def test_active_in_bazaar(self):
181
script.run_script(self, '''\
182
$ bzr config -d tree --scope bazaar file
186
def test_active_in_branch(self):
187
# We need to delete the locations definition that overrides the branch
189
script.run_script(self, '''\
190
$ bzr config -d tree --remove file
191
$ bzr config -d tree file
196
class TestConfigSetOption(tests.TestCaseWithTransport):
199
super(TestConfigSetOption, self).setUp()
200
_t_config.create_configs(self)
202
def test_unknown_config(self):
203
self.run_bzr_error(['The "moon" configuration does not exist'],
204
['config', '--scope', 'moon', 'hello=world'])
206
def test_bazaar_config_outside_branch(self):
207
script.run_script(self, '''\
208
$ bzr config --scope bazaar hello=world
209
$ bzr config -d tree --all hello
214
def test_bazaar_config_inside_branch(self):
215
script.run_script(self, '''\
216
$ bzr config -d tree --scope bazaar hello=world
217
$ bzr config -d tree --all hello
222
def test_locations_config_inside_branch(self):
223
script.run_script(self, '''\
224
$ bzr config -d tree --scope locations hello=world
225
$ bzr config -d tree --all hello
231
def test_branch_config_default(self):
232
script.run_script(self, '''\
233
$ bzr config -d tree hello=world
234
$ bzr config -d tree --all hello
239
def test_branch_config_forcing_branch(self):
240
script.run_script(self, '''\
241
$ bzr config -d tree --scope branch hello=world
242
$ bzr config -d tree --all hello
248
class TestConfigRemoveOption(tests.TestCaseWithTransport):
251
super(TestConfigRemoveOption, self).setUp()
252
_t_config.create_configs_with_file_option(self)
254
def test_unknown_config(self):
255
self.run_bzr_error(['The "moon" configuration does not exist'],
256
['config', '--scope', 'moon', '--remove', 'file'])
258
def test_bazaar_config_outside_branch(self):
259
script.run_script(self, '''\
260
$ bzr config --scope bazaar --remove file
261
$ bzr config -d tree --all file
269
def test_bazaar_config_inside_branch(self):
270
script.run_script(self, '''\
271
$ bzr config -d tree --scope bazaar --remove file
272
$ bzr config -d tree --all file
280
def test_locations_config_inside_branch(self):
281
script.run_script(self, '''\
282
$ bzr config -d tree --scope locations --remove file
283
$ bzr config -d tree --all file
290
def test_branch_config_default(self):
291
script.run_script(self, '''\
292
$ bzr config -d tree --remove file
293
$ bzr config -d tree --all file
299
script.run_script(self, '''\
300
$ bzr config -d tree --remove file
301
$ bzr config -d tree --all file
306
def test_branch_config_forcing_branch(self):
307
script.run_script(self, '''\
308
$ bzr config -d tree --scope branch --remove file
309
$ bzr config -d tree --all file
316
script.run_script(self, '''\
317
$ bzr config -d tree --remove file
318
$ bzr config -d tree --all file