~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Fix encoding of 'already versioned' error

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
    def test_diff(self):
54
54
        self.make_example_branch()
55
55
        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]
 
56
        self.runbzr('commit -m fixing hello')
 
57
        output = self.runbzr('diff -r 2..3', backtick=1, retcode=1)
58
58
        self.assert_('\n+hello world!' in output)
59
 
        output = self.run_bzr('diff -r last:3..last:1',
60
 
                retcode=1)[0]
 
59
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
61
60
        self.assert_('\n+baz' in output)
62
 
        self.build_tree(['moo'])
63
 
        self.run_bzr('add moo')
 
61
        file('moo', 'wb').write('moo')
 
62
        self.runbzr('add moo')
64
63
        os.unlink('moo')
65
 
        self.run_bzr('diff')
 
64
        self.runbzr('diff')
66
65
 
67
66
    def test_diff_prefix(self):
68
67
        """diff --prefix appends to filenames in output"""
69
68
        self.make_example_branch()
70
69
        file('hello', 'wb').write('hello world!\n')
71
 
        out, err = self.run_bzr('diff --prefix old/:new/', retcode=1)
 
70
        out, err = self.runbzr('diff --prefix old/:new/', retcode=1)
72
71
        self.assertEquals(err, '')
73
72
        self.assertEqualDiff(subst_dates(out), '''\
74
73
=== modified file 'hello'
82
81
 
83
82
    def test_diff_illegal_prefix_value(self):
84
83
        # There was an error in error reporting for this option
85
 
        out, err = self.run_bzr('diff --prefix old/', retcode=3)
 
84
        out, err = self.runbzr('diff --prefix old/', retcode=3)
86
85
        self.assertContainsRe(err,
87
86
            '--prefix expects two values separated by a colon')
88
87
 
90
89
        """diff -p1 produces lkml-style diffs"""
91
90
        self.make_example_branch()
92
91
        file('hello', 'wb').write('hello world!\n')
93
 
        out, err = self.run_bzr('diff -p1', retcode=1)
 
92
        out, err = self.runbzr('diff -p1', retcode=1)
94
93
        self.assertEquals(err, '')
95
94
        self.assertEqualDiff(subst_dates(out), '''\
96
95
=== modified file 'hello'
106
105
        """diff -p0 produces diffs with no prefix"""
107
106
        self.make_example_branch()
108
107
        file('hello', 'wb').write('hello world!\n')
109
 
        out, err = self.run_bzr('diff -p0', retcode=1)
 
108
        out, err = self.runbzr('diff -p0', retcode=1)
110
109
        self.assertEquals(err, '')
111
110
        self.assertEqualDiff(subst_dates(out), '''\
112
111
=== modified file 'hello'
122
121
        # Get an error from a file that does not exist at all
123
122
        # (Malone #3619)
124
123
        self.make_example_branch()
125
 
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
 
124
        out, err = self.runbzr('diff does-not-exist', retcode=3)
126
125
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
127
126
 
128
127
    def test_diff_illegal_revision_specifiers(self):
129
 
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
 
128
        out, err = self.runbzr('diff -r 1..23..123', retcode=3)
130
129
        self.assertContainsRe(err, 'one or two revision specifiers')
131
130
 
132
131
    def test_diff_unversioned(self):
134
133
        # (Malone #3619)
135
134
        self.make_example_branch()
136
135
        self.build_tree(['unversioned-file'])
137
 
        out, err = self.run_bzr('diff unversioned-file', retcode=3)
 
136
        out, err = self.runbzr('diff unversioned-file', retcode=3)
138
137
        self.assertContainsRe(err, 'not versioned.*unversioned-file')
139
138
 
140
139
    # TODO: What should diff say for a file deleted in working tree?
141
140
 
142
141
    def example_branches(self):
143
142
        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'])
 
143
        self.capture('init branch1')
 
144
        self.capture('add branch1/file')
 
145
        self.run_bzr_captured(['commit', '-m', 'add file', 'branch1'])
 
146
        self.capture('branch branch1 branch2')
 
147
        print >> open('branch2/file', 'wb'), 'new content'
 
148
        self.run_bzr_captured(['commit', '-m', 'update file', 'branch2'])
150
149
 
151
150
    def test_diff_branches(self):
152
151
        self.example_branches()
153
152
        # should open branch1 and diff against branch2, 
154
 
        out, err = self.run_bzr('diff -r branch:branch2 branch1',
155
 
                                retcode=1)
 
153
        out, err = self.run_bzr_captured(['diff', '-r', 'branch:branch2', 
 
154
                                          'branch1'],
 
155
                                         retcode=1)
156
156
        self.assertEquals('', err)
157
157
        self.assertEquals("=== modified file 'file'\n"
158
158
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
161
161
                          "-new content\n"
162
162
                          "+contents of branch1/file\n"
163
163
                          "\n", subst_dates(out))
164
 
        out, err = self.run_bzr('diff branch2 branch1',
 
164
        out, err = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
165
165
                                         retcode=1)
166
166
        self.assertEquals('', err)
167
167
        self.assertEqualDiff("=== modified file 'file'\n"
175
175
    def test_diff_revno_branches(self):
176
176
        self.example_branches()
177
177
        print >> open('branch2/file', 'wb'), 'even newer content'
178
 
        self.run_bzr(['commit', '-m',
179
 
                      'update file once more', 'branch2'])
 
178
        self.run_bzr_captured(['commit', '-m', 
 
179
                               'update file once more', 'branch2'])
180
180
 
181
 
        out, err = self.run_bzr('diff -r revno:1:branch2..revno:1:branch1',
182
 
                                )
 
181
        out, err = self.run_bzr_captured(['diff', '-r',
 
182
                                          'revno:1:branch2..revno:1:branch1'],
 
183
                                         retcode=0)
183
184
        self.assertEquals('', err)
184
185
        self.assertEquals('', out)
185
 
        out, err = self.run_bzr('diff -r revno:2:branch2..revno:1:branch1',
186
 
                                retcode=1)
 
186
        out, err = self.run_bzr_captured(['diff', '-r', 
 
187
                                          'revno:2:branch2..revno:1:branch1'],
 
188
                                         retcode=1)
187
189
        self.assertEquals('', err)
188
190
        self.assertEqualDiff("=== modified file 'file'\n"
189
191
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
195
197
 
196
198
    def example_branch2(self):
197
199
        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
        self.capture('init branch1')
 
201
        self.capture('add branch1/file1')
200
202
        print >> open('branch1/file1', 'wb'), 'original line'
201
 
        self.run_bzr(['commit', '-m', 'first commit', 'branch1'])
 
203
        self.run_bzr_captured(['commit', '-m', 'first commit', 'branch1'])
202
204
        
203
205
        print >> open('branch1/file1', 'wb'), 'repo line'
204
 
        self.run_bzr(['commit', '-m', 'second commit', 'branch1'])
 
206
        self.run_bzr_captured(['commit', '-m', 'second commit', 'branch1'])
205
207
 
206
208
    def test_diff_to_working_tree(self):
207
209
        self.example_branch2()
208
210
        
209
211
        print >> open('branch1/file1', 'wb'), 'new line'
210
 
        output = self.run_bzr('diff -r 1.. branch1',
211
 
                              retcode=1)
 
212
        output = self.run_bzr_captured(['diff', '-r', '1..', 'branch1'],
 
213
                                       retcode=1)
212
214
        self.assertTrue('\n-original line\n+new line\n' in output[0])
213
215
 
214
216
    def test_diff_across_rename(self):
215
217
        """The working tree path should always be considered for diffing"""
216
218
        self.make_example_branch()
217
 
        self.run_bzr('diff -r 0..1 hello', retcode=1)
 
219
        self.run_bzr('diff', '-r', '0..1', 'hello', retcode=1)
218
220
        wt = workingtree.WorkingTree.open_containing('.')[0]
219
221
        wt.rename_one('hello', 'hello1')
220
 
        self.run_bzr('diff hello1', retcode=1)
221
 
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
 
222
        self.run_bzr('diff', 'hello1', retcode=1)
 
223
        self.run_bzr('diff', '-r', '0..1', 'hello1', retcode=1)
222
224
 
223
225
 
224
226
class TestCheckoutDiff(TestDiff):
225
227
 
226
228
    def make_example_branch(self):
227
229
        super(TestCheckoutDiff, self).make_example_branch()
228
 
        self.run_bzr('checkout . checkout')
 
230
        self.runbzr('checkout . checkout')
229
231
        os.chdir('checkout')
230
232
 
231
233
    def example_branch2(self):
232
234
        super(TestCheckoutDiff, self).example_branch2()
233
235
        os.mkdir('checkouts')
234
 
        self.run_bzr('checkout branch1 checkouts/branch1')
 
236
        self.runbzr('checkout branch1 checkouts/branch1')
235
237
        os.chdir('checkouts')
236
238
 
237
239
    def example_branches(self):
238
240
        super(TestCheckoutDiff, self).example_branches()
239
241
        os.mkdir('checkouts')
240
 
        self.run_bzr('checkout branch1 checkouts/branch1')
241
 
        self.run_bzr('checkout branch2 checkouts/branch2')
 
242
        self.runbzr('checkout branch1 checkouts/branch1')
 
243
        self.runbzr('checkout branch2 checkouts/branch2')
242
244
        os.chdir('checkouts')
243
245
 
244
246
 
246
248
 
247
249
    def test_diff_label_removed(self):
248
250
        super(TestDiffLabels, self).make_example_branch()
249
 
        self.run_bzr('remove hello')
250
 
        diff = self.run_bzr('diff', retcode=1)
 
251
        self.runbzr('remove hello')
 
252
        diff = self.run_bzr_captured(['diff'], retcode=1)
251
253
        self.assertTrue("=== removed file 'hello'" in diff[0])
252
254
 
253
255
    def test_diff_label_added(self):
254
256
        super(TestDiffLabels, self).make_example_branch()
255
257
        file('barbar', 'wt').write('barbar')
256
 
        self.run_bzr('add barbar')
257
 
        diff = self.run_bzr('diff', retcode=1)
 
258
        self.runbzr('add barbar')
 
259
        diff = self.run_bzr_captured(['diff'], retcode=1)
258
260
        self.assertTrue("=== added file 'barbar'" in diff[0])
259
261
 
260
262
    def test_diff_label_modified(self):
261
263
        super(TestDiffLabels, self).make_example_branch()
262
264
        file('hello', 'wt').write('barbar')
263
 
        diff = self.run_bzr('diff', retcode=1)
 
265
        diff = self.run_bzr_captured(['diff'], retcode=1)
264
266
        self.assertTrue("=== modified file 'hello'" in diff[0])
265
267
 
266
268
    def test_diff_label_renamed(self):
267
269
        super(TestDiffLabels, self).make_example_branch()
268
 
        self.run_bzr('rename hello gruezi')
269
 
        diff = self.run_bzr('diff', retcode=1)
 
270
        self.runbzr('rename hello gruezi')
 
271
        diff = self.run_bzr_captured(['diff'], retcode=1)
270
272
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
271
273
 
272
274