/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_check.py

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
 
 
18
"""Test operations that check the repository for corruption"""
 
19
 
 
20
 
 
21
from bzrlib import (
 
22
    errors,
 
23
    revision as _mod_revision,
 
24
    )
 
25
from bzrlib.tests import TestNotApplicable
 
26
from bzrlib.tests.repository_implementations import TestCaseWithRepository
 
27
from bzrlib.tests.repository_implementations.helpers import (
 
28
    TestCaseWithBrokenRevisionIndex,
 
29
    )
 
30
 
 
31
 
 
32
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository):
 
33
 
 
34
    def test_two_files_different_versions_no_inconsistencies_bug_165071(self):
 
35
        """Two files, with different versions can be clean."""
 
36
        tree = self.make_branch_and_tree('.')
 
37
        self.build_tree(['foo'])
 
38
        tree.smart_add(['.'])
 
39
        tree.commit('1')
 
40
        self.build_tree(['bar'])
 
41
        tree.smart_add(['.'])
 
42
        tree.commit('2')
 
43
        # XXX: check requires a non-empty revision IDs list, but it ignores the
 
44
        # contents of it!
 
45
        check_object = tree.branch.repository.check(['ignored'])
 
46
        check_object.report_results(verbose=False)
 
47
        log = self._get_log(keep_log_file=True)
 
48
        self.assertContainsRe(
 
49
            log,
 
50
            "0 unreferenced text versions")
 
51
 
 
52
 
 
53
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
 
54
 
 
55
    def test__find_inconsistent_revision_parents(self):
 
56
        """_find_inconsistent_revision_parents finds revisions with broken
 
57
        parents.
 
58
        """
 
59
        repo = self.make_repo_with_extra_ghost_index()
 
60
        self.assertEqual(
 
61
            [('revision-id', ('incorrect-parent',), ())],
 
62
            list(repo._find_inconsistent_revision_parents()))
 
63
 
 
64
    def test__check_for_inconsistent_revision_parents(self):
 
65
        """_check_for_inconsistent_revision_parents raises BzrCheckError if
 
66
        there are any revisions with inconsistent parents.
 
67
        """
 
68
        repo = self.make_repo_with_extra_ghost_index()
 
69
        self.assertRaises(
 
70
            errors.BzrCheckError,
 
71
            repo._check_for_inconsistent_revision_parents)
 
72
 
 
73
    def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
 
74
        """_check_for_inconsistent_revision_parents does nothing if there are
 
75
        no broken revisions.
 
76
        """
 
77
        repo = self.make_repository('empty-repo')
 
78
        if not repo.revision_graph_can_have_wrong_parents():
 
79
            raise TestNotApplicable(
 
80
                '%r cannot have corrupt revision index.' % repo)
 
81
        repo.lock_read()
 
82
        try:
 
83
            repo._check_for_inconsistent_revision_parents()  # nothing happens
 
84
        finally:
 
85
            repo.unlock()
 
86
 
 
87
    def test_check_reports_bad_ancestor(self):
 
88
        repo = self.make_repo_with_extra_ghost_index()
 
89
        # XXX: check requires a non-empty revision IDs list, but it ignores the
 
90
        # contents of it!
 
91
        check_object = repo.check(['ignored'])
 
92
        check_object.report_results(verbose=False)
 
93
        log = self._get_log(keep_log_file=True)
 
94
        self.assertContainsRe(
 
95
            log, '1 revisions have incorrect parents in the revision index')
 
96
        check_object.report_results(verbose=True)
 
97
        log = self._get_log(keep_log_file=True)
 
98
        self.assertContainsRe(
 
99
            log,
 
100
            "revision-id has wrong parents in index: "
 
101
            r"\('incorrect-parent',\) should be \(\)")
 
102