/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: Martin Pool
  • Date: 2007-09-03 04:35:49 UTC
  • mfrom: (2778 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2779.
  • Revision ID: mbp@sourcefrog.net-20070903043549-0cfyrgx7z2h8ppks
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    """Base class with common setup method"""
39
39
 
40
40
    def make_example_branch(self):
41
 
        # FIXME: copied from test_too_much -- share elsewhere?
42
41
        tree = self.make_branch_and_tree('.')
43
 
        open('hello', 'wb').write('foo\n')
 
42
        self.build_tree_contents([
 
43
            ('hello', 'foo\n'),
 
44
            ('goodbye', 'baz\n')])
44
45
        tree.add(['hello'])
45
46
        tree.commit('setup')
46
 
        open('goodbye', 'wb').write('baz\n')
47
47
        tree.add(['goodbye'])
48
48
        tree.commit('setup')
 
49
        return tree
49
50
 
50
51
 
51
52
class TestDiff(DiffBase):
52
53
 
53
54
    def test_diff(self):
54
 
        self.make_example_branch()
55
 
        file('hello', 'wt').write('hello world!')
56
 
        self.run_bzr('commit -m fixing hello')
 
55
        tree = self.make_example_branch()
 
56
        self.build_tree_contents([('hello', 'hello world!')])
 
57
        tree.commit(message='fixing hello')
57
58
        output = self.run_bzr('diff -r 2..3', retcode=1)[0]
58
59
        self.assert_('\n+hello world!' in output)
59
 
        output = self.run_bzr('diff -r last:3..last:1',
60
 
                retcode=1)[0]
 
60
        output = self.run_bzr('diff -c 3', retcode=1)[0]
 
61
        self.assert_('\n+hello world!' in output)
 
62
        output = self.run_bzr('diff -r last:3..last:1', retcode=1)[0]
 
63
        self.assert_('\n+baz' in output)
 
64
        output = self.run_bzr('diff -c last:2', retcode=1)[0]
61
65
        self.assert_('\n+baz' in output)
62
66
        self.build_tree(['moo'])
63
 
        self.run_bzr('add moo')
 
67
        tree.add('moo')
64
68
        os.unlink('moo')
65
69
        self.run_bzr('diff')
66
70
 
67
71
    def test_diff_prefix(self):
68
72
        """diff --prefix appends to filenames in output"""
69
73
        self.make_example_branch()
70
 
        file('hello', 'wb').write('hello world!\n')
 
74
        self.build_tree_contents([('hello', 'hello world!\n')])
71
75
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
72
76
        self.assertEquals(err, '')
73
77
        self.assertEqualDiff(subst_dates(out), '''\
89
93
    def test_diff_p1(self):
90
94
        """diff -p1 produces lkml-style diffs"""
91
95
        self.make_example_branch()
92
 
        file('hello', 'wb').write('hello world!\n')
 
96
        self.build_tree_contents([('hello', 'hello world!\n')])
93
97
        out, err = self.run_bzr('diff -p1', retcode=1)
94
98
        self.assertEquals(err, '')
95
99
        self.assertEqualDiff(subst_dates(out), '''\
105
109
    def test_diff_p0(self):
106
110
        """diff -p0 produces diffs with no prefix"""
107
111
        self.make_example_branch()
108
 
        file('hello', 'wb').write('hello world!\n')
 
112
        self.build_tree_contents([('hello', 'hello world!\n')])
109
113
        out, err = self.run_bzr('diff -p0', retcode=1)
110
114
        self.assertEquals(err, '')
111
115
        self.assertEqualDiff(subst_dates(out), '''\
140
144
    # TODO: What should diff say for a file deleted in working tree?
141
145
 
142
146
    def example_branches(self):
143
 
        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]
 
147
        branch1_tree = self.make_branch_and_tree('branch1')
 
148
        self.build_tree(['branch1/file'], line_endings='binary')
 
149
        branch1_tree.add('file')
 
150
        branch1_tree.commit(message='add file')
 
151
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
148
152
        self.build_tree_contents([('branch2/file', 'new content\n')])
149
 
        self.run_bzr(['commit', '-m', 'update file', 'branch2'])
 
153
        branch2_tree.commit(message='update file')
 
154
        return branch1_tree, branch2_tree
150
155
 
151
156
    def test_diff_branches(self):
152
157
        self.example_branches()
174
179
 
175
180
    def test_diff_revno_branches(self):
176
181
        self.example_branches()
177
 
        print >> open('branch2/file', 'wb'), 'even newer content'
178
 
        self.run_bzr(['commit', '-m',
179
 
                      'update file once more', 'branch2'])
 
182
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
 
183
        self.build_tree_contents([('branch2/file', 'even newer content')])
 
184
        branch2_tree.commit(message='update file once more')
180
185
 
181
186
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
182
187
                                )
194
199
                              "\n", subst_dates(out))
195
200
 
196
201
    def example_branch2(self):
197
 
        self.build_tree(['branch1/', 'branch1/file1'], line_endings='binary')
198
 
        self.run_bzr('init branch1')[0]
199
 
        self.run_bzr('add branch1/file1')[0]
200
 
        print >> open('branch1/file1', 'wb'), 'original line'
201
 
        self.run_bzr(['commit', '-m', 'first commit', 'branch1'])
202
 
        
203
 
        print >> open('branch1/file1', 'wb'), 'repo line'
204
 
        self.run_bzr(['commit', '-m', 'second commit', 'branch1'])
 
202
        branch1_tree = self.make_branch_and_tree('branch1')
 
203
        self.build_tree_contents([('branch1/file1', 'original line\n')])
 
204
        branch1_tree.add('file1')
 
205
        branch1_tree.commit(message='first commit')
 
206
        self.build_tree_contents([('branch1/file1', 'repo line\n')])
 
207
        branch1_tree.commit(message='second commit')
 
208
        return branch1_tree
205
209
 
206
210
    def test_diff_to_working_tree(self):
207
211
        self.example_branch2()
208
 
        
209
 
        print >> open('branch1/file1', 'wb'), 'new line'
210
 
        output = self.run_bzr('diff -r 1.. branch1',
211
 
                              retcode=1)
 
212
        self.build_tree_contents([('branch1/file1', 'new line')])
 
213
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
212
214
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
213
215
 
214
216
    def test_diff_across_rename(self):
215
217
        """The working tree path should always be considered for diffing"""
216
 
        self.make_example_branch()
 
218
        tree = self.make_example_branch()
217
219
        self.run_bzr('diff -r 0..1 hello', retcode=1)
218
 
        wt = workingtree.WorkingTree.open_containing('.')[0]
219
 
        wt.rename_one('hello', 'hello1')
 
220
        tree.rename_one('hello', 'hello1')
220
221
        self.run_bzr('diff hello1', retcode=1)
221
222
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
222
223
 
224
225
class TestCheckoutDiff(TestDiff):
225
226
 
226
227
    def make_example_branch(self):
227
 
        super(TestCheckoutDiff, self).make_example_branch()
228
 
        self.run_bzr('checkout . checkout')
 
228
        tree = super(TestCheckoutDiff, self).make_example_branch()
 
229
        tree = tree.branch.create_checkout('checkout')
229
230
        os.chdir('checkout')
 
231
        return tree
230
232
 
231
233
    def example_branch2(self):
232
 
        super(TestCheckoutDiff, self).example_branch2()
 
234
        tree = super(TestCheckoutDiff, self).example_branch2()
233
235
        os.mkdir('checkouts')
234
 
        self.run_bzr('checkout branch1 checkouts/branch1')
 
236
        tree = tree.branch.create_checkout('checkouts/branch1')
235
237
        os.chdir('checkouts')
 
238
        return tree
236
239
 
237
240
    def example_branches(self):
238
 
        super(TestCheckoutDiff, self).example_branches()
 
241
        branch1_tree, branch2_tree = super(TestCheckoutDiff, self).example_branches()
239
242
        os.mkdir('checkouts')
240
 
        self.run_bzr('checkout branch1 checkouts/branch1')
241
 
        self.run_bzr('checkout branch2 checkouts/branch2')
 
243
        branch1_tree = branch1_tree.branch.create_checkout('checkouts/branch1')
 
244
        branch2_tree = branch2_tree.branch.create_checkout('checkouts/branch2')
242
245
        os.chdir('checkouts')
 
246
        return branch1_tree, branch2_tree
243
247
 
244
248
 
245
249
class TestDiffLabels(DiffBase):
246
250
 
247
251
    def test_diff_label_removed(self):
248
 
        super(TestDiffLabels, self).make_example_branch()
249
 
        self.run_bzr('remove hello')
 
252
        tree = super(TestDiffLabels, self).make_example_branch()
 
253
        tree.remove('hello', keep_files=False)
250
254
        diff = self.run_bzr('diff', retcode=1)
251
255
        self.assertTrue("=== removed file 'hello'" in diff[0])
252
256
 
253
257
    def test_diff_label_added(self):
254
 
        super(TestDiffLabels, self).make_example_branch()
255
 
        file('barbar', 'wt').write('barbar')
256
 
        self.run_bzr('add barbar')
 
258
        tree = super(TestDiffLabels, self).make_example_branch()
 
259
        self.build_tree_contents([('barbar', 'barbar')])
 
260
        tree.add('barbar')
257
261
        diff = self.run_bzr('diff', retcode=1)
258
262
        self.assertTrue("=== added file 'barbar'" in diff[0])
259
263
 
260
264
    def test_diff_label_modified(self):
261
265
        super(TestDiffLabels, self).make_example_branch()
262
 
        file('hello', 'wt').write('barbar')
 
266
        self.build_tree_contents([('hello', 'barbar')])
263
267
        diff = self.run_bzr('diff', retcode=1)
264
268
        self.assertTrue("=== modified file 'hello'" in diff[0])
265
269
 
266
270
    def test_diff_label_renamed(self):
267
 
        super(TestDiffLabels, self).make_example_branch()
268
 
        self.run_bzr('rename hello gruezi')
 
271
        tree = super(TestDiffLabels, self).make_example_branch()
 
272
        tree.rename_one('hello', 'gruezi')
269
273
        diff = self.run_bzr('diff', retcode=1)
270
274
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
271
275
 
308
312
    def test_diff_output(self):
309
313
        # check that output doesn't mangle line-endings
310
314
        self.make_example_branch()
311
 
        file('hello', 'wb').write('hello world!\n')
 
315
        self.build_tree_contents([('hello', 'hello world!\n')])
312
316
        output = self.run_bzr_subprocess('diff', retcode=1)[0]
313
317
        self.assert_('\n+hello world!\n' in output)