14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
"""Black-box tests for bzr cat.
24
from bzrlib import tests
25
from bzrlib.transport import memory
28
class TestCat(tests.TestCaseWithTransport):
25
from bzrlib.tests.blackbox import TestCaseWithTransport
27
class TestCat(TestCaseWithTransport):
30
29
def test_cat(self):
31
30
tree = self.make_branch_and_tree('branch')
70
69
def test_cat_different_id(self):
71
70
"""'cat' works with old and new files"""
72
self.disable_missing_extensions_warning()
73
71
tree = self.make_branch_and_tree('.')
74
72
# the files are named after their path in the revision and
75
73
# current trees later in the test case
76
74
# a-rev-tree is special because it appears in both the revision
77
75
# tree and the working tree
78
76
self.build_tree_contents([('a-rev-tree', 'foo\n'),
79
('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
77
('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
82
tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
83
tree.commit('add test files', rev_id='first')
84
# remove currently uses self._write_inventory -
80
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
81
tree.commit('add test files')
82
# remove currently uses self._write_inventory -
85
83
# work around that for now.
87
85
tree.remove(['d-rev'])
88
86
tree.rename_one('a-rev-tree', 'b-tree')
89
87
tree.rename_one('c-rev', 'a-rev-tree')
90
tree.rename_one('e-rev', 'old-rev')
91
self.build_tree_contents([('e-rev', 'new\n')])
94
89
# calling bzr as another process require free lock on win32
113
108
self.assertEqual('baz\n', out)
114
109
self.assertEqual('', err)
116
# the actual file-id for e-rev doesn't exist in the old tree
117
out, err = self.run_bzr_subprocess('cat e-rev -rrevid:first')
118
self.assertEqual('qux\n', out)
119
self.assertEqual('', err)
121
111
def test_remote_cat(self):
122
112
wt = self.make_branch_and_tree('.')
123
113
self.build_tree(['README'])
128
118
out, err = self.run_bzr_subprocess(['cat', url])
129
119
self.assertEqual('contents of README\n', out)
131
def test_cat_branch_revspec(self):
132
wt = self.make_branch_and_tree('a')
133
self.build_tree(['a/README'])
135
wt.commit('Making sure there is a basis_tree available')
136
wt = self.make_branch_and_tree('b')
139
out, err = self.run_bzr_subprocess(
140
['cat', '-r', 'branch:../a', 'README'])
141
self.assertEqual('contents of a/README\n', out)
143
def test_cat_filters(self):
144
wt = self.make_branch_and_tree('.')
145
self.build_tree(['README'])
147
wt.commit('Making sure there is a basis_tree available')
148
url = self.get_readonly_url() + '/README'
150
# Test unfiltered output
151
out, err = self.run_bzr_subprocess(['cat', url])
152
self.assertEqual('contents of README\n', out)
154
# Test --filters option is legal but has no impact if no filters
155
out, err = self.run_bzr_subprocess(['cat', '--filters', url])
156
self.assertEqual('contents of README\n', out)
158
def test_cat_filters_applied(self):
159
# Test filtering applied to output. This is tricky to do in a
160
# subprocess because we really need to patch in a plugin that
161
# registers the filters. Instead, we patch in a custom
162
# filter_stack and use run_bzr() ...
163
from cStringIO import StringIO
164
from bzrlib.commands import run_bzr
165
from bzrlib.tests.test_filters import _stack_2
166
from bzrlib.trace import mutter
167
from bzrlib.tree import Tree
168
wt = self.make_branch_and_tree('.')
169
self.build_tree_contents([
170
('README', "junk\nline 1 of README\nline 2 of README\n"),
173
wt.commit('Making sure there is a basis_tree available')
174
url = self.get_readonly_url() + '/README'
175
real_content_filter_stack = Tree._content_filter_stack
176
def _custom_content_filter_stack(tree, path=None, file_id=None):
178
Tree._content_filter_stack = _custom_content_filter_stack
180
out, err = self.run_bzr(['cat', url, '--filters'])
181
# The filter stack will remove the first line and swapcase the rest
182
self.assertEqual('LINE 1 OF readme\nLINE 2 OF readme\n', out)
183
self.assertEqual('', err)
185
Tree._content_filter_stack = real_content_filter_stack
187
121
def test_cat_no_working_tree(self):
188
122
wt = self.make_branch_and_tree('.')
189
123
self.build_tree(['README'])
196
130
self.assertEqual('contents of README\n', out)
198
132
def test_cat_nonexistent_branch(self):
199
self.vfs_transport_factory = memory.MemoryServer
200
self.run_bzr_error(['^bzr: ERROR: Not a branch'],
201
['cat', self.get_url()])
203
def test_cat_directory(self):
204
wt = self.make_branch_and_tree('a')
205
self.build_tree(['a/README'])
207
wt.commit('Making sure there is a basis_tree available')
209
out, err = self.run_bzr_subprocess(['cat', '--directory=a', 'README'])
210
self.assertEqual('contents of a/README\n', out)
212
def test_cat_remote_directory(self):
213
wt = self.make_branch_and_tree('a')
214
self.build_tree(['a/README'])
216
wt.commit('Making sure there is a basis_tree available')
218
url = self.get_readonly_url() + '/a'
219
out, err = self.run_bzr_subprocess(['cat', '-d', url, 'README'])
220
self.assertEqual('contents of a/README\n', out)
133
if sys.platform == "win32":
134
location = "C:/i/do/not/exist"
136
location = "/i/do/not/exist"
137
self.run_bzr_error(['^bzr: ERROR: Not a branch'], ['cat', location])