1
1
# Copyright (C) 2005, 2006 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
110
110
import bzrlib.tests.bzrdir_implementations
111
111
import bzrlib.tests.interrepository_implementations
112
112
import bzrlib.tests.interversionedfile_implementations
113
import bzrlib.tests.intertree_implementations
113
114
import bzrlib.tests.repository_implementations
114
115
import bzrlib.tests.revisionstore_implementations
116
import bzrlib.tests.tree_implementations
115
117
import bzrlib.tests.workingtree_implementations
120
122
bzrlib.tests.bzrdir_implementations,
121
123
bzrlib.tests.interrepository_implementations,
122
124
bzrlib.tests.interversionedfile_implementations,
125
bzrlib.tests.intertree_implementations,
123
126
bzrlib.tests.repository_implementations,
124
127
bzrlib.tests.revisionstore_implementations,
128
bzrlib.tests.tree_implementations,
125
129
bzrlib.tests.workingtree_implementations,
227
231
self.stream.write('E')
229
233
self.pb.update(self._ellipsise_unimportant_words('ERROR', 13), self.testsRun, None)
234
self.pb.note(self._ellipsise_unimportant_words(
235
test.id() + ': ERROR',
236
osutils.terminal_width()))
230
237
self.stream.flush()
231
238
if self.stop_early:
240
247
self.stream.write('F')
242
249
self.pb.update(self._ellipsise_unimportant_words('FAIL', 13), self.testsRun, None)
250
self.pb.note(self._ellipsise_unimportant_words(
251
test.id() + ': FAIL',
252
osutils.terminal_width()))
243
253
self.stream.flush()
244
254
if self.stop_early:
275
285
self.stream.flush()
276
286
# seems best to treat this as success from point-of-view of unittest
277
287
# -- it actually does nothing so it barely matters :)
278
unittest.TestResult.addSuccess(self, test)
290
except KeyboardInterrupt:
293
self.addError(test, test.__exc_info())
295
unittest.TestResult.addSuccess(self, test)
280
297
def printErrorList(self, flavour, errors):
281
298
for test, err in errors:
569
586
Read contents into memory, close, and delete.
588
if self._log_file is None:
571
590
bzrlib.trace.disable_test_log(self._log_nonce)
572
591
self._log_file.seek(0)
573
592
self._log_contents = self._log_file.read()
755
775
encoding = bzrlib.user_encoding
756
776
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
778
def run_bzr_error(self, error_regexes, *args, **kwargs):
779
"""Run bzr, and check that stderr contains the supplied regexes
781
:param error_regexes: Sequence of regular expressions which
782
must each be found in the error output. The relative ordering
784
:param args: command-line arguments for bzr
785
:param kwargs: Keyword arguments which are interpreted by run_bzr
786
This function changes the default value of retcode to be 3,
787
since in most cases this is run when you expect bzr to fail.
788
:return: (out, err) The actual output of running the command (in case you
789
want to do more inspection)
792
# Make sure that commit is failing because there is nothing to do
793
self.run_bzr_error(['no changes to commit'],
794
'commit', '-m', 'my commit comment')
795
# Make sure --strict is handling an unknown file, rather than
796
# giving us the 'nothing to do' error
797
self.build_tree(['unknown'])
798
self.run_bzr_error(['Commit refused because there are unknown files'],
799
'commit', '--strict', '-m', 'my commit comment')
801
kwargs.setdefault('retcode', 3)
802
out, err = self.run_bzr(*args, **kwargs)
803
for regex in error_regexes:
804
self.assertContainsRe(err, regex)
758
807
def run_bzr_subprocess(self, *args, **kwargs):
759
808
"""Run bzr in a subprocess for testing.
932
981
shape is a sequence of file specifications. If the final
933
982
character is '/', a directory is created.
984
This assumes that all the elements in the tree being built are new.
935
986
This doesn't add anything to a branch.
936
987
:param line_endings: Either 'binary' or 'native'
937
988
in binary mode, exact contents are written
942
993
VFS's. If the transport is readonly or None,
943
994
"." is opened automatically.
945
# XXX: It's OK to just create them using forward slashes on windows?
996
# It's OK to just create them using forward slashes on windows.
946
997
if transport is None or transport.is_readonly():
947
998
transport = get_transport(".")
948
999
for name in shape:
958
1009
raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
959
1010
content = "contents of %s%s" % (name.encode('utf-8'), end)
960
transport.put(urlutils.escape(name), StringIO(content))
1011
# Technically 'put()' is the right command. However, put
1012
# uses an AtomicFile, which requires an extra rename into place
1013
# As long as the files didn't exist in the past, append() will
1014
# do the same thing as put()
1015
# On jam's machine, make_kernel_like_tree is:
1016
# put: 4.5-7.5s (averaging 6s)
1018
transport.append(urlutils.escape(name), StringIO(content))
962
1020
def build_tree_contents(self, shape):
963
1021
build_tree_contents(shape)
1196
1254
lsprof_timed=None,
1197
1255
bench_history=None):
1198
1256
"""Run the whole test suite under the enhanced runner"""
1257
# XXX: Very ugly way to do this...
1258
# Disable warning about old formats because we don't want it to disturb
1259
# any blackbox tests.
1260
from bzrlib import repository
1261
repository._deprecation_warning_done = True
1199
1263
global default_transport
1200
1264
if transport is None:
1201
1265
transport = default_transport
1224
1288
testmod_names = [
1225
1289
'bzrlib.tests.test_ancestry',
1226
1290
'bzrlib.tests.test_api',
1291
'bzrlib.tests.test_atomicfile',
1227
1292
'bzrlib.tests.test_bad_files',
1228
1293
'bzrlib.tests.test_branch',
1229
1294
'bzrlib.tests.test_bundle',
1236
1301
'bzrlib.tests.test_decorators',
1237
1302
'bzrlib.tests.test_diff',
1238
1303
'bzrlib.tests.test_doc_generate',
1239
'bzrlib.tests.test_emptytree',
1240
1304
'bzrlib.tests.test_errors',
1241
1305
'bzrlib.tests.test_escaped_store',
1242
1306
'bzrlib.tests.test_fetch',
1244
1308
'bzrlib.tests.test_graph',
1245
1309
'bzrlib.tests.test_hashcache',
1246
1310
'bzrlib.tests.test_http',
1311
'bzrlib.tests.test_http_response',
1247
1312
'bzrlib.tests.test_identitymap',
1313
'bzrlib.tests.test_ignores',
1248
1314
'bzrlib.tests.test_inv',
1249
1315
'bzrlib.tests.test_knit',
1250
1316
'bzrlib.tests.test_lockdir',
1267
1333
'bzrlib.tests.test_repository',
1268
1334
'bzrlib.tests.test_revision',
1269
1335
'bzrlib.tests.test_revisionnamespaces',
1270
'bzrlib.tests.test_revprops',
1271
1336
'bzrlib.tests.test_revisiontree',
1272
1337
'bzrlib.tests.test_rio',
1273
1338
'bzrlib.tests.test_sampler',
1286
1351
'bzrlib.tests.test_transactions',
1287
1352
'bzrlib.tests.test_transform',
1288
1353
'bzrlib.tests.test_transport',
1354
'bzrlib.tests.test_tree',
1289
1355
'bzrlib.tests.test_tsort',
1290
1356
'bzrlib.tests.test_tuned_gzip',
1291
1357
'bzrlib.tests.test_ui',
1304
1370
suite = TestUtil.TestSuite()
1305
1371
loader = TestUtil.TestLoader()
1372
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1306
1373
from bzrlib.transport import TransportTestProviderAdapter
1307
1374
adapter = TransportTestProviderAdapter()
1308
1375
adapt_modules(test_transport_implementations, adapter, loader, suite)
1309
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1310
1376
for package in packages_to_test():
1311
1377
suite.addTest(package.test_suite())
1312
1378
for m in MODULES_TO_TEST: