14
14
# You should have received a copy of the GNU General Public License
15
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
"""Black-box tests for bzr.
21
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
22
command-line interface. This doesn't actually run a new interpreter but
23
23
rather starts again from the run_bzr function.
29
from bzrlib.branch import Branch
30
from bzrlib.config import extract_email_address
31
from bzrlib.tests import TestCaseWithTransport
34
class TestAnnotate(TestCaseWithTransport):
32
from bzrlib.urlutils import joinpath
35
class TestAnnotate(tests.TestCaseWithTransport):
37
38
super(TestAnnotate, self).setUp()
153
class TestSimpleAnnotate(TestCaseWithTransport):
154
class TestSimpleAnnotate(tests.TestCaseWithTransport):
154
155
"""Annotate tests with no complex setup."""
156
def _setup_edited_file(self):
157
def _setup_edited_file(self, relpath='.'):
157
158
"""Create a tree with a locally edited file."""
158
tree = self.make_branch_and_tree('.')
159
self.build_tree_contents([('file', 'foo\ngam\n')])
159
tree = self.make_branch_and_tree(relpath)
160
file_relpath = joinpath(relpath, 'file')
161
self.build_tree_contents([(file_relpath, 'foo\ngam\n')])
161
163
tree.commit('add file', committer="test@host", rev_id="rev1")
162
self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
163
tree.branch.get_config().set_user_option('email', 'current@host2')
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)
165
178
def test_annotate_edited_file(self):
166
179
tree = self._setup_edited_file()
180
tree.branch.get_config().set_user_option('email', 'current@host2')
167
181
out, err = self.run_bzr('annotate file')
168
182
self.assertEqual(
169
183
'1 test@ho | foo\n'
171
185
'1 test@ho | gam\n',
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')
174
203
def test_annotate_edited_file_show_ids(self):
175
204
tree = self._setup_edited_file()
205
tree.branch.get_config().set_user_option('email', 'current@host2')
176
206
out, err = self.run_bzr('annotate file --show-ids')
177
207
self.assertEqual(
197
227
tree.merge_from_branch(tree.branch, "rev1.1.1")
198
228
# edit the file to be 'resolved' and have a further local edit
199
229
self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
201
232
def test_annotated_edited_merged_file_revnos(self):
202
self._create_merged_file()
203
out, err = self.run_bzr('annotate file')
204
email = extract_email_address(Branch.open('.').get_config().username())
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())
205
236
self.assertEqual(
206
237
'3? %-7s | local\n'
207
238
'1 test@ho | foo\n'
224
255
def test_annotate_empty_file(self):
225
tree = self.make_branch_and_tree('tree')
226
self.build_tree_contents([('tree/empty', '')])
228
tree.commit('add empty file')
231
out, err = self.run_bzr('annotate empty')
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'])
232
280
self.assertEqual('', out)
234
282
def test_annotate_nonexistant_file(self):
235
tree = self.make_branch_and_tree('tree')
236
self.build_tree(['tree/file'])
283
tree = self.make_branch_and_tree('.')
284
self.build_tree(['file'])
237
285
tree.add(['file'])
238
286
tree.commit('add a file')
241
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
287
out, err = self.run_bzr(['annotate', 'doesnotexist'], retcode=3)
242
288
self.assertEqual('', out)
243
289
self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
245
291
def test_annotate_without_workingtree(self):
246
tree = self.make_branch_and_tree('branch')
247
self.build_tree_contents([('branch/empty', '')])
292
tree = self.make_branch_and_tree('.')
293
self.build_tree_contents([('empty', '')])
248
294
tree.add('empty')
249
295
tree.commit('add empty file')
250
296
bzrdir = tree.branch.bzrdir
251
297
bzrdir.destroy_workingtree()
252
298
self.assertFalse(bzrdir.has_workingtree())
299
out, err = self.run_bzr(['annotate', 'empty'])
300
self.assertEqual('', out)
255
out, err = self.run_bzr('annotate empty')
256
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)