~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2007-12-04 05:49:37 UTC
  • mto: (3118.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3119.
  • Revision ID: ian.clatworthy@internode.on.net-20071204054937-6v169ypv0lclbyuj
Improved diff based on feedback from abentley

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
    def example_branches(self):
147
147
        branch1_tree = self.make_branch_and_tree('branch1')
148
148
        self.build_tree(['branch1/file'], line_endings='binary')
 
149
        self.build_tree(['branch1/file2'], line_endings='binary')
149
150
        branch1_tree.add('file')
150
 
        branch1_tree.commit(message='add file')
 
151
        branch1_tree.add('file2')
 
152
        branch1_tree.commit(message='add file and file2')
151
153
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
152
154
        self.build_tree_contents([('branch2/file', 'new content\n')])
153
155
        branch2_tree.commit(message='update file')
166
168
                          "-new content\n"
167
169
                          "+contents of branch1/file\n"
168
170
                          "\n", subst_dates(out))
169
 
        out, err = self.run_bzr('diff branch2 branch1',
170
 
                                         retcode=1)
171
 
        self.assertEquals('', err)
172
 
        self.assertEqualDiff("=== modified file 'file'\n"
173
 
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
174
 
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
175
 
                              "@@ -1,1 +1,1 @@\n"
176
 
                              "-new content\n"
177
 
                              "+contents of branch1/file\n"
 
171
        # Compare two working trees
 
172
        out, err = self.run_bzr('diff --old branch2 --new 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))
 
182
        # Test with a selected file that was changed
 
183
        out, err = self.run_bzr('diff --old branch2 --new branch1 file',
 
184
                                         retcode=1)
 
185
        self.assertEquals('', err)
 
186
        self.assertEqualDiff("=== modified file 'file'\n"
 
187
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
188
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
189
                              "@@ -1,1 +1,1 @@\n"
 
190
                              "-new content\n"
 
191
                              "+contents of branch1/file\n"
 
192
                              "\n", subst_dates(out))
 
193
        # Test with a selected file that was not changed
 
194
        out, err = self.run_bzr('diff --old branch2 --new branch1 file2',
 
195
                                         retcode=0)
 
196
        self.assertEquals('', err)
 
197
        self.assertEquals('', out)
 
198
 
 
199
    def test_diff_branches_no_working_trees(self):
 
200
        branch1_tree, branch2_tree = self.example_branches()
 
201
        # Compare a working tree to a branch without a WT
 
202
        dir1 = branch1_tree.bzrdir
 
203
        dir1.destroy_workingtree()
 
204
        self.assertFalse(dir1.has_workingtree())
 
205
        out, err = self.run_bzr('diff --old branch2 --new branch1',
 
206
                                         retcode=1)
 
207
        self.assertEquals('', err)
 
208
        self.assertEqualDiff("=== modified file 'file'\n"
 
209
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
210
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
211
                              "@@ -1,1 +1,1 @@\n"
 
212
                              "-new content\n"
 
213
                              "+contents of branch1/file\n"
 
214
                              "\n", subst_dates(out))
 
215
        # Compare a branch without a WT to one with a WT
 
216
        out, err = self.run_bzr('diff --old branch1 --new branch2',
 
217
                                         retcode=1)
 
218
        self.assertEquals('', err)
 
219
        self.assertEqualDiff("=== modified file 'file'\n"
 
220
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
221
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
222
                              "@@ -1,1 +1,1 @@\n"
 
223
                              "-contents of branch1/file\n"
 
224
                              "+new content\n"
 
225
                              "\n", subst_dates(out))
 
226
        # Compare a branch with a WT against another without a WT
 
227
        dir2 = branch2_tree.bzrdir
 
228
        dir2.destroy_workingtree()
 
229
        self.assertFalse(dir2.has_workingtree())
 
230
        out, err = self.run_bzr('diff --old branch1 --new branch2',
 
231
                                         retcode=1)
 
232
        self.assertEquals('', err)
 
233
        self.assertEqualDiff("=== modified file 'file'\n"
 
234
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
235
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
 
236
                              "@@ -1,1 +1,1 @@\n"
 
237
                              "-contents of branch1/file\n"
 
238
                              "+new content\n"
178
239
                              "\n", subst_dates(out))
179
240
 
180
241
    def test_diff_revno_branches(self):
221
282
        self.run_bzr('diff hello1', retcode=1)
222
283
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
223
284
 
 
285
    def test_diff_to_branch_no_working_tree(self):
 
286
        branch1_tree = self.example_branch2()
 
287
        dir1 = branch1_tree.bzrdir
 
288
        dir1.destroy_workingtree()
 
289
        self.assertFalse(dir1.has_workingtree())
 
290
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
 
291
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
 
292
 
224
293
 
225
294
class TestCheckoutDiff(TestDiff):
226
295