19
19
"""Black-box tests for bzr.
21
21
These check that it behaves properly when it's invoked through the regular
22
command-line interface.
24
This always reinvokes bzr through a new Python interpreter, which is a
25
bit inefficient but arguably tests in a way more representative of how
26
it's normally invoked.
22
command-line interface. This doesn't actually run a new interpreter but
23
rather starts again from the run_bzr function.
29
27
from cStringIO import StringIO
33
from bzrlib.branch import Branch
34
from bzrlib.errors import BzrCommandError
35
from bzrlib.osutils import has_symlinks
33
36
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
34
from bzrlib.branch import Branch
37
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
37
40
class ExternalBase(TestCaseInTempDir):
206
220
test.runbzr('add goodbye')
207
221
test.runbzr('commit -m setup goodbye')
223
def test_export(self):
226
self.example_branch()
227
self.runbzr('export ../latest')
228
self.assertEqual(file('../latest/goodbye', 'rt').read(), 'baz')
229
self.runbzr('export ../first -r 1')
230
assert not os.path.exists('../first/goodbye')
231
self.assertEqual(file('../first/hello', 'rt').read(), 'foo')
232
self.runbzr('export ../first.gz -r 1')
233
self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
234
self.runbzr('export ../first.bz2 -r 1')
235
self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
236
self.runbzr('export ../first.tar -r 1')
237
assert os.path.isfile('../first.tar')
238
from tarfile import TarFile
239
tf = TarFile('../first.tar')
240
assert 'first/hello' in tf.getnames(), tf.getnames()
241
self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
242
self.runbzr('export ../first.tar.gz -r 1')
243
assert os.path.isfile('../first.tar.gz')
244
self.runbzr('export ../first.tbz2 -r 1')
245
assert os.path.isfile('../first.tbz2')
246
self.runbzr('export ../first.tar.bz2 -r 1')
247
assert os.path.isfile('../first.tar.bz2')
248
self.runbzr('export ../first.tar.tbz2 -r 1')
249
assert os.path.isfile('../first.tar.tbz2')
250
from bz2 import BZ2File
251
tf = TarFile('../first.tar.tbz2',
252
fileobj=BZ2File('../first.tar.tbz2', 'r'))
253
assert 'first.tar/hello' in tf.getnames(), tf.getnames()
254
self.assertEqual(tf.extractfile('first.tar/hello').read(), 'foo')
255
self.runbzr('export ../first2.tar -r 1 --root pizza')
256
tf = TarFile('../first2.tar')
257
assert 'pizza/hello' in tf.getnames(), tf.getnames()
209
259
def test_diff(self):
210
260
self.example_branch()
211
261
file('hello', 'wt').write('hello world!')
246
305
# Merging a branch pulls its revision into the tree
247
306
a = Branch.open('.')
248
307
b = Branch.open('../b')
249
a.get_revision_xml(b.last_patch())
308
a.get_revision_xml(b.last_revision())
250
309
self.log('pending merges: %s', a.pending_merges())
251
# assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
252
# % (a.pending_merges(), b.last_patch())
310
# assert a.pending_merges() == [b.last_revision()], "Assertion %s %s" \
311
# % (a.pending_merges(), b.last_revision())
313
def test_merge_with_missing_file(self):
314
"""Merge handles missing file conflicts"""
318
print >> file('sub/a.txt', 'wb'), "hello"
319
print >> file('b.txt', 'wb'), "hello"
320
print >> file('sub/c.txt', 'wb'), "hello"
323
self.runbzr(('commit', '-m', 'added a'))
324
self.runbzr('branch . ../b')
325
print >> file('sub/a.txt', 'ab'), "there"
326
print >> file('b.txt', 'ab'), "there"
327
print >> file('sub/c.txt', 'ab'), "there"
328
self.runbzr(('commit', '-m', 'Added there'))
329
os.unlink('sub/a.txt')
330
os.unlink('sub/c.txt')
333
self.runbzr(('commit', '-m', 'Removed a.txt'))
335
print >> file('sub/a.txt', 'ab'), "something"
336
print >> file('b.txt', 'ab'), "something"
337
print >> file('sub/c.txt', 'ab'), "something"
338
self.runbzr(('commit', '-m', 'Modified a.txt'))
339
self.runbzr('merge ../a/')
340
assert os.path.exists('sub/a.txt.THIS')
341
assert os.path.exists('sub/a.txt.BASE')
343
self.runbzr('merge ../b/')
344
assert os.path.exists('sub/a.txt.OTHER')
345
assert os.path.exists('sub/a.txt.BASE')
254
347
def test_pull(self):
255
348
"""Pull changes from one branch to another."""
283
376
self.runbzr('commit -m blah3 --unchanged')
284
377
self.runbzr('pull ../a', retcode=1)
378
print "DECIDE IF PULL CAN CONVERGE, blackbox.py"
286
381
self.runbzr('merge ../b')
287
382
self.runbzr('commit -m blah4 --unchanged')
288
383
os.chdir('../b/subdir')
289
384
self.runbzr('pull ../../a')
290
385
assert a.revision_history()[-1] == b.revision_history()[-1]
386
self.runbzr('commit -m blah5 --unchanged')
387
self.runbzr('commit -m blah6 --unchanged')
389
self.runbzr('pull ../a')
391
self.runbzr('commit -m blah7 --unchanged')
392
self.runbzr('merge ../b')
393
self.runbzr('commit -m blah8 --unchanged')
394
self.runbzr('pull ../b')
395
self.runbzr('pull ../b')
292
397
def test_add_reports(self):
293
398
"""add command prints the names of added files."""
598
os.symlink("NOWHERE1", "link1")
600
assert self.capture('unknowns') == ''
601
runbzr(['commit', '-m', '1: added symlink link1'])
605
assert self.capture('unknowns') == ''
606
os.symlink("NOWHERE2", "d1/link2")
607
assert self.capture('unknowns') == 'd1/link2\n'
608
# is d1/link2 found when adding d1
610
assert self.capture('unknowns') == ''
611
os.symlink("NOWHERE3", "d1/link3")
612
assert self.capture('unknowns') == 'd1/link3\n'
613
runbzr(['commit', '-m', '2: added dir, symlink'])
615
runbzr('rename d1 d2')
616
runbzr('move d2/link2 .')
617
runbzr('move link1 d2')
618
assert os.readlink("./link2") == "NOWHERE2"
619
assert os.readlink("d2/link1") == "NOWHERE1"
620
runbzr('add d2/link3')
622
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
625
os.symlink("TARGET 2", "link2")
626
os.unlink("d2/link1")
627
os.symlink("TARGET 1", "d2/link1")
629
assert self.capture("relpath d2/link1") == "d2/link1\n"
630
runbzr(['commit', '-m', '4: retarget of two links'])
632
runbzr('remove d2/link1')
633
assert self.capture('unknowns') == 'd2/link1\n'
634
runbzr(['commit', '-m', '5: remove d2/link1'])
638
runbzr('rename d2/link3 d1/link3new')
639
assert self.capture('unknowns') == 'd2/link1\n'
640
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
644
runbzr(['export', '-r', '1', 'exp1.tmp'])
646
assert listdir_sorted(".") == [ "link1" ]
647
assert os.readlink("link1") == "NOWHERE1"
650
runbzr(['export', '-r', '2', 'exp2.tmp'])
652
assert listdir_sorted(".") == [ "d1", "link1" ]
655
runbzr(['export', '-r', '3', 'exp3.tmp'])
657
assert listdir_sorted(".") == [ "d2", "link2" ]
658
assert listdir_sorted("d2") == [ "link1", "link3" ]
659
assert os.readlink("d2/link1") == "NOWHERE1"
660
assert os.readlink("link2") == "NOWHERE2"
663
runbzr(['export', '-r', '4', 'exp4.tmp'])
665
assert listdir_sorted(".") == [ "d2", "link2" ]
666
assert os.readlink("d2/link1") == "TARGET 1"
667
assert os.readlink("link2") == "TARGET 2"
668
assert listdir_sorted("d2") == [ "link1", "link3" ]
671
runbzr(['export', '-r', '5', 'exp5.tmp'])
673
assert listdir_sorted(".") == [ "d2", "link2" ]
674
assert os.path.islink("link2")
675
assert listdir_sorted("d2")== [ "link3" ]
678
runbzr(['export', '-r', '6', 'exp6.tmp'])
680
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
681
assert listdir_sorted("d1") == [ "link3new" ]
682
assert listdir_sorted("d2") == []
683
assert os.readlink("d1/link3new") == "NOWHERE3"
686
progress("skipping symlink tests")
689
class HttpTests(TestCaseWithWebserver):
690
"""Test bzr ui commands against remote branches."""
692
def test_branch(self):
694
branch = Branch.initialize('from')
695
branch.commit('empty commit for nonsense', allow_pointless=True)
696
url = self.get_remote_url('from')
697
self.run_bzr('branch', url, 'to')
698
branch = Branch.open('to')
699
self.assertEqual(1, len(branch.revision_history()))