~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: 2010-08-20 05:20:56 UTC
  • mfrom: (5380.3.3 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100820052056-gwad7dz2otckrjax
(mbp) Start whatsnew for 2.3; update ppa developer docs (Martin Pool)

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
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):
133
136
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
134
137
            error_regexes=('one or two revision specifiers',))
135
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
 
136
143
    def test_diff_nonexistent_revision(self):
137
144
        out, err = self.run_bzr('diff -r 123', retcode=3,
138
145
            error_regexes=("Requested revision: '123' does not "
148
155
        self.assertContainsRe(err,
149
156
            "Requested revision: '1.1' does not exist in branch:")
150
157
 
 
158
    def test_diff_diff_options_and_using(self):
 
159
        out, err = self.run_bzr('diff --diff-options -wu --using /usr/bin/diff', retcode=3,
 
160
          error_regexes=('are mutually exclusive.',))
 
161
 
151
162
    def test_diff_unversioned(self):
152
163
        # Get an error when diffing a non-versioned file.
153
164
        # (Malone #3619)
298
309
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
299
310
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
300
311
 
 
312
    def test_custom_format(self):
 
313
        class BooDiffTree(DiffTree):
 
314
 
 
315
            def show_diff(self, specific_files, extra_trees=None):
 
316
                self.to_file.write("BOO!\n")
 
317
                return super(BooDiffTree, self).show_diff(specific_files,
 
318
                    extra_trees)
 
319
 
 
320
        diff_format_registry.register("boo", BooDiffTree, 
 
321
            "Scary diff format")
 
322
        self.addCleanup(diff_format_registry.remove, "boo")
 
323
        self.make_example_branch()
 
324
        self.build_tree_contents([('hello', 'hello world!\n')])
 
325
        output = self.run_bzr('diff --format=boo', retcode=1)
 
326
        self.assertTrue("BOO!" in output[0])
301
327
 
302
328
class TestCheckoutDiff(TestDiff):
303
329
 
355
381
 
356
382
    def test_external_diff(self):
357
383
        """Test that we can spawn an external diff process"""
 
384
        self.disable_missing_extensions_warning()
358
385
        # We have to use run_bzr_subprocess, because we need to
359
386
        # test writing directly to stdout, (there was a bug in
360
387
        # subprocess.py that we had to workaround).
366
393
                                           universal_newlines=True,
367
394
                                           retcode=None)
368
395
        if 'Diff is not installed on this machine' in err:
369
 
            raise TestSkipped("No external 'diff' is available")
 
396
            raise tests.TestSkipped("No external 'diff' is available")
370
397
        self.assertEqual('', err)
371
398
        # We have to skip the stuff in the middle, because it depends
372
399
        # on time.time()