/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz diff."""
 
18
"""Black-box tests for bzr diff."""
19
19
 
20
20
import os
21
21
import re
22
22
 
23
 
from breezy import (
 
23
from bzrlib import (
24
24
    tests,
25
25
    workingtree,
26
26
    )
27
 
from breezy.diff import (
 
27
from bzrlib.diff import (
28
28
    DiffTree,
29
29
    format_registry as diff_format_registry,
30
30
    )
31
 
from breezy.tests import (
 
31
from bzrlib.tests import (
32
32
    features,
33
33
    )
34
34
 
45
45
    def make_example_branch(self):
46
46
        tree = self.make_branch_and_tree('.')
47
47
        self.build_tree_contents([
48
 
            ('hello', b'foo\n'),
49
 
            ('goodbye', b'baz\n')])
 
48
            ('hello', 'foo\n'),
 
49
            ('goodbye', 'baz\n')])
50
50
        tree.add(['hello'])
51
51
        tree.commit('setup')
52
52
        tree.add(['goodbye'])
58
58
 
59
59
    def test_diff(self):
60
60
        tree = self.make_example_branch()
61
 
        self.build_tree_contents([('hello', b'hello world!')])
 
61
        self.build_tree_contents([('hello', 'hello world!')])
62
62
        tree.commit(message='fixing hello')
63
63
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
64
 
        self.assertTrue('\n+hello world!' in output)
 
64
        self.assert_('\n+hello world!' in output)
65
65
        output = self.run_bzr('diff -c 3', retcode=1)[0]
66
 
        self.assertTrue('\n+hello world!' in output)
 
66
        self.assert_('\n+hello world!' in output)
67
67
        output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
68
 
        self.assertTrue('\n+baz' in output)
 
68
        self.assert_('\n+baz' in output)
69
69
        output = self.run_bzr('diff -c last:2', retcode=1)[0]
70
 
        self.assertTrue('\n+baz' in output)
 
70
        self.assert_('\n+baz' in output)
71
71
        self.build_tree(['moo'])
72
72
        tree.add('moo')
73
73
        os.unlink('moo')
76
76
    def test_diff_prefix(self):
77
77
        """diff --prefix appends to filenames in output"""
78
78
        self.make_example_branch()
79
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
79
        self.build_tree_contents([('hello', 'hello world!\n')])
80
80
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
81
 
        self.assertEqual(err, '')
 
81
        self.assertEquals(err, '')
82
82
        self.assertEqualDiff(subst_dates(out), '''\
83
83
=== modified file 'hello'
84
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
98
98
    def test_diff_p1(self):
99
99
        """diff -p1 produces lkml-style diffs"""
100
100
        self.make_example_branch()
101
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
101
        self.build_tree_contents([('hello', 'hello world!\n')])
102
102
        out, err = self.run_bzr('diff -p1', retcode=1)
103
 
        self.assertEqual(err, '')
 
103
        self.assertEquals(err, '')
104
104
        self.assertEqualDiff(subst_dates(out), '''\
105
105
=== modified file 'hello'
106
106
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
114
114
    def test_diff_p0(self):
115
115
        """diff -p0 produces diffs with no prefix"""
116
116
        self.make_example_branch()
117
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
117
        self.build_tree_contents([('hello', 'hello world!\n')])
118
118
        out, err = self.run_bzr('diff -p0', retcode=1)
119
 
        self.assertEqual(err, '')
 
119
        self.assertEquals(err, '')
120
120
        self.assertEqualDiff(subst_dates(out), '''\
121
121
=== modified file 'hello'
122
122
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
174
174
        branch1_tree.add('file')
175
175
        branch1_tree.add('file2')
176
176
        branch1_tree.commit(message='add file and file2')
177
 
        branch2_tree = branch1_tree.controldir.sprout('branch2').open_workingtree()
178
 
        self.build_tree_contents([('branch2/file', b'new content\n')])
 
177
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
 
178
        self.build_tree_contents([('branch2/file', 'new content\n')])
179
179
        branch2_tree.commit(message='update file')
180
180
        return branch1_tree, branch2_tree
181
181
 
182
182
    def check_b2_vs_b1(self, cmd):
183
183
        # Compare branch2 vs branch1 using cmd and check the result
184
184
        out, err = self.run_bzr(cmd, retcode=1)
185
 
        self.assertEqual('', err)
186
 
        self.assertEqual("=== modified file 'file'\n"
187
 
                          "--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
188
 
                          "+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
185
        self.assertEquals('', err)
 
186
        self.assertEquals("=== modified file 'file'\n"
 
187
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
188
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
189
189
                          "@@ -1,1 +1,1 @@\n"
190
190
                          "-new content\n"
191
191
                          "+contents of branch1/file\n"
194
194
    def check_b1_vs_b2(self, cmd):
195
195
        # Compare branch1 vs branch2 using cmd and check the result
196
196
        out, err = self.run_bzr(cmd, retcode=1)
197
 
        self.assertEqual('', err)
 
197
        self.assertEquals('', err)
198
198
        self.assertEqualDiff("=== modified file 'file'\n"
199
 
                              "--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
200
 
                              "+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
199
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
200
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
201
201
                              "@@ -1,1 +1,1 @@\n"
202
202
                              "-contents of branch1/file\n"
203
203
                              "+new content\n"
206
206
    def check_no_diffs(self, cmd):
207
207
        # Check that running cmd returns an empty diff
208
208
        out, err = self.run_bzr(cmd, retcode=0)
209
 
        self.assertEqual('', err)
210
 
        self.assertEqual('', out)
 
209
        self.assertEquals('', err)
 
210
        self.assertEquals('', out)
211
211
 
212
212
    def test_diff_branches(self):
213
213
        self.example_branches()
229
229
    def test_diff_branches_no_working_trees(self):
230
230
        branch1_tree, branch2_tree = self.example_branches()
231
231
        # Compare a working tree to a branch without a WT
232
 
        dir1 = branch1_tree.controldir
 
232
        dir1 = branch1_tree.bzrdir
233
233
        dir1.destroy_workingtree()
234
234
        self.assertFalse(dir1.has_workingtree())
235
235
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
240
240
        self.check_b1_vs_b2('diff --old branch1 branch2')
241
241
        self.check_b1_vs_b2('diff branch1 --new branch2')
242
242
        # Compare a branch with a WT against another without a WT
243
 
        dir2 = branch2_tree.controldir
 
243
        dir2 = branch2_tree.bzrdir
244
244
        dir2.destroy_workingtree()
245
245
        self.assertFalse(dir2.has_workingtree())
246
246
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
250
250
    def test_diff_revno_branches(self):
251
251
        self.example_branches()
252
252
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
253
 
        self.build_tree_contents([('branch2/file', b'even newer content')])
 
253
        self.build_tree_contents([('branch2/file', 'even newer content')])
254
254
        branch2_tree.commit(message='update file once more')
255
255
 
256
256
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
257
257
                                )
258
 
        self.assertEqual('', err)
259
 
        self.assertEqual('', out)
 
258
        self.assertEquals('', err)
 
259
        self.assertEquals('', out)
260
260
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
261
261
                                retcode=1)
262
 
        self.assertEqual('', err)
 
262
        self.assertEquals('', err)
263
263
        self.assertEqualDiff("=== modified file 'file'\n"
264
 
                              "--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
265
 
                              "+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
264
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
265
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
266
266
                              "@@ -1,1 +1,1 @@\n"
267
267
                              "-new content\n"
268
268
                              "+contents of branch1/file\n"
270
270
 
271
271
    def example_branch2(self):
272
272
        branch1_tree = self.make_branch_and_tree('branch1')
273
 
        self.build_tree_contents([('branch1/file1', b'original line\n')])
 
273
        self.build_tree_contents([('branch1/file1', 'original line\n')])
274
274
        branch1_tree.add('file1')
275
275
        branch1_tree.commit(message='first commit')
276
 
        self.build_tree_contents([('branch1/file1', b'repo line\n')])
 
276
        self.build_tree_contents([('branch1/file1', 'repo line\n')])
277
277
        branch1_tree.commit(message='second commit')
278
278
        return branch1_tree
279
279
 
280
280
    def test_diff_to_working_tree(self):
281
281
        self.example_branch2()
282
 
        self.build_tree_contents([('branch1/file1', b'new line')])
 
282
        self.build_tree_contents([('branch1/file1', 'new line')])
283
283
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
284
284
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
285
285
 
286
286
    def test_diff_to_working_tree_in_subdir(self):
287
287
        self.example_branch2()
288
 
        self.build_tree_contents([('branch1/file1', b'new line')])
 
288
        self.build_tree_contents([('branch1/file1', 'new line')])
289
289
        os.mkdir('branch1/dir1')
290
290
        output = self.run_bzr('diff -r 1..', retcode=1,
291
291
                              working_dir='branch1/dir1')
301
301
 
302
302
    def test_diff_to_branch_no_working_tree(self):
303
303
        branch1_tree = self.example_branch2()
304
 
        dir1 = branch1_tree.controldir
 
304
        dir1 = branch1_tree.bzrdir
305
305
        dir1.destroy_workingtree()
306
306
        self.assertFalse(dir1.has_workingtree())
307
307
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
318
318
        diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
319
319
        self.addCleanup(diff_format_registry.remove, "boo")
320
320
        self.make_example_branch()
321
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
321
        self.build_tree_contents([('hello', 'hello world!\n')])
322
322
        output = self.run_bzr('diff --format=boo', retcode=1)
323
323
        self.assertTrue("BOO!" in output[0])
324
324
        output = self.run_bzr('diff -Fboo', retcode=1)
360
360
 
361
361
    def test_diff_label_added(self):
362
362
        tree = super(TestDiffLabels, self).make_example_branch()
363
 
        self.build_tree_contents([('barbar', b'barbar')])
 
363
        self.build_tree_contents([('barbar', 'barbar')])
364
364
        tree.add('barbar')
365
365
        diff = self.run_bzr('diff', retcode=1)
366
366
        self.assertTrue("=== added file 'barbar'" in diff[0])
367
367
 
368
368
    def test_diff_label_modified(self):
369
369
        super(TestDiffLabels, self).make_example_branch()
370
 
        self.build_tree_contents([('hello', b'barbar')])
 
370
        self.build_tree_contents([('hello', 'barbar')])
371
371
        diff = self.run_bzr('diff', retcode=1)
372
372
        self.assertTrue("=== modified file 'hello'" in diff[0])
373
373
 
397
397
        self.assertEqual('', err)
398
398
        # We have to skip the stuff in the middle, because it depends
399
399
        # on time.time()
400
 
        self.assertStartsWith(
401
 
            out,
402
 
            "=== added file 'goodbye'\n"
403
 
            "--- old/goodbye\t1970-01-01 00:00:00 +0000\n"
404
 
            "+++ new/goodbye\t")
 
400
        self.assertStartsWith(out, "=== added file 'goodbye'\n"
 
401
                                   "--- goodbye\t1970-01-01 00:00:00 +0000\n"
 
402
                                   "+++ goodbye\t")
405
403
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
406
404
                                 "+baz\n\n")
407
405
 
409
407
        """Test that the options are passed correctly to an external diff process"""
410
408
        self.requireFeature(features.diff_feature)
411
409
        self.make_example_branch()
412
 
        self.build_tree_contents([('hello', b'Foo\n')])
 
410
        self.build_tree_contents([('hello', 'Foo\n')])
413
411
        out, err = self.run_bzr('diff --diff-options -i --using diff',
414
412
                                    retcode=1)
415
 
        self.assertEqual("=== modified file 'hello'\n", out)
416
 
        self.assertEqual('', err)
 
413
        self.assertEquals("=== modified file 'hello'\n", out)
 
414
        self.assertEquals('', err)
417
415
 
418
416
 
419
417
class TestDiffOutput(DiffBase):
421
419
    def test_diff_output(self):
422
420
        # check that output doesn't mangle line-endings
423
421
        self.make_example_branch()
424
 
        self.build_tree_contents([('hello', b'hello world!\n')])
 
422
        self.build_tree_contents([('hello', 'hello world!\n')])
425
423
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
426
 
        self.assertTrue('\n+hello world!\n' in output)
 
424
        self.assert_('\n+hello world!\n' in output)