~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 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 bzr diff."""
20
19
 
21
20
import os
22
21
import re
62
61
        self.build_tree_contents([('hello', 'hello world!')])
63
62
        tree.commit(message='fixing hello')
64
63
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
65
 
        self.assert_('\n+hello world!' in output)
 
64
        self.assertTrue('\n+hello world!' in output)
66
65
        output = self.run_bzr('diff -c 3', retcode=1)[0]
67
 
        self.assert_('\n+hello world!' in output)
 
66
        self.assertTrue('\n+hello world!' in output)
68
67
        output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
69
 
        self.assert_('\n+baz' in output)
 
68
        self.assertTrue('\n+baz' in output)
70
69
        output = self.run_bzr('diff -c last:2', retcode=1)[0]
71
 
        self.assert_('\n+baz' in output)
 
70
        self.assertTrue('\n+baz' in output)
72
71
        self.build_tree(['moo'])
73
72
        tree.add('moo')
74
73
        os.unlink('moo')
79
78
        self.make_example_branch()
80
79
        self.build_tree_contents([('hello', 'hello world!\n')])
81
80
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
82
 
        self.assertEquals(err, '')
 
81
        self.assertEqual(err, '')
83
82
        self.assertEqualDiff(subst_dates(out), '''\
84
83
=== modified file 'hello'
85
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
101
100
        self.make_example_branch()
102
101
        self.build_tree_contents([('hello', 'hello world!\n')])
103
102
        out, err = self.run_bzr('diff -p1', retcode=1)
104
 
        self.assertEquals(err, '')
 
103
        self.assertEqual(err, '')
105
104
        self.assertEqualDiff(subst_dates(out), '''\
106
105
=== modified file 'hello'
107
106
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
117
116
        self.make_example_branch()
118
117
        self.build_tree_contents([('hello', 'hello world!\n')])
119
118
        out, err = self.run_bzr('diff -p0', retcode=1)
120
 
        self.assertEquals(err, '')
 
119
        self.assertEqual(err, '')
121
120
        self.assertEqualDiff(subst_dates(out), '''\
122
121
=== modified file 'hello'
123
122
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
183
182
    def check_b2_vs_b1(self, cmd):
184
183
        # Compare branch2 vs branch1 using cmd and check the result
185
184
        out, err = self.run_bzr(cmd, retcode=1)
186
 
        self.assertEquals('', err)
187
 
        self.assertEquals("=== modified file 'file'\n"
 
185
        self.assertEqual('', err)
 
186
        self.assertEqual("=== modified file 'file'\n"
188
187
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
189
188
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
190
189
                          "@@ -1,1 +1,1 @@\n"
195
194
    def check_b1_vs_b2(self, cmd):
196
195
        # Compare branch1 vs branch2 using cmd and check the result
197
196
        out, err = self.run_bzr(cmd, retcode=1)
198
 
        self.assertEquals('', err)
 
197
        self.assertEqual('', err)
199
198
        self.assertEqualDiff("=== modified file 'file'\n"
200
199
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
201
200
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
207
206
    def check_no_diffs(self, cmd):
208
207
        # Check that running cmd returns an empty diff
209
208
        out, err = self.run_bzr(cmd, retcode=0)
210
 
        self.assertEquals('', err)
211
 
        self.assertEquals('', out)
 
209
        self.assertEqual('', err)
 
210
        self.assertEqual('', out)
212
211
 
213
212
    def test_diff_branches(self):
214
213
        self.example_branches()
256
255
 
257
256
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
258
257
                                )
259
 
        self.assertEquals('', err)
260
 
        self.assertEquals('', out)
 
258
        self.assertEqual('', err)
 
259
        self.assertEqual('', out)
261
260
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
262
261
                                retcode=1)
263
 
        self.assertEquals('', err)
 
262
        self.assertEqual('', err)
264
263
        self.assertEqualDiff("=== modified file 'file'\n"
265
264
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
266
265
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
288
287
        self.example_branch2()
289
288
        self.build_tree_contents([('branch1/file1', 'new line')])
290
289
        os.mkdir('branch1/dir1')
291
 
        os.chdir('branch1/dir1')
292
 
        output = self.run_bzr('diff -r 1..', retcode=1)
 
290
        output = self.run_bzr('diff -r 1..', retcode=1,
 
291
                              working_dir='branch1/dir1')
293
292
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
294
293
 
295
294
    def test_diff_across_rename(self):
316
315
                return super(BooDiffTree, self).show_diff(specific_files,
317
316
                    extra_trees)
318
317
 
319
 
        diff_format_registry.register("boo", BooDiffTree, 
320
 
            "Scary diff format")
 
318
        diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
321
319
        self.addCleanup(diff_format_registry.remove, "boo")
322
320
        self.make_example_branch()
323
321
        self.build_tree_contents([('hello', 'hello world!\n')])
343
341
        return tree
344
342
 
345
343
    def example_branches(self):
346
 
        branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
 
344
        branch1_tree, branch2_tree = super(TestCheckoutDiff,
 
345
                                           self).example_branches()
347
346
        os.mkdir('checkouts')
348
347
        branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
349
348
        branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
389
388
        # subprocess.py that we had to workaround).
390
389
        # However, if 'diff' may not be available
391
390
        self.make_example_branch()
392
 
        self.overrideEnv('BZR_PROGRESS_BAR', 'none')
393
 
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
394
 
                                           universal_newlines=True,
395
 
                                           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)
396
395
        if 'Diff is not installed on this machine' in err:
397
396
            raise tests.TestSkipped("No external 'diff' is available")
398
397
        self.assertEqual('', err)
411
410
        self.build_tree_contents([('hello', 'Foo\n')])
412
411
        out, err = self.run_bzr('diff --diff-options -i --using diff',
413
412
                                    retcode=1)
414
 
        self.assertEquals("=== modified file 'hello'\n", out)
415
 
        self.assertEquals('', err)
 
413
        self.assertEqual("=== modified file 'hello'\n", out)
 
414
        self.assertEqual('', err)
416
415
 
417
416
 
418
417
class TestDiffOutput(DiffBase):
422
421
        self.make_example_branch()
423
422
        self.build_tree_contents([('hello', 'hello world!\n')])
424
423
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
425
 
        self.assert_('\n+hello world!\n' in output)
 
424
        self.assertTrue('\n+hello world!\n' in output)