1
# Copyright (C) 2005 Canonical Ltd
2
# -*- coding: utf-8 -*-
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black-box tests for bzr cat.
24
from bzrlib.tests.blackbox import TestCaseWithTransport
26
class TestCat(TestCaseWithTransport):
29
tree = self.make_branch_and_tree('branch')
30
self.build_tree_contents([('branch/a', 'foo\n')])
33
# 'bzr cat' without an option should cat the last revision
34
self.run_bzr(['cat', 'a'], retcode=3)
36
tree.commit(message='1')
37
self.build_tree_contents([('a', 'baz\n')])
39
# We use run_bzr_subprocess rather than run_bzr here so that we can
40
# test mangling of line-endings on Windows.
41
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'foo\n')
43
tree.commit(message='2')
44
self.assertEquals(self.run_bzr_subprocess(['cat', 'a'])[0], 'baz\n')
45
self.assertEquals(self.run_bzr_subprocess(
46
['cat', 'a', '-r', '1'])[0],
48
self.assertEquals(self.run_bzr_subprocess(
49
['cat', 'a', '-r', '-1'])[0],
52
rev_id = tree.branch.last_revision()
54
self.assertEquals(self.run_bzr_subprocess(
55
['cat', 'a', '-r', 'revid:%s' % rev_id])[0],
60
self.assertEquals(self.run_bzr_subprocess(
61
['cat', 'branch/a', '-r', 'revno:1:branch'])[0],
63
self.run_bzr(['cat', 'a'], retcode=3)
65
['cat', 'a', '-r', 'revno:1:branch-that-does-not-exist'],
68
def test_cat_different_id(self):
69
"""'cat' works with old and new files"""
70
tree = self.make_branch_and_tree('.')
71
# the files are named after their path in the revision and
72
# current trees later in the test case
73
# a-rev-tree is special because it appears in both the revision
74
# tree and the working tree
75
self.build_tree_contents([('a-rev-tree', 'foo\n'),
76
('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
79
tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
80
tree.commit('add test files')
81
# remove currently uses self._write_inventory -
82
# work around that for now.
84
tree.remove(['d-rev'])
85
tree.rename_one('a-rev-tree', 'b-tree')
86
tree.rename_one('c-rev', 'a-rev-tree')
88
# calling bzr as another process require free lock on win32
91
# 'b-tree' is not present in the old tree.
92
self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
93
"is not present in revision .+$"],
94
'cat b-tree --name-from-revision')
96
# get to the old file automatically
97
out, err = self.run_bzr_subprocess('cat d-rev')
98
self.assertEqual('bar\n', out)
99
self.assertEqual('', err)
102
self.run_bzr_subprocess('cat a-rev-tree --name-from-revision')
103
self.assertEqual('foo\n', out)
104
self.assertEqual('', err)
106
out, err = self.run_bzr_subprocess('cat a-rev-tree')
107
self.assertEqual('baz\n', out)
108
self.assertEqual('', err)
110
def test_remote_cat(self):
111
wt = self.make_branch_and_tree('.')
112
self.build_tree(['README'])
114
wt.commit('Making sure there is a basis_tree available')
116
url = self.get_readonly_url() + '/README'
117
out, err = self.run_bzr_subprocess(['cat', url])
118
self.assertEqual('contents of README\n', out)
120
def test_cat_no_working_tree(self):
121
wt = self.make_branch_and_tree('.')
122
self.build_tree(['README'])
124
wt.commit('Making sure there is a basis_tree available')
125
wt.branch.bzrdir.destroy_workingtree()
127
url = self.get_readonly_url() + '/README'
128
out, err = self.run_bzr_subprocess(['cat', url])
129
self.assertEqual('contents of README\n', out)