~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
25
24
    tests,
26
25
    workingtree,
27
26
    )
 
27
from bzrlib.diff import (
 
28
    DiffTree,
 
29
    format_registry as diff_format_registry,
 
30
    )
 
31
from bzrlib.tests import (
 
32
    features,
 
33
    )
28
34
 
29
35
 
30
36
def subst_dates(string):
55
61
        self.build_tree_contents([('hello', 'hello world!')])
56
62
        tree.commit(message='fixing hello')
57
63
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
58
 
        self.assert_('\n+hello world!' in output)
 
64
        self.assertTrue('\n+hello world!' in output)
59
65
        output = self.run_bzr('diff -c 3', retcode=1)[0]
60
 
        self.assert_('\n+hello world!' in output)
 
66
        self.assertTrue('\n+hello world!' in output)
61
67
        output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
62
 
        self.assert_('\n+baz' in output)
 
68
        self.assertTrue('\n+baz' in output)
63
69
        output = self.run_bzr('diff -c last:2', retcode=1)[0]
64
 
        self.assert_('\n+baz' in output)
 
70
        self.assertTrue('\n+baz' in output)
65
71
        self.build_tree(['moo'])
66
72
        tree.add('moo')
67
73
        os.unlink('moo')
72
78
        self.make_example_branch()
73
79
        self.build_tree_contents([('hello', 'hello world!\n')])
74
80
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
75
 
        self.assertEquals(err, '')
 
81
        self.assertEqual(err, '')
