~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005 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
27
import os
28
3603.4.5 by Robert Collins
Fix test failure on PQM.
29
from bzrlib.branch import Branch
30
from bzrlib.config import extract_email_address
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
31
from bzrlib.tests import TestCaseWithTransport
1185.16.32 by Martin Pool
- add a basic annotate built-in command
32
33
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
34
class TestAnnotate(TestCaseWithTransport):
35
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
36
    def setUp(self):
37
        super(TestAnnotate, self).setUp()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
38
        wt = self.make_branch_and_tree('.')
39
        b = wt.branch
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
40
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
41
                                  ('nomail.txt', 'nomail\n')])
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
42
        wt.add(['hello.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
43
        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.
44
                              committer='test@user',
45
                              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.
46
        wt.add(['nomail.txt'])
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
47
        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.
48
                              committer='no mail',
49
                              timestamp=1165970000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
50
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
51
                                                'your helicopter\n')])
52
        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.
53
                              committer='user@test',
54
                              timestamp=1166040000.00, timezone=0)
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
55
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
56
                                                'your helicopter\n'
57
                                                'all of\n'
58
                                                'our helicopters\n'
59
                                  )])
60
        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.
61
                              committer='user@test',
62
                              timestamp=1166050000.00, timezone=0)
1185.16.53 by Martin Pool
- annotate improvements from Goffreddo, with extra bug fixes and tests
63
1185.16.32 by Martin Pool
- add a basic annotate built-in command
64
    def test_help_annotate(self):
65
        """Annotate command exists"""
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
66
        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
