1
# Copyright (C) 2008 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for the view command"""
19
from bzrlib import bzrdir
20
from bzrlib.tests import TestCaseWithTransport
21
from bzrlib.workingtree import WorkingTree
24
class TestViewUI(TestCaseWithTransport):
26
def make_branch_and_tree(self):
27
# we need to use a specific format because the default format
28
# doesn't support views yet
29
format = bzrdir.format_registry.make_bzrdir('development-wt5')
30
return TestCaseWithTransport.make_branch_and_tree(self, '.',
33
def test_view_command_help(self):
34
out, err = self.run_bzr('help view')
35
self.assertContainsRe(out, 'Manage filtered views')
37
def test_define_view(self):
38
wt = self.make_branch_and_tree()
39
# Check definition of a new view
40
out, err = self.run_bzr('view a b c')
41
self.assertEquals(out, "Using 'my' view: a, b, c\n")
42
out, err = self.run_bzr('view e f --name foo')
43
self.assertEquals(out, "Using 'foo' view: e, f\n")
44
# Check re-definition of an existing view
45
out, err = self.run_bzr('view p q')
46
self.assertEquals(out, "Using 'foo' view: p, q\n")
47
out, err = self.run_bzr('view r s --name my')
48
self.assertEquals(out, "Using 'my' view: r, s\n")
49
# Check attempts to define the 'off' view are prevented
50
out, err = self.run_bzr('view a --name off', retcode=3)
51
self.assertContainsRe(err, "Cannot change the 'off' pseudo view")
53
def test_list_view(self):
54
wt = self.make_branch_and_tree()
55
# Check list of the current view
56
out, err = self.run_bzr('view')
57
self.assertEquals(out, "No current view.\n")
58
self.run_bzr('view a b c')
59
out, err = self.run_bzr('view')
60
self.assertEquals(out, "'my' view is: a, b, c\n")
61
# Check list of a named view
62
self.run_bzr('view e f --name foo')
63
out, err = self.run_bzr('view --name my')
64
self.assertEquals(out, "'my' view is: a, b, c\n")
65
out, err = self.run_bzr('view --name foo')
66
self.assertEquals(out, "'foo' view is: e, f\n")
67
# Check list of all views
68
out, err = self.run_bzr('view --all')
69
self.assertEquals(out.splitlines(), [
74
# Check list of an unknown view
75
out, err = self.run_bzr('view --name bar', retcode=3)
76
self.assertContainsRe(err, "No such view")
78
def test_delete_view(self):
79
wt = self.make_branch_and_tree()
80
# Check delete of the current view
81
out, err = self.run_bzr('view --delete', retcode=3)
82
self.assertContainsRe(err, "No current view to delete")
83
self.run_bzr('view a b c')
84
out, err = self.run_bzr('view --delete')
85
self.assertEquals(out, "Deleted 'my' view.\n")
86
# Check delete of a named view
87
self.run_bzr('view e f --name foo')
88
out, err = self.run_bzr('view --name foo --delete')
89
self.assertEquals(out, "Deleted 'foo' view.\n")
90
# Check delete of all views
91
out, err = self.run_bzr('view --delete --all')
92
self.assertEquals(out, "Deleted all views.\n")
93
# Check delete of an unknown view
94
out, err = self.run_bzr('view --delete --name bar', retcode=3)
95
self.assertContainsRe(err, "No such view")
96
# Check bad usage is reported to the user
97
out, err = self.run_bzr('view --delete --switch x', retcode=3)
98
self.assertContainsRe(err,
99
"Both --delete and --switch specified")
100
out, err = self.run_bzr('view --delete a b c', retcode=3)
101
self.assertContainsRe(err, "Both --delete and a file list specified")
103
def test_switch_view(self):
104
wt = self.make_branch_and_tree()
105
# Check switching to a named view
106
self.run_bzr('view a b c')
107
self.run_bzr('view e f --name foo')
108
out, err = self.run_bzr('view --switch my')
109
self.assertEquals(out, "Using 'my' view: a, b, c\n")
110
# Check switching off the current view does not delete it
111
out, err = self.run_bzr('view --switch off')
112
self.assertEquals(out, "Disabled 'my' view.\n")
113
# Check error reporting when attempt to switch off again
114
out, err = self.run_bzr('view --switch off', retcode=3)
115
self.assertContainsRe(err, "No current view to disable")
116
# Check bad usage is reported to the user
117
out, err = self.run_bzr('view --switch x --all', retcode=3)
118
self.assertContainsRe(err, "Both --switch and --all specified")