~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-27 01:14:33 UTC
  • mfrom: (1686.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060427011433-95634ee1da8a2049
Merge in faster joins from weave to knit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 by 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
"""
20
20
 
21
21
import os
22
 
import re
23
22
 
24
23
import bzrlib
25
24
from bzrlib.branch import Branch
26
 
from bzrlib import workingtree
27
25
from bzrlib.tests.blackbox import ExternalBase
28
26
 
29
27
 
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
 
 
36
28
class TestDiff(ExternalBase):
37
29
 
38
30
    def make_example_branch(test):
39
31
        # FIXME: copied from test_too_much -- share elsewhere?
40
32
        test.runbzr('init')
41
 
        file('hello', 'wb').write('foo\n')
 
33
        file('hello', 'wt').write('foo')
42
34
        test.runbzr('add hello')
43
35
        test.runbzr('commit -m setup hello')
44
 
        file('goodbye', 'wb').write('baz\n')
 
36
        file('goodbye', 'wt').write('baz')
45
37
        test.runbzr('add goodbye')
46
38
        test.runbzr('commit -m setup goodbye')
47
39
 
58
50
        os.unlink('moo')
59
51
        self.runbzr('diff')
60
52
 
61
 
    def test_diff_prefix(self):
62
 
        """diff --prefix appends to filenames in output"""
63
 
        self.make_example_branch()
64
 
        file('hello', 'wb').write('hello world!\n')
65
 
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
66
 
        self.assertEquals(err, '')
67
 
        self.assertEqualDiff(subst_dates(out), '''\
68
 
=== modified file 'hello'
69
 
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
70
 
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
71
 
@@ -1,1 +1,1 @@
72
 
-foo
73
 
+hello world!
74
 
 
75
 
''')
76
 
 
77
 
    def test_diff_p1(self):
78
 
        """diff -p1 produces lkml-style diffs"""
79
 
        self.make_example_branch()
80
 
        file('hello', 'wb').write('hello world!\n')
81
 
        out, err = self.runbzr('diff -p1', retcode=1)
82
 
        self.assertEquals(err, '')
83
 
        self.assertEqualDiff(subst_dates(out), '''\
84
 
=== modified file 'hello'
85
 
--- old/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
86
 
+++ new/hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
87
 
@@ -1,1 +1,1 @@
88
 
-foo
89
 
+hello world!
90
 
 
91
 
''')
92
 
 
93
 
    def test_diff_p0(self):
94
 
        """diff -p0 produces diffs with no prefix"""
95
 
        self.make_example_branch()
96
 
        file('hello', 'wb').write('hello world!\n')
97
 
        out, err = self.runbzr('diff -p0', retcode=1)
98
 
        self.assertEquals(err, '')
99
 
        self.assertEqualDiff(subst_dates(out), '''\
100
 
=== modified file 'hello'
101
 
--- hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
102
 
+++ hello\tYYYY-MM-DD HH:MM:SS +ZZZZ
103
 
@@ -1,1 +1,1 @@
104
 
-foo
105
 
+hello world!
106
 
 
107
 
''')
108
 
 
109
53
    def test_diff_nonexistent(self):
110
54
        # Get an error from a file that does not exist at all
111
55
        # (Malone #3619)
135
79
    def test_diff_branches(self):
136
80
        self.example_branches()
137
81
        # should open branch1 and diff against branch2, 
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, err = 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', 
164
 
                               'update file once more', 'branch2'])
165
 
 
166
 
        out, err = self.run_bzr_captured(['diff', '-r',
167
 
                                          'revno:1:branch2..revno:1:branch1'],
168
 
                                         retcode=0)
169
 
        self.assertEquals('', err)
170
 
        self.assertEquals('', out)
171
 
        out, err = self.run_bzr_captured(['diff', '-r', 
172
 
                                          'revno:2:branch2..revno:1:branch1'],
173
 
                                         retcode=1)
174
 
        self.assertEquals('', err)
175
 
        self.assertEqualDiff("=== modified file 'file'\n"
176
 
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
177
 
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
178
 
                              "@@ -1,1 +1,1 @@\n"
179
 
                              "-new content\n"
180
 
                              "+contents of branch1/file\n"
181
 
                              "\n", subst_dates(out))
 
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"
 
97
                              "@@ -1,1 +1,1 @@\n"
 
98
                              "-new content\n"
 
99
                              "+contents of branch1/file\n"
 
100
                              "\n", ''), output)
182
101
 
183
102
    def example_branch2(self):
184
103
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
194
113
        self.example_branch2()
195
114
        
196
115
        print >> open('branch1/file1', 'wb'), 'new line'
197
 
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'],
198
 
                                       retcode=1)
 
116
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'], retcode=1)
199
117
        self.assertTrue('\n-original line\n+new line\n' in output[0])
200
118
 
201
 
    def test_diff_across_rename(self):
202
 
        """The working tree path should always be considered for diffing"""
203
 
        self.make_example_branch()
204
 
        self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
205
 
        wt = workingtree.WorkingTree.open_containing('.')[0]
206
 
        wt.rename_one('hello', 'hello1')
207
 
        self.run_bzr('diff', 'hello1', retcode=1)
208
 
        self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
209
 
 
210
119
 
211
120
class TestCheckoutDiff(TestDiff):
212
121
 
235
144
        super(TestDiffLabels, self).make_example_branch()
236
145
        self.runbzr('remove hello')
237
146
        diff = self.run_bzr_captured(['diff'], retcode=1)
238
 
        self.assertTrue("=== removed file 'hello'" in diff[0])
 
147
        self.assertTrue("=== removed file 'a/hello'" in diff[0])
239
148
 
240
149
    def test_diff_label_added(self):
241
150
        super(TestDiffLabels, self).make_example_branch()
242
151
        file('barbar', 'wt').write('barbar')
243
152
        self.runbzr('add barbar')
244
153
        diff = self.run_bzr_captured(['diff'], retcode=1)
245
 
        self.assertTrue("=== added file 'barbar'" in diff[0])
 
154
        self.assertTrue("=== added file 'b/barbar'" in diff[0])
246
155
 
247
156
    def test_diff_label_modified(self):
248
157
        super(TestDiffLabels, self).make_example_branch()
249
158
        file('hello', 'wt').write('barbar')
250
159
        diff = self.run_bzr_captured(['diff'], retcode=1)
251
 
        self.assertTrue("=== modified file 'hello'" in diff[0])
 
160
        self.assertTrue("=== modified file 'a/hello'" in diff[0])
252
161
 
253
162
    def test_diff_label_renamed(self):
254
163
        super(TestDiffLabels, self).make_example_branch()
255
164
        self.runbzr('rename hello gruezi')
256
165
        diff = self.run_bzr_captured(['diff'], retcode=1)
257
 
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
 
166
        self.assertTrue("=== renamed file 'a/hello' => 'b/gruezi'" in diff[0])