~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: 2009-09-09 11:43:10 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909114310-glw7tv76i5gnx9pt
put rules back in Makefile supporting plain-style docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
"""Black-box tests for bzr diff.
126
126
        # Get an error from a file that does not exist at all
127
127
        # (Malone #3619)
128
128
        self.make_example_branch()
129
 
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
130
 
        self.assertContainsRe(err, 'not versioned.*does-not-exist')
 
129
        out, err = self.run_bzr('diff does-not-exist', retcode=3,
 
130
            error_regexes=('not versioned.*does-not-exist',))
131
131
 
132
132
    def test_diff_illegal_revision_specifiers(self):
133
 
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
134
 
        self.assertContainsRe(err, 'one or two revision specifiers')
 
133
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3,
 
134
            error_regexes=('one or two revision specifiers',))
 
135
 
 
136
    def test_diff_nonexistent_revision(self):
 
137
        out, err = self.run_bzr('diff -r 123', retcode=3,
 
138
            error_regexes=("Requested revision: '123' does not "
 
139
                "exist in branch:",))
 
140
 
 
141
    def test_diff_nonexistent_dotted_revision(self):
 
142
        out, err = self.run_bzr('diff -r 1.1', retcode=3)
 
143
        self.assertContainsRe(err,
 
144
            "Requested revision: '1.1' does not exist in branch:")
 
145
 
 
146
    def test_diff_nonexistent_dotted_revision_change(self):
 
147
        out, err = self.run_bzr('diff -c 1.1', retcode=3)
 
148
        self.assertContainsRe(err,
 
149
            "Requested revision: '1.1' does not exist in branch:")
135
150
 
136
151
    def test_diff_unversioned(self):
137
152
        # Get an error when diffing a non-versioned file.
146
161
    def example_branches(self):
147
162
        branch1_tree = self.make_branch_and_tree('branch1')
148
163
        self.build_tree(['branch1/file'], line_endings='binary')
 
164
        self.build_tree(['branch1/file2'], line_endings='binary')
149
165
        branch1_tree.add('file')
150
 
        branch1_tree.commit(message='add file')
 
166
        branch1_tree.add('file2')
 
167
        branch1_tree.commit(message='add file and file2')
151
168
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
152
169
        self.build_tree_contents([('branch2/file', 'new content\n')])
153
170
        branch2_tree.commit(message='update file')
154
171
        return branch1_tree, branch2_tree
155
172
 
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)
 
173
    def check_b2_vs_b1(self, cmd):
 
174
        # Compare branch2 vs branch1 using cmd and check the result
 
175
        out, err = self.run_bzr(cmd, retcode=1)
161
176
        self.assertEquals('', err)
162
177
        self.assertEquals("=== modified file 'file'\n"
163
178
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
166
181
                          "-new content\n"
167
182
                          "+contents of branch1/file\n"
168
183
                          "\n", subst_dates(out))
169
 
        out, err = self.run_bzr('diff branch2 branch1',
170
 
                                         retcode=1)
 
184
 
 
185
    def check_b1_vs_b2(self, cmd):
 
186
        # Compare branch1 vs branch2 using cmd and check the result
 
187
        out, err = self.run_bzr(cmd, retcode=1)
171
188
        self.assertEquals('', err)
172
189
        self.assertEqualDiff("=== modified file 'file'\n"
173
190
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
174
191
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
175
192
                              "@@ -1,1 +1,1 @@\n"
176
 
                              "-new content\n"
177
 
                              "+contents of branch1/file\n"
 
193
                              "-contents of branch1/file\n"
 
194
                              "+new content\n"
178
195
                              "\n", subst_dates(out))
179
196
 
 
197
    def check_no_diffs(self, cmd):
 
198
        # Check that running cmd returns an empty diff
 
199
        out, err = self.run_bzr(cmd, retcode=0)
 
200
        self.assertEquals('', err)
 
201
        self.assertEquals('', out)
 
202
 
 
203
    def test_diff_branches(self):
 
204
        self.example_branches()
 
205
        # should open branch1 and diff against branch2,
 
206
        self.check_b2_vs_b1('diff -r branch:branch2 branch1')
 
207
        # Compare two working trees using various syntax forms
 
208
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
 
209
        self.check_b2_vs_b1('diff --old branch2 branch1')
 
210
        self.check_b2_vs_b1('diff branch2 --new branch1')
 
211
        # Test with a selected file that was changed
 
212
        self.check_b2_vs_b1('diff --old branch2 --new branch1 file')
 
213
        self.check_b2_vs_b1('diff --old branch2 branch1/file')
 
214
        self.check_b2_vs_b1('diff branch2/file --new branch1')
 
215
        # Test with a selected file that was not changed
 
216
        self.check_no_diffs('diff --old branch2 --new branch1 file2')
 
217
        self.check_no_diffs('diff --old branch2 branch1/file2')
 
218
        self.check_no_diffs('diff branch2/file2 --new branch1')
 
219
 
 
220
    def test_diff_branches_no_working_trees(self):
 
221
        branch1_tree, branch2_tree = self.example_branches()
 
222
        # Compare a working tree to a branch without a WT
 
223
        dir1 = branch1_tree.bzrdir
 
224
        dir1.destroy_workingtree()
 
225
        self.assertFalse(dir1.has_workingtree())
 
226
        self.check_b2_vs_b1('diff --old branch2 --new branch1')
 
227
        self.check_b2_vs_b1('diff --old branch2 branch1')
 
228
        self.check_b2_vs_b1('diff branch2 --new branch1')
 
229
        # Compare a branch without a WT to one with a WT
 
230
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
 
231
        self.check_b1_vs_b2('diff --old branch1 branch2')
 
232
        self.check_b1_vs_b2('diff branch1 --new branch2')
 
233
        # Compare a branch with a WT against another without a WT
 
234
        dir2 = branch2_tree.bzrdir
 
235
        dir2.destroy_workingtree()
 
236
        self.assertFalse(dir2.has_workingtree())
 
237
        self.check_b1_vs_b2('diff --old branch1 --new branch2')
 
238
        self.check_b1_vs_b2('diff --old branch1 branch2')
 
239
        self.check_b1_vs_b2('diff branch1 --new branch2')
 
240
 
180
241
    def test_diff_revno_branches(self):
181
242
        self.example_branches()
182
243
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
213
274
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
214
275
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
215
276
 
 
277
    def test_diff_to_working_tree_in_subdir(self):
 
278
        self.example_branch2()
 
279
        self.build_tree_contents([('branch1/file1', 'new line')])
 
280
        os.mkdir('branch1/dir1')
 
281
        os.chdir('branch1/dir1')
 
282
        output = self.run_bzr('diff -r 1..', retcode=1)
 
283
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
 
284
 
216
285
    def test_diff_across_rename(self):
217
286
        """The working tree path should always be considered for diffing"""
218
287
        tree = self.make_example_branch()
221
290
        self.run_bzr('diff hello1', retcode=1)
222
291
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
223
292
 
 
293
    def test_diff_to_branch_no_working_tree(self):
 
294
        branch1_tree = self.example_branch2()
 
295
        dir1 = branch1_tree.bzrdir
 
296
        dir1.destroy_workingtree()
 
297
        self.assertFalse(dir1.has_workingtree())
 
298
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
 
299
        self.assertContainsRe(output[0], '\n\\-original line\n\\+repo line\n')
 
300
 
224
301
 
225
302
class TestCheckoutDiff(TestDiff):
226
303
 
283
360
        # subprocess.py that we had to workaround).
284
361
        # However, if 'diff' may not be available
285
362
        self.make_example_branch()
286
 
        orig_progress = os.environ.get('BZR_PROGRESS_BAR')
287
 
        try:
288
 
            os.environ['BZR_PROGRESS_BAR'] = 'none'
289
 
            out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
290
 
                                               universal_newlines=True,
291
 
                                               retcode=None)
292
 
        finally:
293
 
            if orig_progress is None:
294
 
                del os.environ['BZR_PROGRESS_BAR']
295
 
            else:
296
 
                os.environ['BZR_PROGRESS_BAR'] = orig_progress
297
 
            
 
363
        # this will be automatically restored by the base bzr test class
 
364
        os.environ['BZR_PROGRESS_BAR'] = 'none'
 
365
        out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
 
366
                                           universal_newlines=True,
 
367
                                           retcode=None)
298
368
        if 'Diff is not installed on this machine' in err:
299
369
            raise TestSkipped("No external 'diff' is available")
300
370
        self.assertEqual('', err)