~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Aaron Bentley
  • Date: 2006-09-29 00:04:13 UTC
  • mto: (1731.2.8 nested-trees)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: aaron.bentley@utoronto.ca-20060929000413-bb6d513b7171b59f
fix version_info stuff to deliberately include root

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
from cStringIO import StringIO
19
19
import errno
 
20
import subprocess
20
21
from tempfile import TemporaryFile
21
22
 
22
23
from bzrlib.diff import internal_diff, external_diff, show_diff_trees
109
110
                                     use_stringio=True)
110
111
        self.check_patch(lines)
111
112
 
112
 
    def test_external_diff_binary(self):
113
 
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
114
 
        self.assertEqual(['Binary files old and new differ\n', '\n'], lines)
 
113
    def test_external_diff_binary_lang_c(self):
 
114
        orig_lang = os.environ.get('LANG')
 
115
        try:
 
116
            os.environ['LANG'] = 'C'
 
117
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
 
118
            # Older versions of diffutils say "Binary files", newer
 
119
            # versions just say "Files".
 
120
            self.assertContainsRe(lines[0],
 
121
                                  '(Binary f|F)iles old and new differ\n')
 
122
            self.assertEquals(lines[1:], ['\n'])
 
123
        finally:
 
124
            if orig_lang is None:
 
125
                del os.environ['LANG']
 
126
            else:
 
127
                os.environ['LANG'] = orig_lang
115
128
 
116
129
    def test_no_external_diff(self):
117
130
        """Check that NoDiff is raised when diff is not available"""
182
195
            'internal_diff should return bytestrings')
183
196
 
184
197
 
 
198
class TestDiffFiles(TestCaseInTempDir):
 
199
 
 
200
    def test_external_diff_binary(self):
 
201
        """The output when using external diff should use diff's i18n error"""
 
202
        # Make sure external_diff doesn't fail in the current LANG
 
203
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
 
204
 
 
205
        cmd = ['diff', '-u', 'old', 'new']
 
206
        open('old', 'wb').write('\x00foobar\n')
 
207
        open('new', 'wb').write('foo\x00bar\n')
 
208
        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
 
209
                                     stdin=subprocess.PIPE)
 
210
        out, err = pipe.communicate()
 
211
        # Diff returns '2' on Binary files.
 
212
        self.assertEqual(2, pipe.returncode)
 
213
        # We should output whatever diff tells us, plus a trailing newline
 
214
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
 
215
 
 
216
 
185
217
class TestDiffDates(TestCaseWithTransport):
186
218
 
187
219
    def setUp(self):