~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-10-09 20:32:29 UTC
  • mto: (2903.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2904.
  • Revision ID: v.ladeuil+lp@free.fr-20071009203229-5k200m1g7mf4jf9l
Fix 149019 by using a proper line number when reporting errors.

* bzrlib/util/configobj/configobj.py:
(ConfigObj._handle_error): Trivial fix. Since cur_index is
0-based, line number was off by one.

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
 
            error_regexes=('not versioned.*does-not-exist',))
 
129
        out, err = self.run_bzr('diff does-not-exist', retcode=3)
 
130
        self.assertContainsRe(err, '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
 
            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:")
 
133
        out, err = self.run_bzr('diff -r 1..23..123', retcode=3)
 
134
        self.assertContainsRe(err, 'one or two revision specifiers')
150
135
 
151
136
    def test_diff_unversioned(self):
152
137
        # Get an error when diffing a non-versioned file.
161
146
    def example_branches(self):
162
147
        branch1_tree = self.make_branch_and_tree('branch1')
163
148
        self.build_tree(['branch1/file'], line_endings='binary')
164
 
        self.build_tree(['branch1/file2'], line_endings='binary')
165
149
        branch1_tree.add('file')
166
 
        branch1_tree.add('file2')
167
 
        branch1_tree.commit(message='add file and file2')
 
150
        branch1_tree.commit(message='add file')
168
151
        branch2_tree = branch1_tree.bzrdir.sprout('branch2').open_workingtree()
169
152
        self.build_tree_contents([('branch2/file', 'new content\n')])
170
153
        branch2_tree.commit(message='update file')
171
154
        return branch1_tree, branch2_tree
172
155
 
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)
 
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)
176
161
        self.assertEquals('', err)
177
162
        self.assertEquals("=== modified file 'file'\n"
178
163
                          "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
181
166
                          "-new content\n"
182
167
                          "+contents of branch1/file\n"
183
168
                          "\n", subst_dates(out))
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)
 
169
        out, err = self.run_bzr('diff branch2 branch1',
 
170
                                         retcode=1)
188
171
        self.assertEquals('', err)
189
172
        self.assertEqualDiff("=== modified file 'file'\n"
190
173
                              "--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
191
174
                              "+++ file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
192
175
                              "@@ -1,1 +1,1 @@\n"
193
 
                              "-contents of branch1/file\n"
194
 
                              "+new content\n"
 
176
                              "-new content\n"
 
177
                              "+contents of branch1/file\n"
195
178
                              "\n", subst_dates(out))
196
179
 
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
 
 
241
180
    def test_diff_revno_branches(self):
242
181
        self.example_branches()
243
182
        branch2_tree = workingtree.WorkingTree.open_containing('branch2')[0]
274
213
        output = self.run_bzr('diff -r 1.. branch1', retcode=1)
275
214
        self.assertContainsRe(output[0], '\n\\-original line\n\\+new line\n')
276
215
 
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
 
 
285
216
    def test_diff_across_rename(self):
286
217
        """The working tree path should always be considered for diffing"""
287
218
        tree = self.make_example_branch()
290
221
        self.run_bzr('diff hello1', retcode=1)
291
222
        self.run_bzr('diff -r 0..1 hello1', retcode=1)
292
223
 
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
 
 
301
224
 
302
225
class TestCheckoutDiff(TestDiff):
303
226
 
360
283
        # subprocess.py that we had to workaround).
361
284
        # However, if 'diff' may not be available
362
285
        self.make_example_branch()
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)
 
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
            
368
298
        if 'Diff is not installed on this machine' in err:
369
299
            raise TestSkipped("No external 'diff' is available")
370
300
        self.assertEqual('', err)