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
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
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',))
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',))
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:")
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
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',
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"
167
182
"+contents of branch1/file\n"
168
183
"\n", subst_dates(out))
169
out, err = self.run_bzr('diff branch2 branch1',
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"
177
"+contents of branch1/file\n"
193
"-contents of branch1/file\n"
178
195
"\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')
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')
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')
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)
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')
225
302
class TestCheckoutDiff(TestDiff):
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')
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
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,
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)