17
17
"""UI tests for the test framework."""
23
from bzrlib.tests import (
24
from breezy.tests import (
26
from bzrlib.transport import memory
27
from breezy.transport import memory
28
29
class SelfTestPatch:
46
47
tests.selftest = original_selftest
49
class TestOptionsWritingToDisk(tests.TestCaseInTempDir, SelfTestPatch):
51
def test_benchmark_runs_benchmark_tests(self):
52
"""selftest --benchmark should change the suite factory."""
53
params = self.get_params_passed_to_core('selftest --benchmark')
54
self.assertEqual(benchmarks.test_suite,
55
params[1]['test_suite_factory'])
56
self.assertNotEqual(None, params[1]['bench_history'])
57
benchfile = open(".perf_history", "rt")
59
lines = benchfile.readlines()
62
# Because we don't run the actual test code no output is made to the
64
self.assertEqual(0, len(lines))
67
50
class TestOptions(tests.TestCase, SelfTestPatch):
69
52
def test_load_list(self):
74
57
# Test that we can pass a transport to the selftest core - sftp
76
59
self.requireFeature(features.paramiko)
77
from bzrlib.tests import stub_sftp
60
from breezy.tests import stub_sftp
78
61
params = self.get_params_passed_to_core('selftest --transport=sftp')
79
62
self.assertEqual(stub_sftp.SFTPAbsoluteServer,
80
63
params[1]["transport"])
106
89
'selftest --starting-with foo --starting-with bar')
107
90
self.assertEqual(['foo', 'bar'], params[1]['starting_with'])
109
def test_subunit(self):
110
self.requireFeature(features.subunit)
111
params = self.get_params_passed_to_core('selftest --subunit')
112
self.assertEqual(tests.SubUnitBzrRunner, params[1]['runner_class'])
92
def test_subunitv1(self):
93
self.requireFeature(features.subunit)
94
params = self.get_params_passed_to_core('selftest --subunit1')
95
self.assertEqual(tests.SubUnitBzrRunnerv1, params[1]['runner_class'])
97
def test_subunitv2(self):
98
self.requireFeature(features.subunit)
99
params = self.get_params_passed_to_core('selftest --subunit2')
100
self.assertEqual(tests.SubUnitBzrRunnerv2, params[1]['runner_class'])
114
102
def _parse_test_list(self, lines, newlines_in_header=0):
115
103
"Parse a list of lines into a tuple of 3 lists (header,body,footer)."
137
125
# If the last body line is blank, drop it off the list
138
126
if len(body) > 0 and body[-1] == '':
140
return (header,body,footer)
128
return (header, body, footer)
142
130
def test_list_only(self):
143
# check that bzr selftest --list-only outputs no ui noise
131
# check that brz selftest --list-only outputs no ui noise
144
132
def selftest(*args, **kwargs):
145
133
"""Capture the arguments selftest was run with."""
147
135
def outputs_nothing(cmdline):
148
out,err = self.run_bzr(cmdline)
149
(header,body,footer) = self._parse_test_list(out.splitlines())
136
out, err = self.run_bzr(cmdline)
137
(header, body, footer) = self._parse_test_list(out.splitlines())
150
138
num_tests = len(body)
151
139
self.assertLength(0, header)
152
140
self.assertLength(0, footer)
153
self.assertEqual('', err)
141
self.assertEqual(b'', err)
154
142
# Yes this prevents using threads to run the test suite in parallel,
155
143
# however we don't have a clean dependency injector for commands,
156
144
# and even if we did - we'd still be testing that the glue is wired
167
155
def test_lsprof_tests(self):
168
156
params = self.get_params_passed_to_core('selftest --lsprof-tests')
169
157
self.assertEqual(True, params[1]["lsprof_tests"])
159
def test_parallel_fork_unsupported(self):
160
if getattr(os, "fork", None) is not None:
161
self.addCleanup(setattr, os, "fork", os.fork)
163
out, err = self.run_bzr(["selftest", "--parallel=fork", "-s", "bt.x"],
165
self.assertIn("platform does not support fork", err)
166
self.assertFalse(out)