~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2006-11-10 15:38:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2129.
  • Revision ID: john@arbash-meinel.com-20061110153816-46acf76fc86a512b
use try/finally to clean up a nested progress bar during weave fetching

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                  'YYYY-MM-DD HH:MM:SS +ZZZZ', string)
35
35
 
36
36
 
37
 
class DiffBase(ExternalBase):
38
 
    """Base class with common setup method"""
 
37
class TestDiff(ExternalBase):
39
38
 
40
39
    def make_example_branch(self):
41
40
        # FIXME: copied from test_too_much -- share elsewhere?
47
46
        tree.add(['goodbye'])
48
47
        tree.commit('setup')
49
48
 
50
 
 
51
 
class TestDiff(DiffBase):
52
 
 
53
49
    def test_diff(self):
54
50
        self.make_example_branch()
55
51
        file('hello', 'wt').write('hello world!')
56
 
        self.run_bzr('commit -m fixing hello')
57
 
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
 
52
        self.runbzr('commit -m fixing hello')
 
53
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
58
54
        self.assert_('\n+hello world!' in output)
59
 
        output = self.run_bzr('diff -r last:3..last:1',
60
 
                retcode=1)[0]
 
55
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
61
56
        self.assert_('\n+baz' in output)
62
 
        self.build_tree(['moo'])
63
 
        self.run_bzr('add moo')
 
57
        file('moo', 'wb').write('moo')
 
58
        self.runbzr('add moo')
64
59
        os.unlink('moo')
65
 
        self.run_bzr('diff')
 
60
        self.runbzr('diff')
66
61
 
67
62
    def test_diff_prefix(self):
68
63
        """diff --prefix appends to filenames in output"""
69
64
        self.make_example_branch()
70
65
        file('hello', 'wb').write('hello world!\n')
71
 
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
 
66
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
72
67
        self.assertEquals(err, '')
73
68
        self.assertEqualDiff(subst_dates(out), '''\
74
69
=== modified file 'hello'
80
75
 
81
76
''')
82
77
 
83
 
    def test_diff_illegal_prefix_value(self):
84
 
        # There was an error in error reporting for this option
85
 
        out, err = self.run_bzr('diff --prefix old/', retcode=3)
86
 
        self.assertContainsRe(err,
87
 
            '--prefix expects two values separated by a colon')
88
 
 
89
78
    def test_diff_p1(self):
90
79
        """diff -p1 produces lkml-style diffs"""
91
80
        self.make_example_branch()
92
81
        file('hello', 'wb').write('hello world!\n')
93
 
        out, err = self.run_bzr('diff -p1', retcode=1)
 
82
        out, err = self.runbzr('diff -p1', retcode=1)
94
83
        self.assertEquals(err, '')
95
84
        self.assertEqualDiff(subst_dates(out), '''\
96
85
=== modified file 'hello'
106
95
        """diff -p0 produces diffs with no prefix"""
107
96
        self.make_example_branch()
108
97
        file('hello', 'wb').write('hello world!\n')
109
 
        out, err = self.run_bzr('diff -p0', retcode=1)
 
98
        out, err = self.runbzr('diff -p0', retcode=1)
110
99
        self.assertEquals(err, '')
111
100
        self.assertEqualDiff(subst_dates(out), '''\
112
101
=== modified file 'hello'
122
111
        # Get an error from a file that does not exist at all
123
112
        # (Malone #3619)
124
113
        self.make_example_branch()
125
 
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
 
114
        out, err = self.runbzr('diff does-not-exist', retcode=3)
126
115
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
127
116
 
128
 
    def test_diff_illegal_revision_specifiers(self):
129
 
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
130
 
        self.assertContainsRe(err, 'one or two revision specifiers')
131
 
 
132
117
    def test_diff_unversioned(self):
133
118
        # Get an error when diffing a non-versioned file.
134
119
        # (Malone #3619)
135
120
        self.make_example_branch()
136
121
        self.build_tree(['unversioned-file'])
137
 
        out, err = self.run_bzr('diff unversioned-file', retcode=3)
 
122
        out, err = self.runbzr('diff unversioned-file', retcode=3)
138
123
        self.assertContainsRe(err, 'not versioned.*unversioned-file')
139
124
 
140
125
    # TODO: What should diff say for a file deleted in working tree?
141
126
 
142
127
    def example_branches(self):
143
128
        self.build_tree(['branch1/', 'branch1/file'], line_endings='binary')
144
 
        self.run_bzr('init branch1')[0]
145
 
        self.run_bzr('add branch1/file')[0]
146
 
        self.run_bzr(['commit', '-m', 'add file', 'branch1'])
147
 
        self.run_bzr('branch branch1 branch2')[0]
148
 
        self.build_tree_contents([('branch2/file', 'new content\n')])
149
 
        self.run_bzr(['commit', '-m', 'update file', 'branch2'])
 
129
        self.capture('init branch1')
 
130
        self.capture('add branch1/file')
 
131
        self.run_bzr_captured(['commit', '-m', 'add file', 'branch1'])
 
132
        self.capture('branch branch1 branch2')
 
133
        print >> open('branch2/file', 'wb'), 'new content'
 
134
        self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])
