491
493
self.assertEquals(['bzr','bzrlib','setup.py',
492
494
'test9999.tmp','tests'],
498
class TestSelftestListOnly(TestCase):
501
def _parse_test_list(lines, newlines_in_header=1):
502
"Parse a list of lines into a tuple of 3 lists (header,body,footer)."
509
header_newlines_found = 0
513
header_newlines_found += 1
514
if header_newlines_found >= newlines_in_header:
519
if line.startswith('-------'):
525
# If the last body line is blank, drop it off the list
526
if len(body) > 0 and body[-1] == '':
528
return (header,body,footer)
530
def test_list_only(self):
531
# check that bzr selftest --list-only works correctly
532
out,err = self.run_bzr_captured(['selftest', 'selftest',
534
self.assertEndsWith(err, 'tests passed\n')
535
(header,body,footer) = self._parse_test_list(out.splitlines())
536
num_tests = len(body)
537
self.assertContainsRe(footer[0], 'Listed %s tests in' % num_tests)
539
def test_list_only_filtered(self):
540
# check that a filtered --list-only works, both include and exclude
541
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only'])
542
tests_all = self._parse_test_list(out_all.splitlines())[1]
543
out_incl,err_incl = self.run_bzr_captured(['selftest', '--list-only',
545
tests_incl = self._parse_test_list(out_incl.splitlines())[1]
546
self.assertSubset(tests_incl, tests_all)
547
out_excl,err_excl = self.run_bzr_captured(['selftest', '--list-only',
548
'--exclude', 'selftest'])
549
tests_excl = self._parse_test_list(out_excl.splitlines())[1]
550
self.assertSubset(tests_excl, tests_all)
551
set_incl = set(tests_incl)
552
set_excl = set(tests_excl)
553
intersection = set_incl.intersection(set_excl)
554
self.assertEquals(0, len(intersection))
555
self.assertEquals(len(tests_all), len(tests_incl) + len(tests_excl))
557
def test_list_only_random(self):
558
# check that --randomize works correctly
559
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only',
561
tests_all = self._parse_test_list(out_all.splitlines())[1]
562
out_rand,err_rand = self.run_bzr_captured(['selftest', '--list-only',
563
'selftest', '--randomize', 'now'])
564
(header_rand,tests_rand,dummy) = self._parse_test_list(
565
out_rand.splitlines(), 2)
566
self.assertNotEqual(tests_all, tests_rand)
567
self.assertEqual(sorted(tests_all), sorted(tests_rand))
568
# Check that the seed can be reused to get the exact same order
569
seed_re = re.compile('Randomizing test order using seed (\w+)')
570
match_obj = seed_re.search(header_rand[-1])
571
seed = match_obj.group(1)
572
out_rand2,err_rand2 = self.run_bzr_captured(['selftest', '--list-only',
573
'selftest', '--randomize', seed])
574
(header_rand2,tests_rand2,dummy) = self._parse_test_list(
575
out_rand2.splitlines(), 2)
576
self.assertEqual(tests_rand, tests_rand2)