~bzr-pqm/bzr/bzr.dev

4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2005-2010 Canonical Ltd
1185.16.32 by Martin Pool
- add a basic annotate built-in command
2
# -*- coding: utf-8 -*-
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
3
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
8
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
13
#
1185.16.32 by Martin Pool
- add a basic annotate built-in command
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
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.16.32 by Martin Pool
- add a basic annotate built-in command
17
18
19
"""Black-box tests for bzr.
20
21
These check that it behaves properly when it's invoked through the regular
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
22
command-line interface. This doesn't actually run a new interpreter but
1185.16.32 by Martin Pool
- add a basic annotate built-in command
23
rather starts again from the run_bzr function.
24
"""
25
26
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
27
from bzrlib import tests
1185.16.32 by Martin Pool
- add a basic annotate built-in command
28
3603.4.5 by Robert Collins
Fix test failure on PQM.
29
from bzrlib.config import extract_email_address
4634.120.5 by Andrew Bennetts
Add test.
30
from bzrlib.urlutils import joinpath
1185.16.32 by Martin Pool
- add a basic annotate built-in command
31
32
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
33
class TestAnnotate(tests.TestCaseWithTransport):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
34
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
35
    def setUp(self):
36
        super(TestAnnotate, self).setUp()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
37
        wt = self.make_branch_and_tree('.')
38
        b = wt.branch
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
39
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
40
                                  ('nomail.txt', 'nomail\n')])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
41
        wt.add(['hello.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
42
        self.revision_id_1 = wt.commit('add hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
43
                              committer='test@user',
44
                              timestamp=1165960000.00, timezone=0)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
45
        wt.add(['nomail.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
46
        self.revision_id_2 = wt.commit('add nomail',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
47
                              committer='no mail',
48
                              timestamp=1165970000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
49
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
50
                                                'your helicopter\n')])
51
        self.revision_id_3 = wt.commit('mod hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
52
                              committer='user@test',
53
                              timestamp=1166040000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
54
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
55
                                                'your helicopter\n'
56
                                                'all of\n'
57
                                                'our helicopters\n'
58
                                  )])
59
        self.revision_id_4 = wt.commit('mod hello',
2182.3.12 by John Arbash Meinel
Force the timezone properly during tests which look at dates.
60
                              committer='user@test',
61
                              timestamp=1166050000.00, timezone=0)
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
62
1185.16.32 by Martin Pool
- add a basic annotate built-in command
63
    def test_help_annotate(self):
