/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: Canonical.com Patch Queue Manager
  • Date: 2006-06-26 19:35:47 UTC
  • mfrom: (1813.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060626193547-43661d1377f72b4d
(robertc) Misc minor typos and the like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
"""
20
20
 
21
21
import os
 
22
import re
22
23
 
23
24
import bzrlib
24
25
from bzrlib.branch import Branch
25
26
from bzrlib.tests.blackbox import ExternalBase
26
27
 
27
28
 
 
29
def subst_dates(string):
 
30
    """Replace date strings with constant values."""
 
31
    return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
 
32
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
 
33
 
 
34
 
28
35
class TestDiff(ExternalBase):
29
36
 
30
37
    def make_example_branch(test):
31
38
        # FIXME: copied from test_too_much -- share elsewhere?
32
39
        test.runbzr('init')
33
 
        file('hello', 'wt').write('foo')
 
40
        file('hello', 'wt').write('foo\n')
34
41
        test.runbzr('add hello')
35
42
        test.runbzr('commit -m setup hello')
36
 
        file('goodbye', 'wt').write('baz')
 
43
        file('goodbye', 'wt').write('baz\n')
37
44
        test.runbzr('add goodbye')
38
45
        test.runbzr('commit -m setup goodbye')
39
46
 
50
57
        os.unlink('moo')
51
58
        self.runbzr('diff')
52
59
 
 
60
    def test_diff_prefix(self):
 
61
        """diff --prefix appends to filenames in output"""
 
62
        self.make_example_branch()
 
63
        file('hello', 'wt').write('hello world!\n')
 
64
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
 
65
        self.assertEquals(err, '')
 
66
        self.assertEqualDiff(subst_dates(out), '''\
 
67
=== modified file 'hello'
 
68
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
69
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
70
@@ -1,1 +1,1 @@
 
71
-foo
 
72
+hello world!
 
73
 
 
74
''')
 
75
 
 
76
    def test_diff_p1(self):
 
77
        """diff -p1 produces lkml-style diffs"""
 
78
        self.make_example_branch()
 
79
        file('hello', 'wt').write('hello world!\n')
 
80
        out, err = self.runbzr('diff -p1', retcode=1)
 
81
        self.assertEquals(err, '')
 
82
        self.assertEqualDiff(subst_dates(out), '''\
 
83
=== modified file 'hello'
 
84
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
85
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
86
@@ -1,1 +1,1 @@
 
87
-foo
 
88
+hello world!
 
89
 
 
90
''')
 
91
 
 
92
    def test_diff_p0(self):
 
93
        """diff -p0 produces diffs with no prefix"""
 
94
        self.make_example_branch()
 
95
        file('hello', 'wt').write('hello world!\n')
 
96
        out, err = self.runbzr('diff -p0', retcode=1)
 
97
        self.assertEquals(err, '')
 
98
        self.assertEqualDiff(subst_dates(out), '''\
 
99
=== modified file 'hello'
 
100
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
101
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
102
@@ -1,1 +1,1 @@
 
103
-foo
 
104
+hello world!
 
105
 
 
106
''')
 
107
 
53
108
    def test_diff_nonexistent(self):
54
109
        # Get an error from a file that does not exist at all
55
110
        # (Malone #3619)
79
134
    def test_diff_branches(self):
80
135
        self.example_branches()
81
136
        # should open branch1 and diff against branch2, 
82
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
83
 
                                        'branch1'],
84
 
                                       retcode=1)
85
 
        self.assertEquals(("=== modified file 'a/file'\n"
86
 
                           "--- a/file\t\n"
87
 
                           "+++ b/file\t\n"
88
 
                           "@@ -1,1 +1,1 @@\n"
89
 
                           "-new content\n"
90
 
                           "+contents of branch1/file\n"
91
 
                           "\n", ''), output)
92
 
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
93
 
                                       retcode=1)
94
 
        self.assertEqualDiff(("=== modified file 'a/file'\n"
95
 
                              "--- a/file\t\n"
96
 
                              "+++ b/file\t\n"
 
137
        out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
138
                                          'branch1'],
 
139
                                         retcode=1)
 
140
        self.assertEquals('', err)
 
141
        self.assertEquals("=== modified file 'file'\n"
 
142
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
143
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
144
                          "@@ -1,1 +1,1 @@\n"
 
145
                          "-new content\n"
 
146
                          "+contents of branch1/file\n"
 
147
                          "\n", subst_dates(out))
 
148
        out, ett = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
149
                                         retcode=1)
 
150
        self.assertEquals('', err)
 
151
        self.assertEqualDiff("=== modified file 'file'\n"
 
152
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
153
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
97
154
                              "@@ -1,1 +1,1 @@\n"
98
155
                              "-new content\n"
99
156
                              "+contents of branch1/file\n"
100
 
                              "\n", ''), output)
 
157
                              "\n", subst_dates(out))
101
158
 
102
159
    def example_branch2(self):
103
160
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
144
201
        super(TestDiffLabels, self).make_example_branch()
145
202
        self.runbzr('remove hello')
146
203
        diff = self.run_bzr_captured(['diff'], retcode=1)
147
 
        self.assertTrue("=== removed file 'a/hello'" in diff[0])
 
204
        self.assertTrue("=== removed file 'hello'" in diff[0])
148
205
 
149
206
    def test_diff_label_added(self):
150
207
        super(TestDiffLabels, self).make_example_branch()
151
208
        file('barbar', 'wt').write('barbar')
152
209
        self.runbzr('add barbar')
153
210
        diff = self.run_bzr_captured(['diff'], retcode=1)
154
 
        self.assertTrue("=== added file 'b/barbar'" in diff[0])
 
211
        self.assertTrue("=== added file 'barbar'" in diff[0])
155
212
 
156
213
    def test_diff_label_modified(self):
157
214
        super(TestDiffLabels, self).make_example_branch()
158
215
        file('hello', 'wt').write('barbar')
159
216
        diff = self.run_bzr_captured(['diff'], retcode=1)
160
 
        self.assertTrue("=== modified file 'a/hello'" in diff[0])
 
217
        self.assertTrue("=== modified file 'hello'" in diff[0])
161
218
 
162
219
    def test_diff_label_renamed(self):
163
220
        super(TestDiffLabels, self).make_example_branch()
164
221
        self.runbzr('rename hello gruezi')
165
222
        diff = self.run_bzr_captured(['diff'], retcode=1)
166
 
        self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])
 
223
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])