1
# Copyright (C) 2005 by 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from unittest import TestResult, TestCase
21
class TestBase(TestCase):
22
"""Base class for bzr test cases.
24
Just defines some useful helper functions; doesn't actually test
27
# TODO: Special methods to invoke bzr
29
def runcmd(self, cmd, expected=0):
30
self.log('$ ' + ' '.join(cmd))
31
from os import spawnvp, P_WAIT
32
rc = spawnvp(P_WAIT, cmd[0], cmd)
34
self.fail("command %r returned status %d" % (cmd, rc))
37
def backtick(self, cmd):
38
"""Run a command and return its output"""
40
self.log('$ ' + ' '.join(cmd))
51
self.fail("command %r returned status %d" % (cmd, rc))
57
"""Log a message to a progress file"""
63
class _MyResult(TestResult):
67
No special behaviour for now.
69
# def startTest(self, test):
70
# print str(test).ljust(50),
71
# TestResult.startTest(self, test)
73
# def stopTest(self, test):
75
# TestResult.stopTest(self, test)
84
from unittest import TestLoader, TestSuite
86
import bzrlib.selftest.whitebox
87
import bzrlib.selftest.blackbox
88
from doctest import DocTestSuite
99
for m in bzrlib.selftest.whitebox, bzrlib.selftest.blackbox:
100
suite.addTest(tl.loadTestsFromModule(m))
102
for m in bzrlib.store, bzrlib.inventory, bzrlib.branch, bzrlib.osutils, \
104
suite.addTest(DocTestSuite(m))
109
_show_results(result)
111
return result.wasSuccessful()
114
def _setup_test_log():
119
log_filename = os.path.abspath('testbzr.log')
120
TEST_LOG = open(log_filename, 'wt', buffering=1) # line buffered
122
print >>TEST_LOG, "bzr tests run at " + time.ctime()
123
print '%-30s %s' % ('test log', log_filename)
126
def _setup_test_dir():
130
global ORIG_DIR, TEST_DIR
131
ORIG_DIR = os.getcwdu()
132
TEST_DIR = os.path.abspath("testbzr.tmp")
134
print '%-30s %s' % ('running tests in', TEST_DIR)
136
if os.path.exists(TEST_DIR):
137
shutil.rmtree(TEST_DIR)
143
def _show_results(result):
144
for case, tb in result.errors:
145
_show_test_failure('ERROR', case, tb)
147
for case, tb in result.failures:
148
_show_test_failure('FAILURE', case, tb)
151
print '%4d tests run' % result.testsRun
152
print '%4d errors' % len(result.errors)
153
print '%4d failures' % len(result.failures)
157
def _show_test_failure(kind, case, tb):
158
print (kind + '! ').ljust(60, '-')
161
print ''.ljust(60, '-')