~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Marius Kruger
  • Date: 2007-06-27 18:48:10 UTC
  • mfrom: (2557 +trunk)
  • mto: (2605.1.1 rm-renamed)
  • mto: This revision was merged to the branch mainline in revision 2609.
  • Revision ID: marius.kruger@enerweb.co.za-20070627184810-4jq1y5f20xafow9w
Merge with bzr.dev

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