~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: 2011-09-16 13:27:14 UTC
  • mfrom: (6138.3.15 i18n-gettext-errors)
  • Revision ID: pqm@pqm.ubuntu.com-20110916132714-w81xvesg996w68r6
(jr) Add gettext() to user error messages
 (Jonathan Riddell)

Show diffs side-by-side

added added

removed removed

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