/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: Andrew Bennetts
  • Date: 2007-12-21 05:52:38 UTC
  • mfrom: (3137 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3138.
  • Revision ID: andrew.bennetts@canonical.com-20071221055238-0wjubfut943uzovf
Merge from bzr.dev

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')
154
156
        return branch1_tree, branch2_tree
155
157
 
156
 
    def test_diff_branches(self):
157
 
        self.example_branches()
158
 
        # should open branch1 and diff against branch2, 
159
 
        out, err = self.run_bzr('diff -r branch:branch2 branch1',
160
 
                                retcode=1)
 
158
    def check_b2_vs_b1(self, cmd):
 
159
        # Compare branch2 vs branch1 using cmd and check the result
 
160
        out, err = self.run_bzr(cmd, retcode=1)
161
161
        self.assertEquals('', err)
162
162
        self.assertEquals("=== modified file 'file'\n"
163
163
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
166
166
                          "-new content\n"
167
167
                          "+contents of branch1/file\n"
168
168
                          "\n", subst_dates(out))
169
 
        out, err = self.run_bzr('diff branch2 branch1',
170
 
                                         retcode=1)
 
169
 
 
170
    def check_b1_vs_b2(self, cmd):
 
171
        # Compare branch1 vs branch2 using cmd and check the result
 
172
        out, err = self.run_bzr(cmd, retcode=1)
171
173
        self.assertEquals('', err)
172
174
        self.assertEqualDiff("=== modified file 'file'\n"
173
175
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
174
176
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
175
177
                              "@@ -1,1 +1,1 @@\n"
176
 
                              "-new content\n"
177
 
                              "+contents of branch1/file\n"
 
178
                              "-contents of branch1/file\n"
 
179
                              "+new content\n"
178
180
                              "\n", subst_dates(out))
179
181
 
 
182
    def check_no_diffs(self, cmd):
 
183
        # Check that running cmd returns an empty diff
 
184
        out, err = self.run_bzr(cmd, retcode=0)
 
185
        self.assertEquals('', err)
 
186
        self.assertEquals('', out)
 
187
 
 
188
    def test_diff_branches(self):
 
189
        self.example_branches()
 
190
        # should open branch1 and diff against branch2, 
 
191
        self.check_b2_vs_b1('diff -r branch:branch2 branch1')
 
192
        # Compare two working trees using various syntax forms
 
193
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
 
194
        self.check_b2_vs_b1('diff --old branch2 branch1')
 
195
        self.check_b2_vs_b1('diff branch2 --new branch1')
 
196
        # Test with a selected file that was changed
 
197
        self.check_b2_vs_b1('diff --old branch2 --new branch1 file')
 
198
        self.check_b2_vs_b1('diff --old branch2 branch1/file')
 
199
        self.check_b2_vs_b1('diff branch2/file --new branch1')
 
200
        # Test with a selected file that was not changed
 
201
        self.check_no_diffs('diff --old branch2 --new branch1 file2')
 
202
        self.check_no_diffs('diff --old branch2 branch1/file2')
 
203
        self.check_no_diffs('diff branch2/file2 --new branch1')
 
204
 
 
205
    def test_diff_branches_no_working_trees(self):
 
206
        branch1_tree, branch2_tree = self.example_branches()
 
207
        # Compare a working tree to a branch without a WT
 
208
        dir1 = branch1_tree.bzrdir
 
209
        dir1.destroy_workingtree()
 
210
        self.assertFalse(dir1.has_workingtree())
 
211
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
 
212
        self.check_b2_vs_b1('diff --old branch2 branch1')
 
213
        self.check_b2_vs_b1('diff branch2 --new branch1')
 
214
        # Compare a branch without a WT to one with a WT
 
215
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
 
216
        self.check_b1_vs_b2('diff --old branch1 branch2')
 
217
        self.check_b1_vs_b2('diff branch1 --new branch2')
 
218
        # Compare a branch with a WT against another without a WT
 
219
        dir2 = branch2_tree.bzrdir
 
220
        dir2.destroy_workingtree()
 
221
        self.assertFalse(dir2.has_workingtree())
 
222
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
 
223
        self.check_b1_vs_b2('diff --old branch1 branch2')
 
224
        self.check_b1_vs_b2('diff branch1 --new branch2')
 
225
 
180
226
    def test_diff_revno_branches(self):
181
227
        self.example_branches()
182
228
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
221
267
        self.run_bzr('diff hello1', retcode=1)
222
268
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
223
269
 
 
270
    def test_diff_to_branch_no_working_tree(self):
 
271
        branch1_tree = self.example_branch2()
 
272
        dir1 = branch1_tree.bzrdir
 
273
        dir1.destroy_workingtree()
 
274
        self.assertFalse(dir1.has_workingtree())
 
275
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
 
276
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
 
277
 
224
278
 
225
279
class TestCheckoutDiff(TestDiff):
226
280