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.
32
from bzrlib.urlutils import joinpath
35
class TestAnnotate(tests.TestCaseWithTransport):
38
super(TestAnnotate, self).setUp()
39
wt = self.make_branch_and_tree('.')
41
self.build_tree_contents([('hello.txt', 'my helicopter\n'),
42
('nomail.txt', 'nomail\n')])
44
self.revision_id_1 = wt.commit('add hello',
45
committer='test@user',
46
timestamp=1165960000.00, timezone=0)
47
wt.add(['nomail.txt'])
48
self.revision_id_2 = wt.commit('add nomail',
50
timestamp=1165970000.00, timezone=0)
51
self.build_tree_contents([('hello.txt', 'my helicopter\n'
52
'your helicopter\n')])
53
self.revision_id_3 = wt.commit('mod hello',
54
committer='user@test',
55
timestamp=1166040000.00, timezone=0)
56
self.build_tree_contents([('hello.txt', 'my helicopter\n'
61
self.revision_id_4 = wt.commit('mod hello',
62
committer='user@test',
63
timestamp=1166050000.00, timezone=0)
65
def test_help_annotate(self):
66
"""Annotate command exists"""
67
out, err = self.run_bzr('--no-plugins annotate --help')
69
def test_annotate_cmd(self):
70
out, err = self.run_bzr('annotate hello.txt')
71
self.assertEqual('', err)
72
self.assertEqualDiff('''\
73
1 test@us | my helicopter
74
3 user@te | your helicopter
79
def test_annotate_cmd_full(self):
80
out, err = self.run_bzr('annotate hello.txt --all')
81
self.assertEqual('', err)
82
self.assertEqualDiff('''\
83
1 test@us | my helicopter
84
3 user@te | your helicopter
86
4 user@te | our helicopters
89
def test_annotate_cmd_long(self):
90
out, err = self.run_bzr('annotate hello.txt --long')
91
self.assertEqual('', err)
92
self.assertEqualDiff('''\
93
1 test@user 20061212 | my helicopter
94
3 user@test 20061213 | your helicopter
95
4 user@test 20061213 | all of
99
def test_annotate_cmd_show_ids(self):
100
out, err = self.run_bzr('annotate hello.txt --show-ids')
101
max_len = max([len(self.revision_id_1),
102
len(self.revision_id_3),
103
len(self.revision_id_4)])
104
self.assertEqual('', err)
105
self.assertEqualDiff('''\
107
%*s | your helicopter
109
%*s | our helicopters
110
''' % (max_len, self.revision_id_1,
111
max_len, self.revision_id_3,
112
max_len, self.revision_id_4,
117
def test_no_mail(self):
118
out, err = self.run_bzr('annotate nomail.txt')
119
self.assertEqual('', err)
120
self.assertEqualDiff('''\
124
def test_annotate_cmd_revision(self):
125
out, err = self.run_bzr('annotate hello.txt -r1')
126
self.assertEqual('', err)
127
self.assertEqualDiff('''\
128
1 test@us | my helicopter
131
def test_annotate_cmd_revision3(self):
132
out, err = self.run_bzr('annotate hello.txt -r3')
133
self.assertEqual('', err)
134
self.assertEqualDiff('''\
135
1 test@us | my helicopter
136
3 user@te | your helicopter
139
def test_annotate_cmd_unknown_revision(self):
140
out, err = self.run_bzr('annotate hello.txt -r 10',
142
self.assertEqual('', out)
143
self.assertContainsRe(err, "Requested revision: '10' does not exist")
145
def test_annotate_cmd_two_revisions(self):
146
out, err = self.run_bzr('annotate hello.txt -r1..2',
148
self.assertEqual('', out)
149
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
150
' exactly one revision identifier\n',
154
class TestSimpleAnnotate(tests.TestCaseWithTransport):
155
"""Annotate tests with no complex setup."""
157
def _setup_edited_file(self, relpath='.'):
158
"""Create a tree with a locally edited file."""
159
tree = self.make_branch_and_tree(relpath)
160
file_relpath = joinpath(relpath, 'file')
161
self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
163
tree.commit('add file', committer="test@host", rev_id="rev1")
164
self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
167
def test_annotate_cmd_revspec_branch(self):
168
tree = self._setup_edited_file('trunk')
169
tree.branch.create_checkout(self.get_url('work'), lightweight=True)
170
out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
172
self.assertEqual('', err)
178
def test_annotate_edited_file(self):
179
tree = self._setup_edited_file()
180
tree.branch.get_config().set_user_option('email', 'current@host2')
181
out, err = self.run_bzr('annotate file')
188
def test_annotate_edited_file_no_default(self):
189
# Ensure that when no username is available annotate still works.
190
self.overrideEnv('EMAIL', None)
191
self.overrideEnv('BZR_EMAIL', None)
192
# Also, make sure that it's not inferred from mailname.
193
self.overrideAttr(config, '_auto_user_id',
194
lambda: (None, None))
195
tree = self._setup_edited_file()
196
out, err = self.run_bzr('annotate file')
203
def test_annotate_edited_file_show_ids(self):
204
tree = self._setup_edited_file()
205
tree.branch.get_config().set_user_option('email', 'current@host2')
206
out, err = self.run_bzr('annotate file --show-ids')
213
def _create_merged_file(self):
214
"""Create a file with a pending merge and local edit."""
215
tree = self.make_branch_and_tree('.')
216
self.build_tree_contents([('file', 'foo\ngam\n')])
218
tree.commit('add file', rev_id="rev1", committer="test@host")
220
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
221
tree.commit("right", rev_id="rev1.1.1", committer="test@host")
222
tree.pull(tree.branch, True, "rev1")
224
self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
225
tree.commit("left", rev_id="rev2", committer="test@host")
227
tree.merge_from_branch(tree.branch, "rev1.1.1")
228
# edit the file to be 'resolved' and have a further local edit
229
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
232
def test_annotated_edited_merged_file_revnos(self):
233
wt = self._create_merged_file()
234
out, err = self.run_bzr(['annotate', 'file'])
235
email = config.extract_email_address(wt.branch.get_config().username())
239
'1.1.1 test@ho | bar\n'
241
'1 test@ho | gam\n' % email[:7],
244
def test_annotated_edited_merged_file_ids(self):
245
self._create_merged_file()
246
out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
255
def test_annotate_empty_file(self):
256
tree = self.make_branch_and_tree('.')
257
self.build_tree_contents([('empty', '')])
259
tree.commit('add empty file')
260
out, err = self.run_bzr(['annotate', 'empty'])
261
self.assertEqual('', out)
263
def test_annotate_removed_file(self):
264
tree = self.make_branch_and_tree('.')
265
self.build_tree_contents([('empty', '')])
267
tree.commit('add empty file')
270
tree.commit('remove empty file')
271
out, err = self.run_bzr(['annotate', '-r1', 'empty'])
272
self.assertEqual('', out)
274
def test_annotate_empty_file_show_ids(self):
275
tree = self.make_branch_and_tree('.')
276
self.build_tree_contents([('empty', '')])
278
tree.commit('add empty file')
279
out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
280
self.assertEqual('', out)
282
def test_annotate_nonexistant_file(self):
283
tree = self.make_branch_and_tree('.')
284
self.build_tree(['file'])
286
tree.commit('add a file')
287
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
288
self.assertEqual('', out)
289
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
291
def test_annotate_without_workingtree(self):
292
tree = self.make_branch_and_tree('.')
293
self.build_tree_contents([('empty', '')])
295
tree.commit('add empty file')
296
bzrdir = tree.branch.bzrdir
297
bzrdir.destroy_workingtree()
298
self.assertFalse(bzrdir.has_workingtree())
299
out, err = self.run_bzr(['annotate', 'empty'])
300
self.assertEqual('', out)
302
def test_annotate_directory(self):
303
"""Test --directory option"""
304
wt = self.make_branch_and_tree('a')
305
self.build_tree_contents([('a/hello.txt', 'my helicopter\n')])
306
wt.add(['hello.txt'])
307
wt.commit('commit', committer='test@user')
308
out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
309
self.assertEqualDiff('1 test@us | my helicopter\n', out)
312
class TestSmartServerAnnotate(tests.TestCaseWithTransport):
314
def test_simple_annotate(self):
315
self.setup_smart_server_with_call_log()
316
wt = self.make_branch_and_tree('branch')
317
self.build_tree_contents([('branch/hello.txt', 'my helicopter\n')])
318
wt.add(['hello.txt'])
319
wt.commit('commit', committer='test@user')
320
self.reset_smart_call_log()
321
out, err = self.run_bzr(['annotate', "-d", self.get_url('branch'),
323
# This figure represent the amount of work to perform this use case. It
324
# is entirely ok to reduce this number if a test fails due to rpc_count
325
# being too low. If rpc_count increases, more network roundtrips have
326
# become necessary for this use case. Please do not adjust this number
327
# upwards without agreement from bzr's network support maintainers.
328
self.assertLength(19, self.hpss_calls)