~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2008-09-11 19:36:38 UTC
  • mfrom: (3703 +trunk)
  • mto: (3705.1.1 trunk2)
  • mto: This revision was merged to the branch mainline in revision 3708.
  • Revision ID: v.ladeuil+lp@free.fr-20080911193638-wtjyc1kcmacc6t1f
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr diff.
21
21
import os
22
22
import re
23
23
 
24
 
from bzrlib import (
25
 
    tests,
26
 
    workingtree,
27
 
    )
28
 
from bzrlib.diff import (
29
 
    DiffTree,
30
 
    format_registry as diff_format_registry,
31
 
    )
32
 
from bzrlib.tests import (
33
 
    features,
34
 
    )
 
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
35
29
 
36
30
 
37
31
def subst_dates(string):
40
34
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
41
35
 
42
36
 
43
 
class DiffBase(tests.TestCaseWithTransport):
 
37
class DiffBase(ExternalBase):
44
38
    """Base class with common setup method"""
45
39
 
46
40
    def make_example_branch(self):
132
126
        # Get an error from a file that does not exist at all
133
127
        # (Malone #3619)
134
128
        self.make_example_branch()
135
 
        out, err = self.run_bzr('diff does-not-exist', retcode=3,
136
 
            error_regexes=('not versioned.*does-not-exist',))
 
129
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
 
130
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
137
131
 
138
132
    def test_diff_illegal_revision_specifiers(self):
139
 
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
140
 
            error_regexes=('one or two revision specifiers',))
141
 
 
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',))
145
 
 
146
 
    def test_diff_nonexistent_revision(self):
147
 
        out, err = self.run_bzr('diff -r 123', retcode=3,
148
 
            error_regexes=("Requested revision: '123' does not "
149
 
                "exist in branch:",))
150
 
 
151
 
    def test_diff_nonexistent_dotted_revision(self):
152
 
        out, err = self.run_bzr('diff -r 1.1', retcode=3)
153
 
        self.assertContainsRe(err,
154
 
            "Requested revision: '1.1' does not exist in branch:")
155
 
 
156
 
    def test_diff_nonexistent_dotted_revision_change(self):
157
 
        out, err = self.run_bzr('diff -c 1.1', retcode=3)
158
 
        self.assertContainsRe(err,
159
 
            "Requested revision: '1.1' does not exist in branch:")
 
133
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
 
134
        self.assertContainsRe(err, 'one or two revision specifiers')
160
135
 
161
136
    def test_diff_unversioned(self):
162
137
        # Get an error when diffing a non-versioned file.
212
187
 
213
188
    def test_diff_branches(self):
214
189
        self.example_branches()
215
 
        # should open branch1 and diff against branch2,
 
190
        # should open branch1 and diff against branch2, 
216
191
        self.check_b2_vs_b1('diff -r branch:branch2 branch1')
217
192
        # Compare two working trees using various syntax forms
218
193
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
308
283
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
309
284
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
310
285
 
311
 
    def test_custom_format(self):
312
 
        class BooDiffTree(DiffTree):
313
 
 
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,
317
 
                    extra_trees)
318
 
 
319
 
        diff_format_registry.register("boo", BooDiffTree, 
320
 
            "Scary diff format")
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])
326
 
        output = self.run_bzr('diff -Fboo', retcode=1)
327
 
        self.assertTrue("BOO!" in output[0])
328
 
 
329
286
 
330
287
class TestCheckoutDiff(TestDiff):
331
288
 
383
340
 
384
341
    def test_external_diff(self):
385
342
        """Test that we can spawn an external diff process"""
386
 
        self.disable_missing_extensions_warning()
387
343
        # We have to use run_bzr_subprocess, because we need to
388
344
        # test writing directly to stdout, (there was a bug in
389
345
        # subprocess.py that we had to workaround).
390
346
        # However, if 'diff' may not be available
391
347
        self.make_example_branch()
392
 
        self.overrideEnv('BZR_PROGRESS_BAR', 'none')
393
 
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
394
 
                                           universal_newlines=True,
395
 
                                           retcode=None)
 
348
        orig_progress = os.environ.get('BZR_PROGRESS_BAR')
 
349
        try:
 
350
            os.environ['BZR_PROGRESS_BAR'] = 'none'
 
351
            out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
 
352
                                               universal_newlines=True,
 
353
                                               retcode=None)
 
354
        finally:
 
355
            if orig_progress is None:
 
356
                del os.environ['BZR_PROGRESS_BAR']
 
357
            else:
 
358
                os.environ['BZR_PROGRESS_BAR'] = orig_progress
 
359
            
396
360
        if 'Diff is not installed on this machine' in err:
397
 
            raise tests.TestSkipped("No external 'diff' is available")
 
361
            raise TestSkipped("No external 'diff' is available")
398
362
        self.assertEqual('', err)
399
363
        # We have to skip the stuff in the middle, because it depends
400
364
        # on time.time()
404
368
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
405
369
                                 "+baz\n\n")
406
370
 
407
 
    def test_external_diff_options_and_using(self):
408
 
        """Test that the options are passed correctly to an external diff process"""
409
 
        self.requireFeature(features.diff_feature)
410
 
        self.make_example_branch()
411
 
        self.build_tree_contents([('hello', 'Foo\n')])
412
 
        out, err = self.run_bzr('diff --diff-options -i --using diff',
413
 
                                    retcode=1)
414
 
        self.assertEquals("=== modified file 'hello'\n", out)
415
 
        self.assertEquals('', err)
416
 
 
417
371
 
418
372
class TestDiffOutput(DiffBase):
419
373