596
596
test = TestDanglingLock('test_function')
597
597
result = test.run()
598
self.assertEqual(1, len(result.errors))
598
if self._lock_check_thorough:
599
self.assertEqual(1, len(result.errors))
601
# When _lock_check_thorough is disabled, then we don't trigger a
603
self.assertEqual(0, len(result.errors))
601
606
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
1315
1321
# we could set something and run a test that will check
1316
1322
# it gets santised, but this is probably sufficient for now:
1317
1323
# if someone runs the test with -Dsomething it will error.
1318
self.assertEqual(set(), bzrlib.debug.debug_flags)
1325
if self._lock_check_thorough:
1326
flags.add('strict_locks')
1327
self.assertEqual(flags, bzrlib.debug.debug_flags)
1320
1329
def change_selftest_debug_flags(self, new_flags):
1321
1330
orig_selftest_flags = tests.selftest_debug_flags
1336
1345
self.flags = set(bzrlib.debug.debug_flags)
1337
1346
test = TestThatRecordsFlags('test_foo')
1338
1347
test.run(self.make_test_result())
1339
self.assertEqual(set(['a-flag']), self.flags)
1348
flags = set(['a-flag'])
1349
if 'disable_lock_checks' not in tests.selftest_debug_flags:
1350
flags.add('strict_locks')
1351
self.assertEqual(flags, self.flags)
1353
def test_disable_lock_checks(self):
1354
"""The -Edisable_lock_checks flag disables thorough checks."""
1355
class TestThatRecordsFlags(tests.TestCase):
1356
def test_foo(nested_self):
1357
self.flags = set(bzrlib.debug.debug_flags)
1358
self.test_lock_check_thorough = nested_self._lock_check_thorough
1359
self.change_selftest_debug_flags(set())
1360
test = TestThatRecordsFlags('test_foo')
1361
test.run(self.make_test_result())
1362
# By default we do strict lock checking and thorough lock/unlock
1364
self.assertTrue(self.test_lock_check_thorough)
1365
self.assertEqual(set(['strict_locks']), self.flags)
1366
# Now set the disable_lock_checks flag, and show that this changed.
1367
self.change_selftest_debug_flags(set(['disable_lock_checks']))
1368
test = TestThatRecordsFlags('test_foo')
1369
test.run(self.make_test_result())
1370
self.assertFalse(self.test_lock_check_thorough)
1371
self.assertEqual(set(), self.flags)
1373
def test_this_fails_strict_lock_check(self):
1374
class TestThatRecordsFlags(tests.TestCase):
1375
def test_foo(nested_self):
1376
self.flags1 = set(bzrlib.debug.debug_flags)
1377
self.thisFailsStrictLockCheck()
1378
self.flags2 = set(bzrlib.debug.debug_flags)
1379
# Make sure lock checking is active
1380
self.change_selftest_debug_flags(set())
1381
test = TestThatRecordsFlags('test_foo')
1382
test.run(self.make_test_result())
1383
self.assertEqual(set(['strict_locks']), self.flags1)
1384
self.assertEqual(set(), self.flags2)
1341
1386
def test_debug_flags_restored(self):
1342
1387
"""The bzrlib debug flags should be restored to their original state