1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2006-2010 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
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Black-box tests for bzr diff.
25
from bzrlib import workingtree
26
from bzrlib.branch import Branch
27
from bzrlib.tests import TestSkipped
28
from bzrlib.tests.blackbox import ExternalBase
28
from bzrlib.diff import (
30
format_registry as diff_format_registry,
32
from bzrlib.tests import (
31
37
def subst_dates(string):
34
40
'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
37
class DiffBase(ExternalBase):
43
class DiffBase(tests.TestCaseWithTransport):
38
44
"""Base class with common setup method"""
40
46
def make_example_branch(self):
133
139
out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
134
140
error_regexes=('one or two revision specifiers',))
142
def test_diff_using_and_format(self):
143
out, err = self.run_bzr('diff --format=default --using=mydi', retcode=3,
144
error_regexes=('are mutually exclusive',))
136
146
def test_diff_nonexistent_revision(self):
137
147
out, err = self.run_bzr('diff -r 123', retcode=3,
138
148
error_regexes=("Requested revision: '123' does not "
203
213
def test_diff_branches(self):
204
214
self.example_branches()
205
# should open branch1 and diff against branch2,
215
# should open branch1 and diff against branch2,
206
216
self.check_b2_vs_b1('diff -r branch:branch2 branch1')
207
217
# Compare two working trees using various syntax forms
208
218
self.check_b2_vs_b1('diff --old branch2 --new branch1')
298
308
output = self.run_bzr('diff -r 1.. branch1', retcode=1)
299
309
self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
311
def test_custom_format(self):
312
class BooDiffTree(DiffTree):
314
def show_diff(self, specific_files, extra_trees=None):
315
self.to_file.write("BOO!\n")
316
return super(BooDiffTree, self).show_diff(specific_files,
319
diff_format_registry.register("boo", BooDiffTree,
321
self.addCleanup(diff_format_registry.remove, "boo")
322
self.make_example_branch()
323
self.build_tree_contents([('hello', 'hello world!\n')])
324
output = self.run_bzr('diff --format=boo', retcode=1)
325
self.assertTrue("BOO!" in output[0])
302
327
class TestCheckoutDiff(TestDiff):
356
381
def test_external_diff(self):
357
382
"""Test that we can spawn an external diff process"""
383
self.disable_missing_extensions_warning()
358
384
# We have to use run_bzr_subprocess, because we need to
359
385
# test writing directly to stdout, (there was a bug in
360
386
# subprocess.py that we had to workaround).
361
387
# However, if 'diff' may not be available
362
388
self.make_example_branch()
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
389
# this will be automatically restored by the base bzr test class
390
os.environ['BZR_PROGRESS_BAR'] = 'none'
391
out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
392
universal_newlines=True,
375
394
if 'Diff is not installed on this machine' in err:
376
raise TestSkipped("No external 'diff' is available")
395
raise tests.TestSkipped("No external 'diff' is available")
377
396
self.assertEqual('', err)
378
397
# We have to skip the stuff in the middle, because it depends
383
402
self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
405
def test_external_diff_options_and_using(self):
406
"""Test that the options are passed correctly to an external diff process"""
407
self.requireFeature(features.diff_feature)
408
self.make_example_branch()
409
self.build_tree_contents([('hello', 'Foo\n')])
410
out, err = self.run_bzr('diff --diff-options -i --using diff',
412
self.assertEquals("=== modified file 'hello'\n", out)
413
self.assertEquals('', err)
387
416
class TestDiffOutput(DiffBase):