~bzr-pqm/bzr/bzr.dev

5273.1.8 by Vincent Ladeuil
Merge bzr.dev into cleanup
1
# Copyright (C) 2007-2010 Canonical Ltd
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
16
17
"""Tests for the 'check' CLI command."""
18
3015.4.15 by Daniel Watkins
Added test cases for missing objects.
19
from bzrlib.tests import ChrootedTestCase
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
20
from bzrlib.tests import TestCaseWithTransport
21
22
23
class TestCheck(TestCaseWithTransport):
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
24
25
    def test_check_no_tree(self):
2929.2.3 by Robert Collins
Review feedback.
26
        self.make_branch('.')
27
        self.run_bzr('check')
28
29
    def test_check_initial_tree(self):
30
        self.make_branch_and_tree('.')
31
        self.run_bzr('check')
32
33
    def test_check_one_commit_tree(self):
34
        tree = self.make_branch_and_tree('.')
35
        tree.commit('hallelujah')
3015.4.6 by Daniel Watkins
Modified test to ensure that check with no arguments check everything.
36
        out, err = self.run_bzr('check')
4332.3.10 by Robert Collins
Invert control of check so that trees and branches are checked by calling back into them.
37
        self.assertContainsRe(err, r"Checking working tree at '.*'\.\n")
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
38
        self.assertContainsRe(err, r"Checking repository at '.*'\.\n")
4580.1.1 by Martin Pool
check blackbox tests now handle the root being included in the file-id count
39
        # the root directory may be in the texts for rich root formats
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
40
        self.assertContainsRe(err, r"checked repository.*\n"
3015.4.6 by Daniel Watkins
Modified test to ensure that check with no arguments check everything.
41
                                   r"     1 revisions\n"
4580.1.1 by Martin Pool
check blackbox tests now handle the root being included in the file-id count
42
                                   r"     [01] file-ids\n"
4332.3.17 by Robert Collins
Check revisions as we cross check the revision index, rather than in a separate pass.
43
                                   )
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
44
        self.assertContainsRe(err, r"Checking branch at '.*'\.\n")
45
        self.assertContainsRe(err, r"checked branch.*")
3015.4.1 by Daniel Watkins
Added tests for new command line options.
46
47
    def test_check_branch(self):
48
        tree = self.make_branch_and_tree('.')
49
        tree.commit('foo')
50
        out, err = self.run_bzr('check --branch')
51
        self.assertContainsRe(err, r"^Checking branch at '.*'\.\n"
4332.3.10 by Robert Collins
Invert control of check so that trees and branches are checked by calling back into them.
52
                                   r"checked branch.*")
3015.4.1 by Daniel Watkins
Added tests for new command line options.
53
54
    def test_check_repository(self):
55
        tree = self.make_branch_and_tree('.')
56
        tree.commit('foo')
57
        out, err = self.run_bzr('check --repo')
3015.4.4 by Daniel Watkins
Strengthened tests.
58
        self.assertContainsRe(err, r"^Checking repository at '.*'\.\n"
59
                                   r"checked repository.*\n"
60
                                   r"     1 revisions\n"
4580.1.1 by Martin Pool
check blackbox tests now handle the root being included in the file-id count
61
                                   r"     [01] file-ids\n"
4332.3.17 by Robert Collins
Check revisions as we cross check the revision index, rather than in a separate pass.
62
                                   )
3015.4.1 by Daniel Watkins
Added tests for new command line options.
63
64
    def test_check_tree(self):
65
        tree = self.make_branch_and_tree('.')
66
        tree.commit('foo')
67
        out, err = self.run_bzr('check --tree')
3015.4.4 by Daniel Watkins
Strengthened tests.
68
        self.assertContainsRe(err, r"^Checking working tree at '.*'\.\n$")
3015.4.8 by Daniel Watkins
Added test to check that two flags both operate.
69
70
    def test_partial_check(self):
71
        tree = self.make_branch_and_tree('.')
72
        tree.commit('foo')
73
        out, err = self.run_bzr('check --tree --branch')
74
        self.assertContainsRe(err, r"^Checking working tree at '.*'\.\n"
75
                                   r"Checking branch at '.*'\.\n"
4332.3.10 by Robert Collins
Invert control of check so that trees and branches are checked by calling back into them.
76
                                   r"checked branch.*")
3015.4.15 by Daniel Watkins
Added test cases for missing objects.
77
78
    def test_check_missing_tree(self):
79
        branch = self.make_branch('.')
80
        out, err = self.run_bzr('check --tree')
81
        self.assertEqual(err, "No working tree found at specified location.\n")
82
3015.4.17 by Daniel Watkins
Minor test re-org.
83
    def test_check_missing_partial(self):
84
        branch = self.make_branch('.')
85
        out, err = self.run_bzr('check --tree --branch')
86
        self.assertContainsRe(err,
87
            r"Checking branch at '.*'\.\n"
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
88
            r"No working tree found at specified location\.\n"
4332.3.10 by Robert Collins
Invert control of check so that trees and branches are checked by calling back into them.
89
            r"checked branch.*")
3015.4.17 by Daniel Watkins
Minor test re-org.
90
3015.4.18 by Daniel Watkins
Added bzrlib.tests.blackbox.test_check.TestCheck.test_check_missing_branch_in_shared_repo.
91
    def test_check_missing_branch_in_shared_repo(self):
92
        self.make_repository('shared', shared=True)
93
        out, err = self.run_bzr('check --branch shared')
94
        self.assertEqual(err, "No branch found at specified location.\n")
95
3015.4.17 by Daniel Watkins
Minor test re-org.
96
97
class ChrootedCheckTests(ChrootedTestCase):
98
3015.4.15 by Daniel Watkins
Added test cases for missing objects.
99
    def test_check_missing_branch(self):
100
        out, err = self.run_bzr(
101
            'check --branch %s' % self.get_readonly_url(''))
102
        self.assertEqual(err, "No branch found at specified location.\n")
103
104
    def test_check_missing_repository(self):
105
        out, err = self.run_bzr('check --repo %s' % self.get_readonly_url(''))
106
        self.assertEqual(err, "No repository found at specified location.\n")
107
108
    def test_check_missing_everything(self):
109
        out, err = self.run_bzr('check %s' % self.get_readonly_url(''))
110
        self.assertEqual(err, "No working tree found at specified location.\n"
111
                              "No branch found at specified location.\n"
112
                              "No repository found at specified location.\n")