/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 breezy/tests/blackbox/test_diff.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-07 01:17:16 UTC
  • mto: (6653.3.7 bzrwt)
  • mto: This revision was merged to the branch mainline in revision 6668.
  • Revision ID: jelmer@jelmer.uk-20170607011716-hsqdox2pyaqcm4kn
Fix some more tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 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 bzr diff.
19
 
"""
 
18
"""Black-box tests for brz diff."""
20
19
 
21
20
import os
22
21
import re
23
22
 
24
 
from bzrlib import (
 
23
from breezy import (
25
24
    tests,
26
25
    workingtree,
27
26
    )
28
 
from bzrlib.diff import (
 
27
from breezy.diff import (
29
28
    DiffTree,
30
29
    format_registry as diff_format_registry,
31
30
    )
 
31
from breezy.tests import (
 
32
    features,
 
33
    )
32
34
 
33
35
 
34
36
def subst_dates(string):
59
61
        self.build_tree_contents([('hello', 'hello world!')])
60
62
        tree.commit(message='fixing hello')
61
63
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
62
 
        self.assert_('\n+hello world!' in output)
 
64
        self.assertTrue('\n+hello world!' in output)
63
65
        output = self.run_bzr('diff -c 3', retcode=1)[0]
64
 
        self.assert_('\n+hello world!' in output)
 
66
        self.assertTrue('\n+hello world!' in output)
65
67
        output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
66
 
        self.assert_('\n+baz' in output)
 
68
        self.assertTrue('\n+baz' in output)
67
69
        output = self.run_bzr('diff -c last:2', retcode=1)[0]
68
 
        self.assert_('\n+baz' in output)
 
70
        self.assertTrue('\n+baz' in output)
69
71
        self.build_tree(['moo'])
70
72
        tree.add('moo')
71
73
        os.unlink('moo')
76
78
        self.make_example_branch()
77
79
        self.build_tree_contents([('hello', 'hello world!\n')])
78
80
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
79
 
        self.assertEquals(err, '')
 
81
        self.assertEqual(err, '')
80
82
        self.assertEqualDiff(subst_dates(out), '''\
81
83
=== modified file 'hello'
82
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
98
100
        self.make_example_branch()
99
101
        self.build_tree_contents([('hello', 'hello world!\n')])
100
102
        out, err = self.run_bzr('diff -p1', retcode=1)
101
 
        self.assertEquals(err, '')
 
103
        self.assertEqual(err, '')
102
104
        self.assertEqualDiff(subst_dates(out), '''\
103
105
=== modified file 'hello'
104
106
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
114
116
        self.make_example_branch()
115
117
        self.build_tree_contents([('hello', 'hello world!\n')])
116
118
        out, err = self.run_bzr('diff -p0', retcode=1)
117
 
        self.assertEquals(err, '')
 
119
        self.assertEqual(err, '')
118
120
        self.assertEqualDiff(subst_dates(out), '''\
119
121
=== modified file 'hello'
120
122
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
180
182
    def check_b2_vs_b1(self, cmd):
181
183
        # Compare branch2 vs branch1 using cmd and check the result
182
184
        out, err = self.run_bzr(cmd, retcode=1)
183
 
        self.assertEquals('', err)
184
 
        self.assertEquals("=== modified file 'file'\n"
185
 
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
186
 
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
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"
187
189
                          "@@ -1,1 +1,1 @@\n"
188
190
                          "-new content\n"
189
191
                          "+contents of branch1/file\n"
192
194
    def check_b1_vs_b2(self, cmd):
193
195
        # Compare branch1 vs branch2 using cmd and check the result
194
196
        out, err = self.run_bzr(cmd, retcode=1)
195
 
        self.assertEquals('', err)
 
197
        self.assertEqual('', err)
196
198
        self.assertEqualDiff("=== modified file 'file'\n"
197
 
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
198
 
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
199
                              "--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
200
                              "+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
199
201
                              "@@ -1,1 +1,1 @@\n"
200
202
                              "-contents of branch1/file\n"
201
203
                              "+new content\n"
204
206
    def check_no_diffs(self, cmd):
205
207
        # Check that running cmd returns an empty diff
206
208
        out, err = self.run_bzr(cmd, retcode=0)
207
 
        self.assertEquals('', err)
208
 
        self.assertEquals('', out)
 
209
        self.assertEqual('', err)
 
210
        self.assertEqual('', out)
209
211
 
210
212
    def test_diff_branches(self):
211
213
        self.example_branches()
253
255
 
254
256
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
255
257
                                )
256
 
        self.assertEquals('', err)
257
 
        self.assertEquals('', out)
 
258
        self.assertEqual('', err)
 
259
        self.assertEqual('', out)
258
260
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
259
261
                                retcode=1)
260
 
        self.assertEquals('', err)
 
262
        self.assertEqual('', err)
261
263
        self.assertEqualDiff("=== modified file 'file'\n"
262
 
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
263
 
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
264
                              "--- old/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
265
                              "+++ new/file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
264
266
                              "@@ -1,1 +1,1 @@\n"
265
267
                              "-new content\n"
266
268
                              "+contents of branch1/file\n"
285
287
        self.example_branch2()
286
288
        self.build_tree_contents([('branch1/file1', 'new line')])
287
289
        os.mkdir('branch1/dir1')
288
 
        os.chdir('branch1/dir1')
289
 
        output = self.run_bzr('diff -r 1..', retcode=1)
 
290
        output = self.run_bzr('diff -r 1..', retcode=1,
 
291
                              working_dir='branch1/dir1')
290
292
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
291
293
 
292
294
    def test_diff_across_rename(self):
313
315
                return super(BooDiffTree, self).show_diff(specific_files,
314
316
                    extra_trees)
315
317
 
316
 
        diff_format_registry.register("boo", BooDiffTree, 
317
 
            "Scary diff format")
 
318
        diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
318
319
        self.addCleanup(diff_format_registry.remove, "boo")
319
320
        self.make_example_branch()
320
321
        self.build_tree_contents([('hello', 'hello world!\n')])
321
322
        output = self.run_bzr('diff --format=boo', retcode=1)
322
323
        self.assertTrue("BOO!" in output[0])
 
324
        output = self.run_bzr('diff -Fboo', retcode=1)
 
325
        self.assertTrue("BOO!" in output[0])
323
326
 
324
327
 
325
328
class TestCheckoutDiff(TestDiff):
338
341
        return tree
339
342
 
340
343
    def example_branches(self):
341
 
        branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
 
344
        branch1_tree, branch2_tree = super(TestCheckoutDiff,
 
345
                                           self).example_branches()
342
346
        os.mkdir('checkouts')
343
347
        branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
344
348
        branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
384
388
        # subprocess.py that we had to workaround).
385
389
        # However, if 'diff' may not be available
386
390
        self.make_example_branch()
387
 
        # this will be automatically restored by the base bzr test class
388
 
        os.environ['BZR_PROGRESS_BAR'] = 'none'
389
 
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
390
 
                                           universal_newlines=True,
391
 
                                           retcode=None)
 
391
        out, err = self.run_bzr_subprocess(
 
392
            'diff -Oprogress_bar=none -r 1 --diff-options -ub',
 
393
            universal_newlines=True,
 
394
            retcode=None)
392
395
        if 'Diff is not installed on this machine' in err:
393
396
            raise tests.TestSkipped("No external 'diff' is available")
394
397
        self.assertEqual('', err)
395
398
        # We have to skip the stuff in the middle, because it depends
396
399
        # on time.time()
397
 
        self.assertStartsWith(out, "=== added file 'goodbye'\n"
398
 
                                   "--- goodbye\t1970-01-01 00:00:00 +0000\n"
399
 
                                   "+++ goodbye\t")
 
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
405
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
401
406
                                 "+baz\n\n")
402
407
 
 
408
    def test_external_diff_options_and_using(self):
 
409
        """Test that the options are passed correctly to an external diff process"""
 
410
        self.requireFeature(features.diff_feature)
 
411
        self.make_example_branch()
 
412
        self.build_tree_contents([('hello', 'Foo\n')])
 
413
        out, err = self.run_bzr('diff --diff-options -i --using diff',
 
414
                                    retcode=1)
 
415
        self.assertEqual("=== modified file 'hello'\n", out)
 
416
        self.assertEqual('', err)
 
417
 
403
418
 
404
419
class TestDiffOutput(DiffBase):
405
420
 
408
423
        self.make_example_branch()
409
424
        self.build_tree_contents([('hello', 'hello world!\n')])
410
425
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
411
 
        self.assert_('\n+hello world!\n' in output)
 
426
        self.assertTrue('\n+hello world!\n' in output)