~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jamie Wilkinson
  • Date: 2006-07-18 23:59:52 UTC
  • mfrom: (1868 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1874.
  • Revision ID: jaq@spacepants.org-20060718235952-1e362401a7858958
merge from bzr.dev

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
 
26
from bzrlib import workingtree
25
27
from bzrlib.tests.blackbox import ExternalBase
26
28
 
27
29
 
 
30
def subst_dates(string):
 
31
    """Replace date strings with constant values."""
 
32
    return re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-\+]\d{4}',
 
33
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
 
34
 
 
35
 
28
36
class TestDiff(ExternalBase):
29
37
 
30
38
    def make_example_branch(test):
31
39
        # FIXME: copied from test_too_much -- share elsewhere?
32
40
        test.runbzr('init')
33
 
        file('hello', 'wt').write('foo\n')
 
41
        file('hello', 'wb').write('foo\n')
34
42
        test.runbzr('add hello')
35
43
        test.runbzr('commit -m setup hello')
36
 
        file('goodbye', 'wt').write('baz\n')
 
44
        file('goodbye', 'wb').write('baz\n')
37
45
        test.runbzr('add goodbye')
38
46
        test.runbzr('commit -m setup goodbye')
39
47
 
53
61
    def test_diff_prefix(self):
54
62
        """diff --prefix appends to filenames in output"""
55
63
        self.make_example_branch()
56
 
        file('hello', 'wt').write('hello world!\n')
 
64
        file('hello', 'wb').write('hello world!\n')
57
65
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
58
66
        self.assertEquals(err, '')
59
 
        self.assertEqualDiff(out, '''\
 
67
        self.assertEqualDiff(subst_dates(out), '''\
60
68
=== modified file 'hello'
61
 
--- old/hello\t
62
 
+++ new/hello\t
 
69
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
70
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
63
71
@@ -1,1 +1,1 @@
64
72
-foo
65
73
+hello world!
69
77
    def test_diff_p1(self):
70
78
        """diff -p1 produces lkml-style diffs"""
71
79
        self.make_example_branch()
72
 
        file('hello', 'wt').write('hello world!\n')
 
80
        file('hello', 'wb').write('hello world!\n')
73
81
        out, err = self.runbzr('diff -p1', retcode=1)
74
82
        self.assertEquals(err, '')
75
 
        self.assertEqualDiff(out, '''\
 
83
        self.assertEqualDiff(subst_dates(out), '''\
76
84
=== modified file 'hello'
77
 
--- old/hello\t
78
 
+++ new/hello\t
 
85
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
86
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
79
87
@@ -1,1 +1,1 @@
80
88
-foo
81
89
+hello world!
85
93
    def test_diff_p0(self):
86
94
        """diff -p0 produces diffs with no prefix"""
87
95
        self.make_example_branch()
88
 
        file('hello', 'wt').write('hello world!\n')
 
96
        file('hello', 'wb').write('hello world!\n')
89
97
        out, err = self.runbzr('diff -p0', retcode=1)
90
98
        self.assertEquals(err, '')
91
 
        self.assertEqualDiff(out, '''\
 
99
        self.assertEqualDiff(subst_dates(out), '''\
92
100
=== modified file 'hello'
93
 
--- hello\t
94
 
+++ hello\t
 
101
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
102
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
95
103
@@ -1,1 +1,1 @@
96
104
-foo
97
105
+hello world!
127
135
    def test_diff_branches(self):
128
136
        self.example_branches()
129
137
        # should open branch1 and diff against branch2, 
130
 
        output = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
131
 
                                        'branch1'],
132
 
                                       retcode=1)
133
 
        self.assertEquals(("=== modified file 'file'\n"
134
 
                           "--- file\t\n"
135
 
                           "+++ file\t\n"
136
 
                           "@@ -1,1 +1,1 @@\n"
137
 
                           "-new content\n"
138
 
                           "+contents of branch1/file\n"
139
 
                           "\n", ''), output)
140
 
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
141
 
                                       retcode=1)
142
 
        self.assertEqualDiff(("=== modified file 'file'\n"
143
 
                              "--- file\t\n"
144
 
                              "+++ file\t\n"
145
 
                              "@@ -1,1 +1,1 @@\n"
146
 
                              "-new content\n"
147
 
                              "+contents of branch1/file\n"
148
 
                              "\n", ''), output)
 
138
        out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
139
                                          'branch1'],
 
140
                                         retcode=1)
 
141
        self.assertEquals('', err)
 
142
        self.assertEquals("=== modified file 'file'\n"
 
143
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
144
                          "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
145
                          "@@ -1,1 +1,1 @@\n"
 
146
                          "-new content\n"
 
147
                          "+contents of branch1/file\n"
 
148
                          "\n", subst_dates(out))
 
149
        out, ett = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
150
                                         retcode=1)
 
151
        self.assertEquals('', err)
 
152
        self.assertEqualDiff("=== modified file 'file'\n"
 
153
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
154
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
155
                              "@@ -1,1 +1,1 @@\n"
 
156
                              "-new content\n"
 
157
                              "+contents of branch1/file\n"
 
158
                              "\n", subst_dates(out))
 
159
 
 
160
    def test_diff_revno_branches(self):
 
161
        self.example_branches()
 
162
        print >> open('branch2/file', 'wb'), 'even newer content'
 
163
        self.run_bzr_captured(['commit', '-m', 'update file once more', 'branch2'])
 
164
 
 
165
        out, err = self.run_bzr_captured(['diff', '-r', 'revno:1:branch2..revno:1:branch1'],
 
166
                                         retcode=0)
 
167
        self.assertEquals('', err)
 
168
        self.assertEquals('', out)
 
169
        out, ett = self.run_bzr_captured(['diff', '-r', 'revno:2:branch2..revno:1:branch1'],
 
170
                                         retcode=1)
 
171
        self.assertEquals('', err)
 
172
        self.assertEqualDiff("=== modified file 'file'\n"
 
173
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
174
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
175
                              "@@ -1,1 +1,1 @@\n"
 
176
                              "-new content\n"
 
177
                              "+contents of branch1/file\n"
 
178
                              "\n", subst_dates(out))
149
179
 
150
180
    def example_branch2(self):
151
181
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
164
194
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1)
165
195
        self.assertTrue('\n-original line\n+new line\n' in output[0])
166
196
 
 
197
    def test_diff_across_rename(self):
 
198
        """The working tree path should always be considered for diffing"""
 
199
        self.make_example_branch()
 
200
        self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
 
201
        wt = workingtree.WorkingTree.open_containing('.')[0]
 
202
        wt.rename_one('hello', 'hello1')
 
203
        self.run_bzr('diff', 'hello1', retcode=1)
 
204
        self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
 
205
 
167
206
 
168
207
class TestCheckoutDiff(TestDiff):
169
208