108
114
def test_args(self):
109
"""Test that run_bzr passes args correctly to run_bzr_captured"""
115
"""Test that run_bzr passes args correctly to _run_bzr_core"""
116
## self.callDeprecated(
117
## ['passing varargs to run_bzr was deprecated in version 0.18.'],
119
## 'arg1', 'arg2', 'arg3', retcode=1)
110
120
self.run_bzr('arg1', 'arg2', 'arg3', retcode=1)
111
self.assertEqual(('arg1', 'arg2', 'arg3'), self.argv)
121
self.assertEqual(['arg1', 'arg2', 'arg3'], self.argv)
113
123
def test_encoding(self):
114
"""Test that run_bzr passes encoding to run_bzr_captured"""
115
self.run_bzr('foo', 'bar')
124
"""Test that run_bzr passes encoding to _run_bzr_core"""
125
self.run_bzr('foo bar')
116
126
self.assertEqual(None, self.encoding)
117
self.assertEqual(('foo', 'bar'), self.argv)
127
self.assertEqual(['foo', 'bar'], self.argv)
119
self.run_bzr('foo', 'bar', encoding='baz')
129
self.run_bzr('foo bar', encoding='baz')
120
130
self.assertEqual('baz', self.encoding)
121
self.assertEqual(('foo', 'bar'), self.argv)
131
self.assertEqual(['foo', 'bar'], self.argv)
123
133
def test_retcode(self):
124
"""Test that run_bzr passes retcode to run_bzr_captured"""
134
"""Test that run_bzr passes retcode to _run_bzr_core"""
125
135
# Default is retcode == 0
126
self.run_bzr('foo', 'bar')
136
self.run_bzr('foo bar')
127
137
self.assertEqual(0, self.retcode)
128
self.assertEqual(('foo', 'bar'), self.argv)
138
self.assertEqual(['foo', 'bar'], self.argv)
130
self.run_bzr('foo', 'bar', retcode=1)
140
self.run_bzr('foo bar', retcode=1)
131
141
self.assertEqual(1, self.retcode)
132
self.assertEqual(('foo', 'bar'), self.argv)
142
self.assertEqual(['foo', 'bar'], self.argv)
134
self.run_bzr('foo', 'bar', retcode=None)
144
self.run_bzr('foo bar', retcode=None)
135
145
self.assertEqual(None, self.retcode)
136
self.assertEqual(('foo', 'bar'), self.argv)
146
self.assertEqual(['foo', 'bar'], self.argv)
138
self.run_bzr('foo', 'bar', retcode=3)
148
self.run_bzr(['foo', 'bar'], retcode=3)
139
149
self.assertEqual(3, self.retcode)
140
self.assertEqual(('foo', 'bar'), self.argv)
150
self.assertEqual(['foo', 'bar'], self.argv)
142
152
def test_stdin(self):
143
153
# test that the stdin keyword to run_bzr is passed through to
144
# run_bzr_captured as-is. We do this by overriding
145
# run_bzr_captured in this class, and then calling run_bzr,
146
# which is a convenience function for run_bzr_captured, so
154
# _run_bzr_core as-is. We do this by overriding
155
# _run_bzr_core in this class, and then calling run_bzr,
156
# which is a convenience function for _run_bzr_core, so
147
157
# should invoke it.
148
self.run_bzr('foo', 'bar', stdin='gam')
158
self.run_bzr('foo bar', stdin='gam')
149
159
self.assertEqual('gam', self.stdin)
150
self.assertEqual(('foo', 'bar'), self.argv)
160
self.assertEqual(['foo', 'bar'], self.argv)
152
self.run_bzr('foo', 'bar', stdin='zippy')
162
self.run_bzr('foo bar', stdin='zippy')
153
163
self.assertEqual('zippy', self.stdin)
154
self.assertEqual(('foo', 'bar'), self.argv)
164
self.assertEqual(['foo', 'bar'], self.argv)
156
166
def test_working_dir(self):
157
"""Test that run_bzr passes working_dir to run_bzr_captured"""
158
self.run_bzr('foo', 'bar')
167
"""Test that run_bzr passes working_dir to _run_bzr_core"""
168
self.run_bzr('foo bar')
159
169
self.assertEqual(None, self.working_dir)
160
self.assertEqual(('foo', 'bar'), self.argv)
170
self.assertEqual(['foo', 'bar'], self.argv)
162
self.run_bzr('foo', 'bar', working_dir='baz')
172
self.run_bzr('foo bar', working_dir='baz')
163
173
self.assertEqual('baz', self.working_dir)
164
self.assertEqual(('foo', 'bar'), self.argv)
174
self.assertEqual(['foo', 'bar'], self.argv)
167
177
class TestBenchmarkTests(TestCaseWithTransport):
204
215
def test_stdin(self):
205
# test that the stdin keyword to run_bzr_captured is passed through to
216
# test that the stdin keyword to _run_bzr_core is passed through to
206
217
# apply_redirected as a StringIO. We do this by overriding
207
# apply_redirected in this class, and then calling run_bzr_captured,
218
# apply_redirected in this class, and then calling _run_bzr_core,
208
219
# which calls apply_redirected.
209
self.run_bzr_captured(['foo', 'bar'], stdin='gam')
220
self.run_bzr(['foo', 'bar'], stdin='gam')
210
221
self.assertEqual('gam', self.stdin.read())
211
222
self.assertTrue(self.stdin is self.factory_stdin)
212
self.run_bzr_captured(['foo', 'bar'], stdin='zippy')
223
self.run_bzr(['foo', 'bar'], stdin='zippy')
213
224
self.assertEqual('zippy', self.stdin.read())
214
225
self.assertTrue(self.stdin is self.factory_stdin)
216
227
def test_ui_factory(self):
217
# each invocation of self.run_bzr_captured should get its
228
# each invocation of self.run_bzr should get its
218
229
# own UI factory, which is an instance of TestUIFactory,
219
230
# with stdin, stdout and stderr attached to the stdin,
220
# stdout and stderr of the invoked run_bzr_captured
231
# stdout and stderr of the invoked run_bzr
221
232
current_factory = bzrlib.ui.ui_factory
222
self.run_bzr_captured(['foo'])
233
self.run_bzr(['foo'])
223
234
self.failIf(current_factory is self.factory)
224
235
self.assertNotEqual(sys.stdout, self.factory.stdout)
225
236
self.assertNotEqual(sys.stderr, self.factory.stderr)
232
243
cwd = osutils.getcwd()
234
245
# Default is to work in the current directory
235
self.run_bzr_captured(['foo', 'bar'])
246
self.run_bzr(['foo', 'bar'])
236
247
self.assertEqual(cwd, self.working_dir)
238
self.run_bzr_captured(['foo', 'bar'], working_dir=None)
249
self.run_bzr(['foo', 'bar'], working_dir=None)
239
250
self.assertEqual(cwd, self.working_dir)
241
252
# The function should be run in the alternative directory
242
253
# but afterwards the current working dir shouldn't be changed
243
self.run_bzr_captured(['foo', 'bar'], working_dir='one')
254
self.run_bzr(['foo', 'bar'], working_dir='one')
244
255
self.assertNotEqual(cwd, self.working_dir)
245
256
self.assertEndsWith(self.working_dir, 'one')
246
257
self.assertEqual(cwd, osutils.getcwd())
248
self.run_bzr_captured(['foo', 'bar'], working_dir='two')
259
self.run_bzr(['foo', 'bar'], working_dir='two')
249
260
self.assertNotEqual(cwd, self.working_dir)
250
261
self.assertEndsWith(self.working_dir, 'two')
251
262
self.assertEqual(cwd, osutils.getcwd())
539
550
def test_list_only_filtered(self):
540
551
# check that a filtered --list-only works, both include and exclude
541
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only'])
552
out_all,err_all = self.run_bzr(['selftest', '--list-only'])
542
553
tests_all = self._parse_test_list(out_all.splitlines())[1]
543
out_incl,err_incl = self.run_bzr_captured(['selftest', '--list-only',
554
out_incl,err_incl = self.run_bzr(['selftest', '--list-only',
545
556
tests_incl = self._parse_test_list(out_incl.splitlines())[1]
546
557
self.assertSubset(tests_incl, tests_all)
547
out_excl,err_excl = self.run_bzr_captured(['selftest', '--list-only',
558
out_excl,err_excl = self.run_bzr(['selftest', '--list-only',
548
559
'--exclude', 'selftest'])
549
560
tests_excl = self._parse_test_list(out_excl.splitlines())[1]
550
561
self.assertSubset(tests_excl, tests_all)
557
568
def test_list_only_random(self):
558
569
# check that --randomize works correctly
559
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only',
570
out_all,err_all = self.run_bzr(['selftest', '--list-only',
561
572
tests_all = self._parse_test_list(out_all.splitlines())[1]
562
573
# XXX: It looks like there are some orders for generating tests that
563
574
# fail as of 20070504 - maybe because of import order dependencies.
564
575
# So unfortunately this will rarely intermittently fail at the moment.
565
576
# -- mbp 20070504
566
out_rand,err_rand = self.run_bzr_captured(['selftest', '--list-only',
577
out_rand,err_rand = self.run_bzr(['selftest', '--list-only',
567
578
'selftest', '--randomize', 'now'])
568
579
(header_rand,tests_rand,dummy) = self._parse_test_list(
569
580
out_rand.splitlines(), 2)