1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
28
from bzrlib.diff import (
30
format_registry as diff_format_registry,
25
from bzrlib import workingtree
26
from bzrlib.branch import Branch
27
from bzrlib.tests import TestSkipped
28
from bzrlib.tests.blackbox import ExternalBase
34
31
def subst_dates(string):
37
34
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
40
class DiffBase(tests.TestCaseWithTransport):
37
class DiffBase(ExternalBase):
41
38
"""Base class with common setup method"""
43
40
def make_example_branch(self):
136
133
out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
137
134
error_regexes=('one or two revision specifiers',))
139
def test_diff_using_and_format(self):
140
out, err = self.run_bzr('diff --format=default --using=mydi', retcode=3,
141
error_regexes=('are mutually exclusive',))
143
136
def test_diff_nonexistent_revision(self):
144
137
out, err = self.run_bzr('diff -r 123', retcode=3,
145
138
error_regexes=("Requested revision: '123' does not "
305
298
output = self.run_bzr('diff -r 1.. branch1', retcode=1)
306
299
self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
308
def test_custom_format(self):
309
class BooDiffTree(DiffTree):
311
def show_diff(self, specific_files, extra_trees=None):
312
self.to_file.write("BOO!\n")
313
return super(BooDiffTree, self).show_diff(specific_files,
316
diff_format_registry.register("boo", BooDiffTree,
318
self.addCleanup(diff_format_registry.remove, "boo")
319
self.make_example_branch()
320
self.build_tree_contents([('hello', 'hello world!\n')])
321
output = self.run_bzr('diff --format=boo', retcode=1)
322
self.assertTrue("BOO!" in output[0])
325
302
class TestCheckoutDiff(TestDiff):
379
356
def test_external_diff(self):
380
357
"""Test that we can spawn an external diff process"""
381
self.disable_missing_extensions_warning()
382
358
# We have to use run_bzr_subprocess, because we need to
383
359
# test writing directly to stdout, (there was a bug in
384
360
# subprocess.py that we had to workaround).
385
361
# However, if 'diff' may not be available
386
362
self.make_example_branch()
387
# this will be automatically restored by the base bzr test class
388
os.environ['BZR_PROGRESS_BAR'] = 'none'
389
out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
390
universal_newlines=True,
363
orig_progress = os.environ.get('BZR_PROGRESS_BAR')
365
os.environ['BZR_PROGRESS_BAR'] = 'none'
366
out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
367
universal_newlines=True,
370
if orig_progress is None:
371
del os.environ['BZR_PROGRESS_BAR']
373
os.environ['BZR_PROGRESS_BAR'] = orig_progress
392
375
if 'Diff is not installed on this machine' in err:
393
raise tests.TestSkipped("No external 'diff' is available")
376
raise TestSkipped("No external 'diff' is available")
394
377
self.assertEqual('', err)
395
378
# We have to skip the stuff in the middle, because it depends