67
68
    def test_annotate_cmd(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
69
        out, err = self.run_bzr('annotate hello.txt')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
70
        self.assertEqual('', err)
71
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
72
1   test@us | my helicopter
73
3   user@te | your helicopter
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
74
4   user@te | all of
75
            | our helicopters
76
''', out)
77
78
    def test_annotate_cmd_full(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
79
        out, err = self.run_bzr('annotate hello.txt --all')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
80
        self.assertEqual('', err)
81
        self.assertEqualDiff('''\
82
1   test@us | my helicopter
83
3   user@te | your helicopter
84
4   user@te | all of
85
4   user@te | our helicopters
86
''', out)
87
88
    def test_annotate_cmd_long(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
89
        out, err = self.run_bzr('annotate hello.txt --long')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
90
        self.assertEqual('', err)
91
        self.assertEqualDiff('''\
92
1   test@user 20061212 | my helicopter
93
3   user@test 20061213 | your helicopter
94
4   user@test 20061213 | all of
95
                       | our helicopters
96
''', out)
97
98
    def test_annotate_cmd_show_ids(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
99
        out, err = self.run_bzr('annotate hello.txt --show-ids')
2182.3.7 by John Arbash Meinel
Cleanup and add blackbox tests for annotate.
100
        max_len = max([len(self.revision_id_1),
101
                       len(self.revision_id_3),
102
                       len(self.revision_id_4)])
103
        self.assertEqual('', err)
104
        self.assertEqualDiff('''\
105
%*s | my helicopter
106
%*s | your helicopter
107
%*s | all of
108
%*s | our helicopters
109
''' % (max_len, self.revision_id_1,
110
       max_len, self.revision_id_3,
111
       max_len, self.revision_id_4,
112
       max_len, '',
113
      )
114
, out)
1185.33.31 by Martin Pool
Make annotate cope better with revisions committed without a valid
115
116
    def test_no_mail(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
117
        out, err = self.run_bzr('annotate nomail.txt')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
118
        self.assertEqual('', err)
119
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
120
2   no mail | nomail
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
121
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
122
123
    def test_annotate_cmd_revision(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
124
        out, err = self.run_bzr('annotate hello.txt -r1')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
125
        self.assertEqual('', err)
126
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
127
1   test@us | my helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
128
''', out)
1694.2.6 by Martin Pool
[merge] bzr.dev
129
1558.14.6 by Aaron Bentley
Added annotate test
130
    def test_annotate_cmd_revision3(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
131
        out, err = self.run_bzr('annotate hello.txt -r3')
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
132
        self.assertEqual('', err)
133
        self.assertEqualDiff('''\
2182.3.3 by John Arbash Meinel
Add tests for annotate with dotted revnos.
134
1   test@us | my helicopter
135
3   user@te | your helicopter
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
136
''', out)
1558.14.6 by Aaron Bentley
Added annotate test
137
1694.2.6 by Martin Pool
[merge] bzr.dev
138
    def test_annotate_cmd_unknown_revision(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
139
        out, err = self.run_bzr('annotate hello.txt -r 10',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
140
                                retcode=3)
141
        self.assertEqual('', out)
1948.4.15 by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable
142
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
1694.2.6 by Martin Pool
[merge] bzr.dev
143
144
    def test_annotate_cmd_two_revisions(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
145
        out, err = self.run_bzr('annotate hello.txt -r1..2',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
146
                                retcode=3)
147
        self.assertEqual('', out)
148
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
3655.3.1 by Lukáš Lalinský
Fix `bzr st -rbranch:PATH_TO_BRANCH`
149
                         ' exactly one revision identifier\n',
2182.3.6 by John Arbash Meinel
Cleanup annotate blackbox tests
150
                         err)
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
151
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
152
153
class TestSimpleAnnotate(TestCaseWithTransport):
154
    """Annotate tests with no complex setup."""
155
156
    def _setup_edited_file(self):
157
        """Create a tree with a locally edited file."""
158
        tree = self.make_branch_and_tree('.')
159
        self.build_tree_contents([('file', 'foo\ngam\n')])
160
        tree.add('file')
3603.4.3 by Robert Collins
Review feedback.
161
        tree.commit('add file', committer="test@host", rev_id="rev1")
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
162
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
163
        tree.branch.get_config().set_user_option('email', 'current@host2')
164
165
    def test_annotate_edited_file(self):
166
        tree = self._setup_edited_file()
167
        out, err = self.run_bzr('annotate file')
168
        self.assertEqual(
169
            '1   test@ho | foo\n'
170
            '2?  current | bar\n'
171
            '1   test@ho | gam\n',
172
            out)
173
174
    def test_annotate_edited_file_show_ids(self):
175
        tree = self._setup_edited_file()
176
        out, err = self.run_bzr('annotate file --show-ids')
177
        self.assertEqual(
3603.4.3 by Robert Collins
Review feedback.
178
            '    rev1 | foo\n'
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
179
            'current: | bar\n'
3603.4.3 by Robert Collins
Review feedback.
180
            '    rev1 | gam\n',
181
            out)
182
183
    def _create_merged_file(self):
184
        """Create a file with a pending merge and local edit."""
185
        tree = self.make_branch_and_tree('.')
186
        self.build_tree_contents([('file', 'foo\ngam\n')])
187
        tree.add('file')
188
        tree.commit('add file', rev_id="rev1", committer="test@host")
189
        # right side
190
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
191
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
192
        tree.pull(tree.branch, True, "rev1")
193
        # left side
194
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
195
        tree.commit("left", rev_id="rev2", committer="test@host")
196
        # merge
197
        tree.merge_from_branch(tree.branch, "rev1.1.1")
198
        # edit the file to be 'resolved' and have a further local edit
199
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
200
201
    def test_annotated_edited_merged_file_revnos(self):
202
        self._create_merged_file()
203
        out, err = self.run_bzr('annotate file')
3603.4.5 by Robert Collins
Fix test failure on PQM.
204
        email = extract_email_address(Branch.open('.').get_config().username())
3603.4.3 by Robert Collins
Review feedback.
205
        self.assertEqual(
3603.4.5 by Robert Collins
Fix test failure on PQM.
206
            '3?    %-7s | local\n'
3603.4.3 by Robert Collins
Review feedback.
207
            '1     test@ho | foo\n'
208
            '1.1.1 test@ho | bar\n'
209
            '2     test@ho | baz\n'
3603.4.5 by Robert Collins
Fix test failure on PQM.
210
            '1     test@ho | gam\n' % email[:7],
3603.4.3 by Robert Collins
Review feedback.
211
            out)
212
213
    def test_annotated_edited_merged_file_ids(self):
214
        self._create_merged_file()
215
        out, err = self.run_bzr('annotate file --show-ids')
216
        self.assertEqual(
217
            'current: | local\n'
218
            '    rev1 | foo\n'
219
            'rev1.1.1 | bar\n'
220
            '    rev2 | baz\n'
221
            '    rev1 | gam\n',
3603.4.1 by Robert Collins
Implement lookups into the current working tree for bzr annotate, fixing bug 3439.
222
            out)
223
2027.3.1 by John Arbash Meinel
'bzr annotate' shouldn't fail on an empty file: fix bug #56814
224
    def test_annotate_empty_file(self):
225
        tree = self.make_branch_and_tree('tree')
226
        self.build_tree_contents([('tree/empty', '')])
227
        tree.add('empty')
228
        tree.commit('add empty file')
229
230
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
231
        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
232
        self.assertEqual('', out)
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
233
3960.1.1 by Vincent Ladeuil
Fix bug #314525: don't try to put ids if there is no annotation.
234
    def test_annotate_empty_file_show_ids(self):
235
        tree = self.make_branch_and_tree('tree')
236
        self.build_tree_contents([('tree/empty', '')])
237
        tree.add('empty')
238
        tree.commit('add empty file')
239
240
        os.chdir('tree')
241
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
242
        self.assertEqual('', out)
243
2561.2.1 by James Westby
Display a useful error message when annotating a non-existant file (#122656)
244
    def test_annotate_nonexistant_file(self):
245
        tree = self.make_branch_and_tree('tree')
246
        self.build_tree(['tree/file'])
247
        tree.add(['file'])
248
        tree.commit('add a file')
249
250
        os.chdir('tree')
251
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
252
        self.assertEqual('', out)
2745.3.2 by Daniel Watkins
Updated tests to reflect new error text.
253
        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.
254
255
    def test_annotate_without_workingtree(self):
256
        tree = self.make_branch_and_tree('branch')
257
        self.build_tree_contents([('branch/empty', '')])
258
        tree.add('empty')
259
        tree.commit('add empty file')
260
        bzrdir = tree.branch.bzrdir
261
        bzrdir.destroy_workingtree()
262
        self.assertFalse(bzrdir.has_workingtree())
263
264
        os.chdir('branch')
265
        out, err = self.run_bzr('annotate empty')
266
        self.assertEqual('', out)