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
34
36
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
35
from bzrlib.branch import Branch
37
from bzrlib.selftest.HTTPTestUtil import TestCaseWithWebserver
38
40
class ExternalBase(TestCaseInTempDir):
303
318
print >> file('sub/a.txt', 'wb'), "hello"
319
print >> file('b.txt', 'wb'), "hello"
320
print >> file('sub/c.txt', 'wb'), "hello"
304
321
self.runbzr('init')
305
322
self.runbzr('add')
306
323
self.runbzr(('commit', '-m', 'added a'))
307
324
self.runbzr('branch . ../b')
308
325
print >> file('sub/a.txt', 'ab'), "there"
326
print >> file('b.txt', 'ab'), "there"
327
print >> file('sub/c.txt', 'ab'), "there"
309
328
self.runbzr(('commit', '-m', 'Added there'))
310
329
os.unlink('sub/a.txt')
330
os.unlink('sub/c.txt')
312
333
self.runbzr(('commit', '-m', 'Removed a.txt'))
314
335
print >> file('sub/a.txt', 'ab'), "something"
336
print >> file('b.txt', 'ab'), "something"
337
print >> file('sub/c.txt', 'ab'), "something"
315
338
self.runbzr(('commit', '-m', 'Modified a.txt'))
316
339
self.runbzr('merge ../a/')
317
340
assert os.path.exists('sub/a.txt.THIS')
318
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')
320
347
def test_pull(self):
321
348
"""Pull changes from one branch to another."""
364
393
self.runbzr('commit -m blah8 --unchanged')
365
394
self.runbzr('pull ../b')
366
395
self.runbzr('pull ../b')
397
def test_locations(self):
398
"""Using and remembering different locations"""
402
self.runbzr('commit -m unchanged --unchanged')
403
self.runbzr('pull', retcode=1)
404
self.runbzr('merge', retcode=1)
405
self.runbzr('branch . ../b')
408
self.runbzr('branch . ../c')
409
self.runbzr('pull ../c')
412
self.runbzr('pull ../b')
414
self.runbzr('pull ../c')
415
self.runbzr('branch ../c ../d')
416
shutil.rmtree('../c')
421
self.runbzr('pull', retcode=1)
422
self.runbzr('pull ../a --remember')
368
425
def test_add_reports(self):
369
426
"""add command prints the names of added files."""
384
441
self.assertEquals(out, '')
385
442
err.index('unknown command')
444
def test_conflicts(self):
445
"""Handling of merge conflicts"""
448
file('hello', 'wb').write("hi world")
449
file('answer', 'wb').write("42")
452
self.runbzr('commit -m base')
453
self.runbzr('branch . ../other')
454
self.runbzr('branch . ../this')
456
file('hello', 'wb').write("Hello.")
457
file('answer', 'wb').write("Is anyone there?")
458
self.runbzr('commit -m other')
460
file('hello', 'wb').write("Hello, world")
461
self.runbzr('mv answer question')
462
file('question', 'wb').write("What do you get when you multiply six"
464
self.runbzr('commit -m this')
465
self.runbzr('merge ../other')
466
result = self.runbzr('conflicts', backtick=1)
467
self.assertEquals(result, "hello\nquestion\n")
468
result = self.runbzr('status', backtick=1)
469
assert "conflicts:\n hello\n question\n" in result, result
470
self.runbzr('resolve hello')
471
result = self.runbzr('conflicts', backtick=1)
472
self.assertEquals(result, "question\n")
473
self.runbzr('commit -m conflicts', retcode=1)
474
self.runbzr('resolve --all')
475
result = self.runbzr('conflicts', backtick=1)
476
self.runbzr('commit -m conflicts')
477
self.assertEquals(result, "")
479
def listdir_sorted(dir):
389
485
class OldTests(ExternalBase):
660
os.symlink("NOWHERE1", "link1")
662
assert self.capture('unknowns') == ''
663
runbzr(['commit', '-m', '1: added symlink link1'])
667
assert self.capture('unknowns') == ''
668
os.symlink("NOWHERE2", "d1/link2")
669
assert self.capture('unknowns') == 'd1/link2\n'
670
# is d1/link2 found when adding d1
672
assert self.capture('unknowns') == ''
673
os.symlink("NOWHERE3", "d1/link3")
674
assert self.capture('unknowns') == 'd1/link3\n'
675
runbzr(['commit', '-m', '2: added dir, symlink'])
677
runbzr('rename d1 d2')
678
runbzr('move d2/link2 .')
679
runbzr('move link1 d2')
680
assert os.readlink("./link2") == "NOWHERE2"
681
assert os.readlink("d2/link1") == "NOWHERE1"
682
runbzr('add d2/link3')
684
runbzr(['commit', '-m', '3: rename of dir, move symlinks, add link3'])
687
os.symlink("TARGET 2", "link2")
688
os.unlink("d2/link1")
689
os.symlink("TARGET 1", "d2/link1")
691
assert self.capture("relpath d2/link1") == "d2/link1\n"
692
runbzr(['commit', '-m', '4: retarget of two links'])
694
runbzr('remove d2/link1')
695
assert self.capture('unknowns') == 'd2/link1\n'
696
runbzr(['commit', '-m', '5: remove d2/link1'])
700
runbzr('rename d2/link3 d1/link3new')
701
assert self.capture('unknowns') == 'd2/link1\n'
702
runbzr(['commit', '-m', '6: remove d2/link1, move/rename link3'])
706
runbzr(['export', '-r', '1', 'exp1.tmp'])
708
assert listdir_sorted(".") == [ "link1" ]
709
assert os.readlink("link1") == "NOWHERE1"
712
runbzr(['export', '-r', '2', 'exp2.tmp'])
714
assert listdir_sorted(".") == [ "d1", "link1" ]
717
runbzr(['export', '-r', '3', 'exp3.tmp'])
719
assert listdir_sorted(".") == [ "d2", "link2" ]
720
assert listdir_sorted("d2") == [ "link1", "link3" ]
721
assert os.readlink("d2/link1") == "NOWHERE1"
722
assert os.readlink("link2") == "NOWHERE2"
725
runbzr(['export', '-r', '4', 'exp4.tmp'])
727
assert listdir_sorted(".") == [ "d2", "link2" ]
728
assert os.readlink("d2/link1") == "TARGET 1"
729
assert os.readlink("link2") == "TARGET 2"
730
assert listdir_sorted("d2") == [ "link1", "link3" ]
733
runbzr(['export', '-r', '5', 'exp5.tmp'])
735
assert listdir_sorted(".") == [ "d2", "link2" ]
736
assert os.path.islink("link2")
737
assert listdir_sorted("d2")== [ "link3" ]
740
runbzr(['export', '-r', '6', 'exp6.tmp'])
742
assert listdir_sorted(".") == [ "d1", "d2", "link2" ]
743
assert listdir_sorted("d1") == [ "link3new" ]
744
assert listdir_sorted("d2") == []
745
assert os.readlink("d1/link3new") == "NOWHERE3"
748
progress("skipping symlink tests")
751
class HttpTests(TestCaseWithWebserver):
752
"""Test bzr ui commands against remote branches."""
754
def test_branch(self):
756
branch = Branch.initialize('from')
757
branch.commit('empty commit for nonsense', allow_pointless=True)
758
url = self.get_remote_url('from')
759
self.run_bzr('branch', url, 'to')
760
branch = Branch.open('to')
761
self.assertEqual(1, len(branch.revision_history()))