~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-13 06:08:53 UTC
  • mfrom: (4737.1.1 merge-2.0-into-devel)
  • Revision ID: pqm@pqm.ubuntu.com-20091013060853-erk2aaj80fnkrv25
(andrew) Merge lp:bzr/2.0 into lp:bzr, including fixes for #322807,
        #389413, #402623 and documentation improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for bzr diff."""
 
18
"""Black-box tests for bzr diff.
 
19
"""
19
20
 
20
21
import os
21
22
import re
24
25
    tests,
25
26
    workingtree,
26
27
    )
27
 
from bzrlib.diff import (
28
 
    DiffTree,
29
 
    format_registry as diff_format_registry,
30
 
    )
31
 
from bzrlib.tests import (
32
 
    features,
33
 
    )
34
28
 
35
29
 
36
30
def subst_dates(string):
138
132
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
139
133
            error_regexes=('one or two revision specifiers',))
140
134
 
141
 
    def test_diff_using_and_format(self):
142
 
        out, err = self.run_bzr('diff --format=default --using=mydi', retcode=3,
143
 
            error_regexes=('are mutually exclusive',))
144
 
 
145
135
    def test_diff_nonexistent_revision(self):
146
136
        out, err = self.run_bzr('diff -r 123', retcode=3,
147
137
            error_regexes=("Requested revision: '123' does not "
287
277
        self.example_branch2()
288
278
        self.build_tree_contents([('branch1/file1', 'new line')])
289
279
        os.mkdir('branch1/dir1')
290
 
        output = self.run_bzr('diff -r 1..', retcode=1,
291
 
                              working_dir='branch1/dir1')
 
280
        os.chdir('branch1/dir1')
 
281
        output = self.run_bzr('diff -r 1..', retcode=1)
292
282
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
293
283
 
294
284
    def test_diff_across_rename(self):
307
297
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
308
298
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
309
299
 
310
 
    def test_custom_format(self):
311
 
        class BooDiffTree(DiffTree):
312
 
 
313
 
            def show_diff(self, specific_files, extra_trees=None):
314
 
                self.to_file.write("BOO!\n")
315
 
                return super(BooDiffTree, self).show_diff(specific_files,
316
 
                    extra_trees)
317
 
 
318
 
        diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
319
 
        self.addCleanup(diff_format_registry.remove, "boo")
320
 
        self.make_example_branch()
321
 
        self.build_tree_contents([('hello', 'hello world!\n')])
322
 
        output = self.run_bzr('diff --format=boo', retcode=1)
323
 
        self.assertTrue("BOO!" in output[0])
324
 
        output = self.run_bzr('diff -Fboo', retcode=1)
325
 
        self.assertTrue("BOO!" in output[0])
326
 
 
327
300
 
328
301
class TestCheckoutDiff(TestDiff):
329
302
 
341
314
        return tree
342
315
 
343
316
    def example_branches(self):
344
 
        branch1_tree, branch2_tree = super(TestCheckoutDiff,
345
 
                                           self).example_branches()
 
317
        branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
346
318
        os.mkdir('checkouts')
347
319
        branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
348
320
        branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
388
360
        # subprocess.py that we had to workaround).
389
361
        # However, if 'diff' may not be available
390
362
        self.make_example_branch()
391
 
        self.overrideEnv('BZR_PROGRESS_BAR', 'none')
 
363
        # this will be automatically restored by the base bzr test class
 
364
        os.environ['BZR_PROGRESS_BAR'] = 'none'
392
365
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
393
366
                                           universal_newlines=True,
394
367
                                           retcode=None)
403
376
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
404
377
                                 "+baz\n\n")
405
378
 
406
 
    def test_external_diff_options_and_using(self):
407
 
        """Test that the options are passed correctly to an external diff process"""
408
 
        self.requireFeature(features.diff_feature)
409
 
        self.make_example_branch()
410
 
        self.build_tree_contents([('hello', 'Foo\n')])
411
 
        out, err = self.run_bzr('diff --diff-options -i --using diff',
412
 
                                    retcode=1)
413
 
        self.assertEquals("=== modified file 'hello'\n", out)
414
 
        self.assertEquals('', err)
415
 
 
416
379
 
417
380
class TestDiffOutput(DiffBase):
418
381