76
82
        self.assertEqualDiff(subst_dates(out), '''\
77
83
=== modified file 'hello'
78
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
94
100
        self.make_example_branch()
95
101
        self.build_tree_contents([('hello', 'hello world!\n')])
96
102
        out, err = self.run_bzr('diff -p1', retcode=1)
97
 
        self.assertEquals(err, '')
 
103
        self.assertEqual(err, '')
98
104
        self.assertEqualDiff(subst_dates(out), '''\
99
105
=== modified file 'hello'
100
106
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
110
116
        self.make_example_branch()
111
117
        self.build_tree_contents([('hello', 'hello world!\n')])
112
118
        out, err = self.run_bzr('diff -p0', retcode=1)
113
 
        self.assertEquals(err, '')
 
119
        self.assertEqual(err, '')
114
120
        self.assertEqualDiff(subst_dates(out), '''\
115
121
=== modified file 'hello'
116
122
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
132
138
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
133
139
            error_regexes=('one or two revision specifiers',))
134
140
 
 
141
    def test_diff_using_and_format(self):
 
142
        out, err = self.run_bzr('diff --format=default --using=mydi', retcode=3,
 
143
            error_regexes=('are mutually exclusive',))
 
144
 
135
145
    def test_diff_nonexistent_revision(self):
136
146
        out, err = self.run_bzr('diff -r 123', retcode=3,
137
147
            error_regexes=("Requested revision: '123' does not "
172
182
    def check_b2_vs_b1(self, cmd):
173
183
        # Compare branch2 vs branch1 using cmd and check the result
174
184
        out, err = self.run_bzr(cmd, retcode=1)
175
 
        self.assertEquals('', err)
176
 
        self.assertEquals("=== modified file 'file'\n"
 
185
        self.assertEqual('', err)
 
186
        self.assertEqual("=== modified file 'file'\n"
177
187
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
178
188
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
179
189
                          "@@ -1,1 +1,1 @@\n"
184
194
    def check_b1_vs_b2(self, cmd):
185
195
        # Compare branch1 vs branch2 using cmd and check the result
186
196
        out, err = self.run_bzr(cmd, retcode=1)
187
 
        self.assertEquals('', err)
 
197
        self.assertEqual('', err)
188
198
        self.assertEqualDiff("=== modified file 'file'\n"
189
199
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
190
200
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
196
206
    def check_no_diffs(self, cmd):
197
207
        # Check that running cmd returns an empty diff
198
208
        out, err = self.run_bzr(cmd, retcode=0)
199
 
        self.assertEquals('', err)
200
 
        self.assertEquals('', out)
 
209
        self.assertEqual('', err)
 
210
        self.assertEqual('', out)
201
211
 
202
212
    def test_diff_branches(self):
203
213
        self.example_branches()
245
255
 
246
256
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
247
257
                                )
248
 
        self.assertEquals('', err)
249
 
        self.assertEquals('', out)
 
258
        self.assertEqual('', err)
 
259
        self.assertEqual('', out)
250
260
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
251
261
                                retcode=1)
252
 
        self.assertEquals('', err)
 
262
        self.assertEqual('', err)
253
263
        self.assertEqualDiff("=== modified file 'file'\n"
254
264
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
255
265
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
277
287
        self.example_branch2()
278
288
        self.build_tree_contents([('branch1/file1', 'new line')])
279
289
        os.mkdir('branch1/dir1')
280
 
        os.chdir('branch1/dir1')
281
 
        output = self.run_bzr('diff -r 1..', retcode=1)
 
290
        output = self.run_bzr('diff -r 1..', retcode=1,
 
291
                              working_dir='branch1/dir1')
282
292
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
283
293
 
284
294
    def test_diff_across_rename(self):
297
307
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
298
308
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
299
309
 
 
310
    def test_custom_format(self):
 
311
        class BooDiffTree(DiffTree):
 
312
 
 
313
            def show_diff(self, specific_files, extra_trees=None):
 
314
                self.to_file.write("BOO!\n")
 
315
                return super(BooDiffTree, self).show_diff(specific_files,
 
316
                    extra_trees)
 
317
 
 
318
        diff_format_registry.register("boo", BooDiffTree, "Scary diff format")
 
319
        self.addCleanup(diff_format_registry.remove, "boo")
 
320
        self.make_example_branch()
 
321
        self.build_tree_contents([('hello', 'hello world!\n')])
 
322
        output = self.run_bzr('diff --format=boo', retcode=1)
 
323
        self.assertTrue("BOO!" in output[0])
 
324
        output = self.run_bzr('diff -Fboo', retcode=1)
 
325
        self.assertTrue("BOO!" in output[0])
 
326
 
300
327
 
301
328
class TestCheckoutDiff(TestDiff):
302
329
 
314
341
        return tree
315
342
 
316
343
    def example_branches(self):
317
 
        branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
 
344
        branch1_tree, branch2_tree = super(TestCheckoutDiff,
 
345
                                           self).example_branches()
318
346
        os.mkdir('checkouts')
319
347
        branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
320
348
        branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
360
388
        # subprocess.py that we had to workaround).
361
389
        # However, if 'diff' may not be available
362
390
        self.make_example_branch()
363
 
        # this will be automatically restored by the base bzr test class
364
 
        os.environ['BZR_PROGRESS_BAR'] = 'none'
365
 
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
366
 
                                           universal_newlines=True,
367
 
                                           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)
368
395
        if 'Diff is not installed on this machine' in err:
369
396
            raise tests.TestSkipped("No external 'diff' is available")
370
397
        self.assertEqual('', err)
376
403
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
377
404
                                 "+baz\n\n")
378
405
 
 
406
    def test_external_diff_options_and_using(self):
 
407
        """Test that the options are passed correctly to an external diff process"""
 
408
        self.requireFeature(features.diff_feature)
 
409
        self.make_example_branch()
 
410
        self.build_tree_contents([('hello', 'Foo\n')])
 
411
        out, err = self.run_bzr('diff --diff-options -i --using diff',
 
412
                                    retcode=1)
 
413
        self.assertEqual("=== modified file 'hello'\n", out)
 
414
        self.assertEqual('', err)
 
415
 
379
416
 
380
417
class TestDiffOutput(DiffBase):
381
418
 
384
421
        self.make_example_branch()
385
422
        self.build_tree_contents([('hello', 'hello world!\n')])
386
423
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
387
 
        self.assert_('\n+hello world!\n' in output)
 
424
        self.assertTrue('\n+hello world!\n' in output)