1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for the 'check' CLI command."""
19
from bzrlib.tests import ChrootedTestCase
20
from bzrlib.tests.blackbox import ExternalBase
23
class TestCheck(ExternalBase):
25
def test_check_no_tree(self):
29
def test_check_initial_tree(self):
30
self.make_branch_and_tree('.')
33
def test_check_one_commit_tree(self):
34
tree = self.make_branch_and_tree('.')
35
tree.commit('hallelujah')
36
out, err = self.run_bzr('check')
37
self.assertContainsRe(err, r"^Checking working tree at '.*'\.\n"
38
r"Checking repository at '.*'\.\n"
39
r"checked repository.*\n"
42
r" 0 unique file texts\n"
43
r" 0 repeated file texts\n"
44
r" 0 unreferenced text versions\n"
45
r"Checking branch at '.*'\.\n"
46
r"checked branch.*\n$")
48
def test_check_branch(self):
49
tree = self.make_branch_and_tree('.')
51
out, err = self.run_bzr('check --branch')
52
self.assertContainsRe(err, r"^Checking branch at '.*'\.\n"
53
r"checked branch.*\n$")
55
def test_check_repository(self):
56
tree = self.make_branch_and_tree('.')
58
out, err = self.run_bzr('check --repo')
59
self.assertContainsRe(err, r"^Checking repository at '.*'\.\n"
60
r"checked repository.*\n"
63
r" 0 unique file texts\n"
64
r" 0 repeated file texts\n"
65
r" 0 unreferenced text versions$")
67
def test_check_tree(self):
68
tree = self.make_branch_and_tree('.')
70
out, err = self.run_bzr('check --tree')
71
self.assertContainsRe(err, r"^Checking working tree at '.*'\.\n$")
73
def test_partial_check(self):
74
tree = self.make_branch_and_tree('.')
76
out, err = self.run_bzr('check --tree --branch')
77
self.assertContainsRe(err, r"^Checking working tree at '.*'\.\n"
78
r"Checking branch at '.*'\.\n"
79
r"checked branch.*\n$")
81
def test_check_missing_tree(self):
82
branch = self.make_branch('.')
83
out, err = self.run_bzr('check --tree')
84
self.assertEqual(err, "No working tree found at specified location.\n")
86
def test_check_missing_partial(self):
87
branch = self.make_branch('.')
88
out, err = self.run_bzr('check --tree --branch')
89
self.assertContainsRe(err,
90
r"^No working tree found at specified location\.\n"
91
r"Checking branch at '.*'\.\n"
92
r"checked branch.*\n$")
94
def test_check_missing_branch_in_shared_repo(self):
95
self.make_repository('shared', shared=True)
96
out, err = self.run_bzr('check --branch shared')
97
self.assertEqual(err, "No branch found at specified location.\n")
100
class ChrootedCheckTests(ChrootedTestCase):
102
def test_check_missing_branch(self):
103
out, err = self.run_bzr(
104
'check --branch %s' % self.get_readonly_url(''))
105
self.assertEqual(err, "No branch found at specified location.\n")
107
def test_check_missing_repository(self):
108
out, err = self.run_bzr('check --repo %s' % self.get_readonly_url(''))
109
self.assertEqual(err, "No repository found at specified location.\n")
111
def test_check_missing_everything(self):
112
out, err = self.run_bzr('check %s' % self.get_readonly_url(''))
113
self.assertEqual(err, "No working tree found at specified location.\n"
114
"No branch found at specified location.\n"
115
"No repository found at specified location.\n")