~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Martin Pool
  • Date: 2006-08-10 01:16:16 UTC
  • mto: (1904.1.2 0.9)
  • mto: This revision was merged to the branch mainline in revision 1913.
  • Revision ID: mbp@sourcefrog.net-20060810011616-d74881eba696e746
compare_trees is deprecated in 0.9 not 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Development 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
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
import os
18
18
from cStringIO import StringIO
19
19
import errno
20
 
import subprocess
21
20
from tempfile import TemporaryFile
22
21
 
23
22
from bzrlib.diff import internal_diff, external_diff, show_diff_trees
110
109
                                     use_stringio=True)
111
110
        self.check_patch(lines)
112
111
 
113
 
    def test_external_diff_binary_lang_c(self):
114
 
        orig_lang = os.environ.get('LANG')
115
 
        orig_lc_all = os.environ.get('LC_ALL')
116
 
        try:
117
 
            os.environ['LANG'] = 'C'
118
 
            os.environ['LC_ALL'] = 'C'
119
 
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
120
 
            # Older versions of diffutils say "Binary files", newer
121
 
            # versions just say "Files".
122
 
            self.assertContainsRe(lines[0],
123
 
                                  '(Binary f|F)iles old and new differ\n')
124
 
            self.assertEquals(lines[1:], ['\n'])
125
 
        finally:
126
 
            for name, value in [('LANG', orig_lang), ('LC_ALL', orig_lc_all)]:
127
 
                if value is None:
128
 
                    del os.environ[name]
129
 
                else:
130
 
                    os.environ[name] = value
 
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)
131
115
 
132
116
    def test_no_external_diff(self):
133
117
        """Check that NoDiff is raised when diff is not available"""
198
182
            'internal_diff should return bytestrings')
199
183
 
200
184
 
201
 
class TestDiffFiles(TestCaseInTempDir):
202
 
 
203
 
    def test_external_diff_binary(self):
204
 
        """The output when using external diff should use diff's i18n error"""
205
 
        # Make sure external_diff doesn't fail in the current LANG
206
 
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
207
 
 
208
 
        cmd = ['diff', '-u', 'old', 'new']
209
 
        open('old', 'wb').write('\x00foobar\n')
210
 
        open('new', 'wb').write('foo\x00bar\n')
211
 
        pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE,
212
 
                                     stdin=subprocess.PIPE)
213
 
        out, err = pipe.communicate()
214
 
        # Diff returns '2' on Binary files.
215
 
        self.assertEqual(2, pipe.returncode)
216
 
        # We should output whatever diff tells us, plus a trailing newline
217
 
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
218
 
 
219
 
 
220
185
class TestDiffDates(TestCaseWithTransport):
221
186
 
222
187
    def setUp(self):