~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 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
12
12
#
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
16
16
 
17
17
 
18
18
"""Black-box tests for bzr diff.
21
21
import os
22
22
import re
23
23
 
24
 
import bzrlib
25
 
from bzrlib import workingtree
26
 
from bzrlib.branch import Branch
27
 
from bzrlib.tests import TestSkipped
28
 
from bzrlib.tests.blackbox import ExternalBase
 
24
from bzrlib import (
 
25
    tests,
 
26
    workingtree,
 
27
    )
 
28
from bzrlib.diff import (
 
29
    DiffTree,
 
30
    format_registry as diff_format_registry,
 
31
    )
29
32
 
30
33
 
31
34
def subst_dates(string):
34
37
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
35
38
 
36
39
 
37
 
class DiffBase(ExternalBase):
 
40
class DiffBase(tests.TestCaseWithTransport):
38
41
    """Base class with common setup method"""
39
42
 
40
43
    def make_example_branch(self):
126
129
        # Get an error from a file that does not exist at all
127
130
        # (Malone #3619)
128
131
        self.make_example_branch()
129
 
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
130
 
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
 
132
        out, err = self.run_bzr('diff does-not-exist', retcode=3,
 
133
            error_regexes=('not versioned.*does-not-exist',))
131
134
 
132
135
    def test_diff_illegal_revision_specifiers(self):
133
 
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
134
 
        self.assertContainsRe(err, 'one or two revision specifiers')
 
136
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
 
137
            error_regexes=('one or two revision specifiers',))
 
138
 
 
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',))
 
142
 
 
143
    def test_diff_nonexistent_revision(self):
 
144
        out, err = self.run_bzr('diff -r 123', retcode=3,
 
145
            error_regexes=("Requested revision: '123' does not "
 
146
                "exist in branch:",))
 
147
 
 
148
    def test_diff_nonexistent_dotted_revision(self):
 
149
        out, err = self.run_bzr('diff -r 1.1', retcode=3)
 
150
        self.assertContainsRe(err,
 
151
            "Requested revision: '1.1' does not exist in branch:")
 
152
 
 
153
    def test_diff_nonexistent_dotted_revision_change(self):
 
154
        out, err = self.run_bzr('diff -c 1.1', retcode=3)
 
155
        self.assertContainsRe(err,
 
156
            "Requested revision: '1.1' does not exist in branch:")
135
157
 
136
158
    def test_diff_unversioned(self):
137
159
        # Get an error when diffing a non-versioned file.
187
209
 
188
210
    def test_diff_branches(self):
189
211
        self.example_branches()
190
 
        # should open branch1 and diff against branch2, 
 
212
        # should open branch1 and diff against branch2,
191
213
        self.check_b2_vs_b1('diff -r branch:branch2 branch1')
192
214
        # Compare two working trees using various syntax forms
193
215
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
259
281
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
260
282
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
261
283
 
 
284
    def test_diff_to_working_tree_in_subdir(self):
 
285
        self.example_branch2()
 
286
        self.build_tree_contents([('branch1/file1', 'new line')])
 
287
        os.mkdir('branch1/dir1')
 
288
        os.chdir('branch1/dir1')
 
289
        output = self.run_bzr('diff -r 1..', retcode=1)
 
290
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
 
291
 
262
292
    def test_diff_across_rename(self):
263
293
        """The working tree path should always be considered for diffing"""
264
294
        tree = self.make_example_branch()
275
305
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
276
306
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
277
307
 
 
308
    def test_custom_format(self):
 
309
        class BooDiffTree(DiffTree):
 
310
 
 
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,
 
314
                    extra_trees)
 
315
 
 
316
        diff_format_registry.register("boo", BooDiffTree, 
 
317
            "Scary diff format")
 
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])
 
323
 
278
324
 
279
325
class TestCheckoutDiff(TestDiff):
280
326
 
332
378
 
333
379
    def test_external_diff(self):
334
380
        """Test that we can spawn an external diff process"""
 
381
        self.disable_missing_extensions_warning()
335
382
        # We have to use run_bzr_subprocess, because we need to
336
383
        # test writing directly to stdout, (there was a bug in
337
384
        # subprocess.py that we had to workaround).
338
385
        # However, if 'diff' may not be available
339
386
        self.make_example_branch()
340
 
        orig_progress = os.environ.get('BZR_PROGRESS_BAR')
341
 
        try:
342
 
            os.environ['BZR_PROGRESS_BAR'] = 'none'
343
 
            out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
344
 
                                               universal_newlines=True,
345
 
                                               retcode=None)
346
 
        finally:
347
 
            if orig_progress is None:
348
 
                del os.environ['BZR_PROGRESS_BAR']
349
 
            else:
350
 
                os.environ['BZR_PROGRESS_BAR'] = orig_progress
351
 
            
 
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,
 
391
                                           retcode=None)
352
392
        if 'Diff is not installed on this machine' in err:
353
 
            raise TestSkipped("No external 'diff' is available")
 
393
            raise tests.TestSkipped("No external 'diff' is available")
354
394
        self.assertEqual('', err)
355
395
        # We have to skip the stuff in the middle, because it depends
356
396
        # on time.time()