1
# Copyright (C) 2005-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""Black-box tests for bzr.
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface. This doesn't actually run a new interpreter but
23
rather starts again from the run_bzr function.
27
from bzrlib import tests
29
from bzrlib.config import extract_email_address
30
from bzrlib.urlutils import joinpath
33
class TestAnnotate(tests.TestCaseWithTransport):
36
super(TestAnnotate, self).setUp()
37
wt = self.make_branch_and_tree('.')
39
self.build_tree_contents([('hello.txt', 'my helicopter\n'),
40
('nomail.txt', 'nomail\n')])
42
self.revision_id_1 = wt.commit('add hello',
43
committer='test@user',
44
timestamp=1165960000.00, timezone=0)
45
wt.add(['nomail.txt'])
46
self.revision_id_2 = wt.commit('add nomail',
48
timestamp=1165970000.00, timezone=0)
49
self.build_tree_contents([('hello.txt', 'my helicopter\n'
50
'your helicopter\n')])
51
self.revision_id_3 = wt.commit('mod hello',
52
committer='user@test',
53
timestamp=1166040000.00, timezone=0)
54
self.build_tree_contents([('hello.txt', 'my helicopter\n'
59
self.revision_id_4 = wt.commit('mod hello',
60
committer='user@test',
61
timestamp=1166050000.00, timezone=0)
63
def test_help_annotate(self):
64
"""Annotate command exists"""
65
out, err = self.run_bzr('--no-plugins annotate --help')
67
def test_annotate_cmd(self):
68
out, err = self.run_bzr('annotate hello.txt')
69
self.assertEqual('', err)
70
self.assertEqualDiff('''\
71
1 test@us | my helicopter
72
3 user@te | your helicopter
77
def test_annotate_cmd_full(self):
78
out, err = self.run_bzr('annotate hello.txt --all')
79
self.assertEqual('', err)
80
self.assertEqualDiff('''\
81
1 test@us | my helicopter
82
3 user@te | your helicopter
84
4 user@te | our helicopters
87
def test_annotate_cmd_long(self):
88
out, err = self.run_bzr('annotate hello.txt --long')
89
self.assertEqual('', err)
90
self.assertEqualDiff('''\
91
1 test@user 20061212 | my helicopter
92
3 user@test 20061213 | your helicopter
93
4 user@test 20061213 | all of
97
def test_annotate_cmd_show_ids(self):
98
out, err = self.run_bzr('annotate hello.txt --show-ids')
99
max_len = max([len(self.revision_id_1),
100
len(self.revision_id_3),
101
len(self.revision_id_4)])
102
self.assertEqual('', err)
103
self.assertEqualDiff('''\
105
%*s | your helicopter
107
%*s | our helicopters
108
''' % (max_len, self.revision_id_1,
109
max_len, self.revision_id_3,
110
max_len, self.revision_id_4,
115
def test_no_mail(self):
116
out, err = self.run_bzr('annotate nomail.txt')
117
self.assertEqual('', err)
118
self.assertEqualDiff('''\
122
def test_annotate_cmd_revision(self):
123
out, err = self.run_bzr('annotate hello.txt -r1')
124
self.assertEqual('', err)
125
self.assertEqualDiff('''\
126
1 test@us | my helicopter
129
def test_annotate_cmd_revision3(self):
130
out, err = self.run_bzr('annotate hello.txt -r3')
131
self.assertEqual('', err)
132
self.assertEqualDiff('''\
133
1 test@us | my helicopter
134
3 user@te | your helicopter
137
def test_annotate_cmd_unknown_revision(self):
138
out, err = self.run_bzr('annotate hello.txt -r 10',
140
self.assertEqual('', out)
141
self.assertContainsRe(err, "Requested revision: '10' does not exist")
143
def test_annotate_cmd_two_revisions(self):
144
out, err = self.run_bzr('annotate hello.txt -r1..2',
146
self.assertEqual('', out)
147
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
148
' exactly one revision identifier\n',
152
class TestSimpleAnnotate(tests.TestCaseWithTransport):
153
"""Annotate tests with no complex setup."""
155
def _setup_edited_file(self, relpath='.'):
156
"""Create a tree with a locally edited file."""
157
tree = self.make_branch_and_tree(relpath)
158
file_relpath = joinpath(relpath, 'file')
159
self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
161
tree.commit('add file', committer="test@host", rev_id="rev1")
162
self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
163
tree.branch.get_config().set_user_option('email', 'current@host2')
166
def test_annotate_cmd_revspec_branch(self):
167
tree = self._setup_edited_file('trunk')
168
tree.branch.create_checkout(self.get_url('work'), lightweight=True)
169
out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
171
self.assertEqual('', err)
177
def test_annotate_edited_file(self):
178
tree = self._setup_edited_file()
179
out, err = self.run_bzr('annotate file')
186
def test_annotate_edited_file_show_ids(self):
187
tree = self._setup_edited_file()
188
out, err = self.run_bzr('annotate file --show-ids')
195
def _create_merged_file(self):
196
"""Create a file with a pending merge and local edit."""
197
tree = self.make_branch_and_tree('.')
198
self.build_tree_contents([('file', 'foo\ngam\n')])
200
tree.commit('add file', rev_id="rev1", committer="test@host")
202
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
203
tree.commit("right", rev_id="rev1.1.1", committer="test@host")
204
tree.pull(tree.branch, True, "rev1")
206
self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
207
tree.commit("left", rev_id="rev2", committer="test@host")
209
tree.merge_from_branch(tree.branch, "rev1.1.1")
210
# edit the file to be 'resolved' and have a further local edit
211
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
214
def test_annotated_edited_merged_file_revnos(self):
215
wt = self._create_merged_file()
216
out, err = self.run_bzr(['annotate', 'file'])
217
email = extract_email_address(wt.branch.get_config().username())
221
'1.1.1 test@ho | bar\n'
223
'1 test@ho | gam\n' % email[:7],
226
def test_annotated_edited_merged_file_ids(self):
227
self._create_merged_file()
228
out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
237
def test_annotate_empty_file(self):
238
tree = self.make_branch_and_tree('.')
239
self.build_tree_contents([('empty', '')])
241
tree.commit('add empty file')
242
out, err = self.run_bzr(['annotate', 'empty'])
243
self.assertEqual('', out)
245
def test_annotate_removed_file(self):
246
tree = self.make_branch_and_tree('.')
247
self.build_tree_contents([('empty', '')])
249
tree.commit('add empty file')
252
tree.commit('remove empty file')
253
out, err = self.run_bzr(['annotate', '-r1', 'empty'])
254
self.assertEqual('', out)
256
def test_annotate_empty_file_show_ids(self):
257
tree = self.make_branch_and_tree('.')
258
self.build_tree_contents([('empty', '')])
260
tree.commit('add empty file')
261
out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
262
self.assertEqual('', out)
264
def test_annotate_nonexistant_file(self):
265
tree = self.make_branch_and_tree('.')
266
self.build_tree(['file'])
268
tree.commit('add a file')
269
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
270
self.assertEqual('', out)
271
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
273
def test_annotate_without_workingtree(self):
274
tree = self.make_branch_and_tree('.')
275
self.build_tree_contents([('empty', '')])
277
tree.commit('add empty file')
278
bzrdir = tree.branch.bzrdir
279
bzrdir.destroy_workingtree()
280
self.assertFalse(bzrdir.has_workingtree())
281
out, err = self.run_bzr(['annotate', 'empty'])
282
self.assertEqual('', out)
284
def test_annotate_directory(self):
285
"""Test --directory option"""
286
wt = self.make_branch_and_tree('a')
287
self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
288
wt.add(['hello.txt'])
289
wt.commit('commit', committer='test@user')
290
out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
291
self.assertEqualDiff('1 test@us | my helicopter\n', out)