64
        """Annotate command exists"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
65
        out, err = self.run_bzr('--no-plugins annotate --help')
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
66
67
    def test_annotate_cmd(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
68
        out, err = self.run_bzr('annotate hello.txt')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
69
        self.assertEqual('', err)
70
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
71
1   test@us | my helicopter
72
3   user@te | your helicopter
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
73
4   user@te | all of
74
            | our helicopters
75
''', out)
76
77
    def test_annotate_cmd_full(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
78
        out, err = self.run_bzr('annotate hello.txt --all')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
79
        self.assertEqual('', err)
80
        self.assertEqualDiff('''\
81
1   test@us | my helicopter
82
3   user@te | your helicopter
83
4   user@te | all of
84
4   user@te | our helicopters
85
''', out)
86
87
    def test_annotate_cmd_long(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
88
        out, err = self.run_bzr('annotate hello.txt --long')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
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
94
                       | our helicopters
95
''', out)
96
97
    def test_annotate_cmd_show_ids(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        out, err = self.run_bzr('annotate hello.txt --show-ids')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
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('''\
104
%*s | my helicopter
105
%*s | your helicopter
106
%*s | all of
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,
111
       max_len, '',
112
      )
113
, out)
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
114
115
    def test_no_mail(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
116
        out, err = self.run_bzr('annotate nomail.txt')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
117
        self.assertEqual('', err)
118
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
119
2   no mail | nomail
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
120
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
121
122
    def test_annotate_cmd_revision(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
123
        out, err = self.run_bzr('annotate hello.txt -r1')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
124
        self.assertEqual('', err)
125
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
126
1   test@us | my helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
127
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
128
1558.14.6 by Aaron Bentley
Added annotate test
129
    def test_annotate_cmd_revision3(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
130
        out, err = self.run_bzr('annotate hello.txt -r3')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
131
        self.assertEqual('', err)
132
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
133
1   test@us | my helicopter
134
3   user@te | your helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
135
''', out)
1558.14.6 by Aaron Bentley
Added annotate test
136
1694.2.6 by Martin Pool
[merge] bzr.dev
137
    def test_annotate_cmd_unknown_revision(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
138
        out, err = self.run_bzr('annotate hello.txt -r 10',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
139
                                retcode=3)
140
        self.assertEqual('', out)
5105.1.4 by Vincent Ladeuil
Use single quotes so that no test need to be updated.
141
        self.assertContainsRe(err, "Requested revision: '10' does not exist")
1694.2.6 by Martin Pool
[merge] bzr.dev
142
143
    def test_annotate_cmd_two_revisions(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
144
        out, err = self.run_bzr('annotate hello.txt -r1..2',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
145
                                retcode=3)
146
        self.assertEqual('', out)
147
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
148
                         ' exactly one revision identifier\n',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
149
                         err)
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
150
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
151
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
152
class TestSimpleAnnotate(tests.TestCaseWithTransport):
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
153
    """Annotate tests with no complex setup."""
154
4634.120.5 by Andrew Bennetts
Add test.
155
    def _setup_edited_file(self, relpath='.'):
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
156
        """Create a tree with a locally edited file."""
4634.120.5 by Andrew Bennetts
Add test.
157
        tree = self.make_branch_and_tree(relpath)
158
        file_relpath = joinpath(relpath, 'file')
159
        self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
160
        tree.add('file')
3603.4.3 by Robert Collins
Review feedback.
161
        tree.commit('add file', committer="test@host", rev_id="rev1")
4634.120.5 by Andrew Bennetts
Add test.
162
        self.build_tree_contents([(file_relpath, 'foo\nbar\ngam\n')])
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
163
        tree.branch.get_config().set_user_option('email', 'current@host2')
4634.120.5 by Andrew Bennetts
Add test.
164
        return tree
165
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)
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
169
        out, err = self.run_bzr(['annotate', 'file', '-r', 'branch:../trunk'],
170
                                working_dir='work')
4634.120.5 by Andrew Bennetts
Add test.
171
        self.assertEqual('', err)
172
        self.assertEqual(
173
            '1   test@ho | foo\n'
174
            '            | gam\n',
175
            out)
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
176
177
    def test_annotate_edited_file(self):
178
        tree = self._setup_edited_file()
179
        out, err = self.run_bzr('annotate file')
180
        self.assertEqual(
181
            '1   test@ho | foo\n'
182
            '2?  current | bar\n'
183
            '1   test@ho | gam\n',
184
            out)
185
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')
189
        self.assertEqual(
3603.4.3 by Robert Collins
Review feedback.
190
            '    rev1 | foo\n'
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
191
            'current: | bar\n'
3603.4.3 by Robert Collins
Review feedback.
192
            '    rev1 | gam\n',
193
            out)
194
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')])
199
        tree.add('file')
200
        tree.commit('add file', rev_id="rev1", committer="test@host")
201
        # right side
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")
205
        # left side
206
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
207
        tree.commit("left", rev_id="rev2", committer="test@host")
208
        # merge
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')])
5638.2.4 by Vincent Ladeuil
Delete one more import.
212
        return tree
3603.4.3 by Robert Collins
Review feedback.
213
214
    def test_annotated_edited_merged_file_revnos(self):
5638.2.4 by Vincent Ladeuil
Delete one more import.
215
        wt = self._create_merged_file()
216
        out, err = self.run_bzr(['annotate', 'file'])
217
        email = extract_email_address(wt.branch.get_config().username())
3603.4.3 by Robert Collins
Review feedback.
218
        self.assertEqual(
3603.4.5 by Robert Collins
Fix test failure on PQM.
219
            '3?    %-7s | local\n'
3603.4.3 by Robert Collins
Review feedback.
220
            '1     test@ho | foo\n'
221
            '1.1.1 test@ho | bar\n'
222
            '2     test@ho | baz\n'
3603.4.5 by Robert Collins
Fix test failure on PQM.
223
            '1     test@ho | gam\n' % email[:7],
3603.4.3 by Robert Collins
Review feedback.
224
            out)
225
226
    def test_annotated_edited_merged_file_ids(self):
227
        self._create_merged_file()
5638.2.4 by Vincent Ladeuil
Delete one more import.
228
        out, err = self.run_bzr(['annotate', 'file', '--show-ids'])
3603.4.3 by Robert Collins
Review feedback.
229
        self.assertEqual(
230
            'current: | local\n'
231
            '    rev1 | foo\n'
232
            'rev1.1.1 | bar\n'
233
            '    rev2 | baz\n'
234
            '    rev1 | gam\n',
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
235
            out)
236
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
237
    def test_annotate_empty_file(self):
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
238
        tree = self.make_branch_and_tree('.')
239
        self.build_tree_contents([('empty', '')])
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
240
        tree.add('empty')
241
        tree.commit('add empty file')
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
242
        out, err = self.run_bzr(['annotate', 'empty'])
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
243
        self.assertEqual('', out)
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
244
5638.2.1 by Andrew King
Fix 537442 - cannot annotate deleted file
245
    def test_annotate_removed_file(self):
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
246
        tree = self.make_branch_and_tree('.')
247
        self.build_tree_contents([('empty', '')])
5638.2.1 by Andrew King
Fix 537442 - cannot annotate deleted file
248
        tree.add('empty')
249
        tree.commit('add empty file')
250
        # delete the file.
251
        tree.remove('empty')
252
        tree.commit('remove empty file')
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
253
        out, err = self.run_bzr(['annotate', '-r1', 'empty'])
5638.2.1 by Andrew King
Fix 537442 - cannot annotate deleted file
254
        self.assertEqual('', out)
255
3960.1.1 by Vincent Ladeuil
Fix bug #314525: don't try to put ids if there is no annotation.
256
    def test_annotate_empty_file_show_ids(self):
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
257
        tree = self.make_branch_and_tree('.')
258
        self.build_tree_contents([('empty', '')])
3960.1.1 by Vincent Ladeuil
Fix bug #314525: don't try to put ids if there is no annotation.
259
        tree.add('empty')
260
        tree.commit('add empty file')
261
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
262
        self.assertEqual('', out)
263
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
264
    def test_annotate_nonexistant_file(self):
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
265
        tree = self.make_branch_and_tree('.')
266
        self.build_tree(['file'])
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
267
        tree.add(['file'])
268
        tree.commit('add a file')
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
269
        out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
270
        self.assertEqual('', out)
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
271
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
3146.2.1 by Lukáš Lalinský
Don't require a working tree in cmd_annotate.
272
273
    def test_annotate_without_workingtree(self):
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
274
        tree = self.make_branch_and_tree('.')
275
        self.build_tree_contents([('empty', '')])
3146.2.1 by Lukáš Lalinský
Don't require a working tree in cmd_annotate.
276
        tree.add('empty')
277
        tree.commit('add empty file')
278
        bzrdir = tree.branch.bzrdir
279
        bzrdir.destroy_workingtree()
280
        self.assertFalse(bzrdir.has_workingtree())
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
281
        out, err = self.run_bzr(['annotate', 'empty'])
3146.2.1 by Lukáš Lalinský
Don't require a working tree in cmd_annotate.
282
        self.assertEqual('', out)
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
283
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')
5638.2.3 by Vincent Ladeuil
Freshen up the tests to a more modern style.
290
        out, err = self.run_bzr(['annotate', '-d', 'a', 'hello.txt'])
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
291
        self.assertEqualDiff('1   test@us | my helicopter\n', out)