214
214
self.assertEqual(out.splitlines(True) + ['\n'], lines)
217
class TestShowDiffTreesHelper(TestCaseWithTransport):
218
"""Has a helper for running show_diff_trees"""
220
def get_diff(self, tree1, tree2, specific_files=None, working_tree=None):
222
if working_tree is not None:
223
extra_trees = (working_tree,)
226
show_diff_trees(tree1, tree2, output, specific_files=specific_files,
227
extra_trees=extra_trees, old_label='old/',
229
return output.getvalue()
232
class TestDiffDates(TestShowDiffTreesHelper):
217
class TestDiffDates(TestCaseWithTransport):
235
220
super(TestDiffDates, self).setUp()
269
254
# set the date stamps for files in the working tree to known values
270
255
os.utime('file1', (1144195200, 1144195200)) # 2006-04-05 00:00:00 UTC
257
def get_diff(self, tree1, tree2, specific_files=None, working_tree=None):
259
if working_tree is not None:
260
extra_trees = (working_tree,)
263
show_diff_trees(tree1, tree2, output, specific_files=specific_files,
264
extra_trees=extra_trees, old_label='old/',
266
return output.getvalue()
272
268
def test_diff_rev_tree_working_tree(self):
273
269
output = self.get_diff(self.wt.basis_tree(), self.wt)
274
270
# note that the date for old/file1 is from rev 2 rather than from
358
354
self.assertNotContainsRe(out, 'file1\t')
362
class TestShowDiffTrees(TestShowDiffTreesHelper):
363
"""Direct tests for show_diff_trees"""
365
def test_modified_file(self):
366
"""Test when a file is modified."""
367
tree = self.make_branch_and_tree('tree')
368
self.build_tree_contents([('tree/file', 'contents\n')])
369
tree.add(['file'], ['file-id'])
370
tree.commit('one', rev_id='rev-1')
372
self.build_tree_contents([('tree/file', 'new contents\n')])
373
diff = self.get_diff(tree.basis_tree(), tree)
374
self.assertContainsRe(diff, "=== modified file 'file'\n")
375
self.assertContainsRe(diff, '--- old/file\t')
376
self.assertContainsRe(diff, '\\+\\+\\+ new/file\t')
377
self.assertContainsRe(diff, '-contents\n'
380
def test_modified_file_in_renamed_dir(self):
381
"""Test when a file is modified in a renamed directory."""
382
tree = self.make_branch_and_tree('tree')
383
self.build_tree(['tree/dir/'])
384
self.build_tree_contents([('tree/dir/file', 'contents\n')])
385
tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
386
tree.commit('one', rev_id='rev-1')
388
tree.rename_one('dir', 'other')
389
self.build_tree_contents([('tree/other/file', 'new contents\n')])
390
diff = self.get_diff(tree.basis_tree(), tree)
391
self.assertContainsRe(diff, "=== renamed directory 'dir' => 'other'\n")
392
self.assertContainsRe(diff, "=== modified file 'other/file'\n")
393
# XXX: This is technically incorrect, because it used to be at another
394
# location. What to do?
395
self.assertContainsRe(diff, '--- old/dir/file\t')
396
self.assertContainsRe(diff, '\\+\\+\\+ new/other/file\t')
397
self.assertContainsRe(diff, '-contents\n'
400
def test_renamed_directory(self):
401
"""Test when only a directory is only renamed."""
402
tree = self.make_branch_and_tree('tree')
403
self.build_tree(['tree/dir/'])
404
self.build_tree_contents([('tree/dir/file', 'contents\n')])
405
tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
406
tree.commit('one', rev_id='rev-1')
408
tree.rename_one('dir', 'newdir')
409
diff = self.get_diff(tree.basis_tree(), tree)
410
# Renaming a directory should be a single "you renamed this dir" even
411
# when there are files inside.
412
self.assertEqual("=== renamed directory 'dir' => 'newdir'\n", diff)
414
def test_renamed_file(self):
415
"""Test when a file is only renamed."""
416
tree = self.make_branch_and_tree('tree')
417
self.build_tree_contents([('tree/file', 'contents\n')])
418
tree.add(['file'], ['file-id'])
419
tree.commit('one', rev_id='rev-1')
421
tree.rename_one('file', 'newname')
422
diff = self.get_diff(tree.basis_tree(), tree)
423
self.assertContainsRe(diff, "=== renamed file 'file' => 'newname'\n")
424
# We shouldn't have a --- or +++ line, because there is no content
426
self.assertNotContainsRe(diff, '---')
428
def test_renamed_and_modified_file(self):
429
"""Test when a file is only renamed."""
430
tree = self.make_branch_and_tree('tree')
431
self.build_tree_contents([('tree/file', 'contents\n')])
432
tree.add(['file'], ['file-id'])
433
tree.commit('one', rev_id='rev-1')
435
tree.rename_one('file', 'newname')
436
self.build_tree_contents([('tree/newname', 'new contents\n')])
437
diff = self.get_diff(tree.basis_tree(), tree)
438
self.assertContainsRe(diff, "=== renamed file 'file' => 'newname'\n")
439
self.assertContainsRe(diff, '--- old/file\t')
440
self.assertContainsRe(diff, '\\+\\+\\+ new/newname\t')
441
self.assertContainsRe(diff, '-contents\n'
445
357
class TestPatienceDiffLib(TestCase):
447
359
def test_unique_lcs(self):