150
135
 
151
136
    def test_diff_branches(self):
152
137
        self.example_branches()
153
138
        # should open branch1 and diff against branch2, 
154
 
        out, err = self.run_bzr('diff -r branch:branch2 branch1',
155
 
                                retcode=1)
 
139
        out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
140
                                          'branch1'],
 
141
                                         retcode=1)
156
142
        self.assertEquals('', err)
157
143
        self.assertEquals("=== modified file 'file'\n"
158
144
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
161
147
                          "-new content\n"
162
148
                          "+contents of branch1/file\n"
163
149
                          "\n", subst_dates(out))
164
 
        out, err = self.run_bzr('diff branch2 branch1',
 
150
        out, err = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
165
151
                                         retcode=1)
166
152
        self.assertEquals('', err)
167
153
        self.assertEqualDiff("=== modified file 'file'\n"
175
161
    def test_diff_revno_branches(self):
176
162
        self.example_branches()
177
163
        print >> open('branch2/file', 'wb'), 'even newer content'
178
 
        self.run_bzr(['commit', '-m',
179
 
                      'update file once more', 'branch2'])
 
164
        self.run_bzr_captured(['commit', '-m', 
 
165
                               'update file once more', 'branch2'])
180
166
 
181
 
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
182
 
                                )
 
167
        out, err = self.run_bzr_captured(['diff', '-r',
 
168
                                          'revno:1:branch2..revno:1:branch1'],
 
169
                                         retcode=0)
183
170
        self.assertEquals('', err)
184
171
        self.assertEquals('', out)
185
 
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
186
 
                                retcode=1)
 
172
        out, err = self.run_bzr_captured(['diff', '-r', 
 
173
                                          'revno:2:branch2..revno:1:branch1'],
 
174
                                         retcode=1)
187
175
        self.assertEquals('', err)
188
176
        self.assertEqualDiff("=== modified file 'file'\n"
189
177
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
195
183
 
196
184
    def example_branch2(self):
197
185
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
198
 
        self.run_bzr('init branch1')[0]
199
 
        self.run_bzr('add branch1/file1')[0]
 
186
        self.capture('init branch1')
 
187
        self.capture('add branch1/file1')
200
188
        print >> open('branch1/file1', 'wb'), 'original line'
201
 
        self.run_bzr(['commit', '-m', 'first commit', 'branch1'])
 
189
        self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1'])
202
190
        
203
191
        print >> open('branch1/file1', 'wb'), 'repo line'
204
 
        self.run_bzr(['commit', '-m', 'second commit', 'branch1'])
 
192
        self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
205
193
 
206
194
    def test_diff_to_working_tree(self):
207
195
        self.example_branch2()
208
196
        
209
197
        print >> open('branch1/file1', 'wb'), 'new line'
210
 
        output = self.run_bzr('diff -r 1.. branch1',
211
 
                              retcode=1)
 
198
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'],
 
199
                                       retcode=1)
212
200
        self.assertTrue('\n-original line\n+new line\n' in output[0])
213
201
 
214
202
    def test_diff_across_rename(self):
215
203
        """The working tree path should always be considered for diffing"""
216
204
        self.make_example_branch()
