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
18
18
"""Black-box tests for bzr diff.
126
126
# Get an error from a file that does not exist at all
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')
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',))
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:",))
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:")
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')
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
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',
176
161
self.assertEquals('', err)
177
162
self.assertEquals("=== modified file 'file'\n"
178
163
"--- file\tYYYY-MM-DD HH:MM:SS +ZZZZ\n"
182
167
"+contents of branch1/file\n"
183
168
"\n", subst_dates(out))
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',
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"
177
"+contents of branch1/file\n"
195
178
"\n", subst_dates(out))
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)
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')
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')
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')
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')
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)
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')
302
225
class TestCheckoutDiff(TestDiff):
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,
286
orig_progress = os.environ.get('BZR_PROGRESS_BAR')
288
os.environ['BZR_PROGRESS_BAR'] = 'none'
289
out, err = self.run_bzr_subprocess('diff -r 1 --diff-options -ub',
290
universal_newlines=True,
293
if orig_progress is None:
294
del os.environ['BZR_PROGRESS_BAR']
296
os.environ['BZR_PROGRESS_BAR'] = orig_progress
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)