~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2009-09-08 08:09:25 UTC
  • mto: (4634.6.27 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090908080925-ccmjw4kzzz7bepg7
Fix more tests to cope with new commit_write_group strictness.

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
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):
139
133
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
140
134
            error_regexes=('one or two revision specifiers',))
141
135
 
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
136
    def test_diff_nonexistent_revision(self):
147
137
        out, err = self.run_bzr('diff -r 123', retcode=3,
148
138
            error_regexes=("Requested revision: '123' does not "
308
298
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
309
299
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
310
300
 
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
301
 
330
302
class TestCheckoutDiff(TestDiff):
331
303
 
383
355
 
384
356
    def test_external_diff(self):
385
357
        """Test that we can spawn an external diff process"""
386
 
        self.disable_missing_extensions_warning()
387
358
        # We have to use run_bzr_subprocess, because we need to
388
359
        # test writing directly to stdout, (there was a bug in
389
360
        # subprocess.py that we had to workaround).
390
361
        # However, if 'diff' may not be available
391
362
        self.make_example_branch()
392
 
        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'
393
365
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
394
366
                                           universal_newlines=True,
395
367
                                           retcode=None)
396
368
        if 'Diff is not installed on this machine' in err:
397
 
            raise tests.TestSkipped("No external 'diff' is available")
 
369
            raise TestSkipped("No external 'diff' is available")
398
370
        self.assertEqual('', err)
399
371
        # We have to skip the stuff in the middle, because it depends
400
372
        # on time.time()
404
376
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
405
377
                                 "+baz\n\n")
406
378
 
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
379
 
418
380
class TestDiffOutput(DiffBase):
419
381