217
 
        self.run_bzr('diff -r 0..1 hello', retcode=1)
 
205
        self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
218
206
        wt = workingtree.WorkingTree.open_containing('.')[0]
219
207
        wt.rename_one('hello', 'hello1')
220
 
        self.run_bzr('diff hello1', retcode=1)
221
 
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
 
208
        self.run_bzr('diff', 'hello1', retcode=1)
 
209
        self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
222
210
 
223
211
 
224
212
class TestCheckoutDiff(TestDiff):
225
213
 
226
214
    def make_example_branch(self):
227
215
        super(TestCheckoutDiff, self).make_example_branch()
228
 
        self.run_bzr('checkout . checkout')
 
216
        self.runbzr('checkout . checkout')
229
217
        os.chdir('checkout')
230
218
 
231
219
    def example_branch2(self):
232
220
        super(TestCheckoutDiff, self).example_branch2()
233
221
        os.mkdir('checkouts')
234
 
        self.run_bzr('checkout branch1 checkouts/branch1')
 
222
        self.runbzr('checkout branch1 checkouts/branch1')
235
223
        os.chdir('checkouts')
236
224
 
237
225
    def example_branches(self):
238
226
        super(TestCheckoutDiff, self).example_branches()
239
227
        os.mkdir('checkouts')
240
 
        self.run_bzr('checkout branch1 checkouts/branch1')
241
 
        self.run_bzr('checkout branch2 checkouts/branch2')
 
228
        self.runbzr('checkout branch1 checkouts/branch1')
 
229
        self.runbzr('checkout branch2 checkouts/branch2')
242
230
        os.chdir('checkouts')
243
231
 
244
232
 
245
 
class TestDiffLabels(DiffBase):
 
233
class TestDiffLabels(TestDiff):
246
234
 
247
235
    def test_diff_label_removed(self):
248
236
        super(TestDiffLabels, self).make_example_branch()
249
 
        self.run_bzr('remove hello')
250
 
        diff = self.run_bzr('diff', retcode=1)
 
237
        self.runbzr('remove hello')
 
238
        diff = self.run_bzr_captured(['diff'], retcode=1)
251
239
        self.assertTrue("=== removed file 'hello'" in diff[0])
252
240
 
253
241
    def test_diff_label_added(self):
254
242
        super(TestDiffLabels, self).make_example_branch()
255
243
        file('barbar', 'wt').write('barbar')
256
 
        self.run_bzr('add barbar')
257
 
        diff = self.run_bzr('diff', retcode=1)
 
244
        self.runbzr('add barbar')
 
245
        diff = self.run_bzr_captured(['diff'], retcode=1)
258
246
        self.assertTrue("=== added file 'barbar'" in diff[0])
259
247
 
260
248
    def test_diff_label_modified(self):
261
249
        super(TestDiffLabels, self).make_example_branch()
262
250
        file('hello', 'wt').write('barbar')
263
 
        diff = self.run_bzr('diff', retcode=1)
 
251
        diff = self.run_bzr_captured(['diff'], retcode=1)
264
252
        self.assertTrue("=== modified file 'hello'" in diff[0])
265
253
 
266
254
    def test_diff_label_renamed(self):
267
255
        super(TestDiffLabels, self).make_example_branch()
268
 
        self.run_bzr('rename hello gruezi')
269
 
        diff = self.run_bzr('diff', retcode=1)
 
256
        self.runbzr('rename hello gruezi')
 
257
        diff = self.run_bzr_captured(['diff'], retcode=1)
270
258
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
271
259
 
272
260
 
273
 
class TestExternalDiff(DiffBase):
 
261
class TestExternalDiff(TestDiff):
274
262
 
275
263
    def test_external_diff(self):
276
264
        """Test that we can spawn an external diff process"""
302
290
                                   "+++ goodbye\t")
303
291
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
304
292
                                 "+baz\n\n")
305
 
 
306
 
 
307
 
class TestDiffOutput(DiffBase):
308
 
 
309
 
    def test_diff_output(self):
310
 
        # check that output doesn't mangle line-endings
311
 
        self.make_example_branch()
312
 
        file('hello', 'wb').write('hello world!\n')
313
 
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
314
 
        self.assert_('\n+hello world!\n' in output)