1
# Copyright (C) 2006 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
"""Black-box tests for 'bzr inventory'."""
21
from bzrlib.tests import TestCaseWithTransport
24
class TestInventory(TestCaseWithTransport):
27
TestCaseWithTransport.setUp(self)
29
tree = self.make_branch_and_tree('.')
30
self.build_tree(['a', 'b/', 'b/c'])
32
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
33
tree.commit('init', rev_id='one')
36
def assertInventoryEqual(self, expected, args=None, **kwargs):
37
"""Test that the output of 'bzr inventory' is as expected.
39
Any arguments supplied will be passed to run_bzr.
44
out, err = self.run_bzr(command, **kwargs)
45
self.assertEqual(expected, out)
46
self.assertEqual('', err)
48
def test_inventory(self):
49
self.assertInventoryEqual('a\nb\nb/c\n')
51
def test_inventory_kind(self):
52
self.assertInventoryEqual('a\nb/c\n', '--kind file')
53
self.assertInventoryEqual('b\n', '--kind directory')
55
def test_inventory_show_ids(self):
56
expected = ''.join(('%-50s %s\n' % (path, file_id))
63
self.assertInventoryEqual(expected, '--show-ids')
65
def test_inventory_specific_files(self):
66
self.assertInventoryEqual('a\n', 'a')
67
self.assertInventoryEqual('b\nb/c\n', 'b b/c')
68
# 'bzr inventory' recurses into subdirectories
69
self.assertInventoryEqual('b\nb/c\n', 'b')
71
def test_inventory_mixed(self):
72
"""Test that we get expected results when mixing parameters"""
73
a_line = '%-50s %s\n' % ('a', 'a-id')
74
b_line = '%-50s %s\n' % ('b', 'b-id')
75
c_line = '%-50s %s\n' % ('b/c', 'c-id')
77
self.assertInventoryEqual('', '--kind directory a')
78
self.assertInventoryEqual(a_line + c_line, '--kind file --show-ids')
79
self.assertInventoryEqual(c_line, '--kind file --show-ids b b/c')
81
def test_in_subdir(self):
83
# TODO: jam 20060922 Maybe inventory should return the paths as
84
# relative to '.', rather than relative to root
86
# a plain 'inventory' returns all files
87
self.assertInventoryEqual('a\nb\nb/c\n')
88
# But passing '.' will only return paths underneath here
89
self.assertInventoryEqual('b\nb/c\n', '.')
92
def test_inventory_revision(self):
93
self.build_tree(['b/d', 'e'])
94
self.tree.add(['b/d', 'e'], ['d-id', 'e-id'])
95
self.tree.commit('add files')
97
self.tree.rename_one('b/d', 'd')
98
self.tree.commit('rename b/d => d')
100
# Passing just -r returns the inventory of that revision
101
self.assertInventoryEqual('a\nb\nb/c\n', '-r 1')
102
self.assertInventoryEqual('a\nb\nb/c\nb/d\ne\n', '-r 2')
104
# Passing a path will lookup the path in the old and current locations
105
self.assertInventoryEqual('b/d\n', '-r 2 b/d')
106
self.assertInventoryEqual('b/d\n', '-r 2 d')
108
self.tree.rename_one('e', 'b/e')
109
self.tree.commit('rename e => b/e')
111
# When supplying just a directory paths that are now,
112
# or used to be, in that directory are shown
113
self.assertInventoryEqual('b\nb/c\nb/d\ne\n', '-r 2 b')
115
def test_missing_file(self):
116
self.run_bzr_error([r'Path\(s\) are not versioned: no-such-file'],
117
'inventory no-such-file')