~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

Merge from mpool.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
 
26
26
 
 
27
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
28
# Note: Please don't add new tests here, it's too big and bulky.  Instead add
 
29
# them into small suites for the particular function that's tested.
 
30
 
 
31
 
27
32
from cStringIO import StringIO
28
33
import os
29
34
import re
67
72
        self.assert_(os.path.exists('subdir1'))
68
73
        self.assert_(os.path.exists('subdir1/.bzr'))
69
74
 
70
 
        self.runbzr('init subdir2/nothere', retcode=2)
 
75
        self.runbzr('init subdir2/nothere', retcode=3)
71
76
        
72
77
        os.mkdir('subdir2')
73
78
        self.runbzr('init subdir2')
74
 
        self.runbzr('init subdir2', retcode=1)
 
79
        self.runbzr('init subdir2', retcode=3)
75
80
 
76
81
        self.runbzr('init subdir2/subsubdir1')
77
82
        self.assert_(os.path.exists('subdir2/subsubdir1/.bzr'))
107
112
        if bzr_email is not None:
108
113
            os.environ['BZREMAIL'] = bzr_email
109
114
 
 
115
    def test_nick_command(self):
 
116
        """bzr nick for viewing, setting nicknames"""
 
117
        os.mkdir('me.dev')
 
118
        os.chdir('me.dev')
 
119
        self.runbzr('init')
 
120
        nick = self.runbzr("nick",backtick=True)
 
121
        self.assertEqual(nick, 'me.dev\n')
 
122
        nick = self.runbzr("nick moo")
 
123
        nick = self.runbzr("nick",backtick=True)
 
124
        self.assertEqual(nick, 'moo\n')
 
125
 
 
126
 
110
127
    def test_invalid_commands(self):
111
 
        self.runbzr("pants", retcode=1)
112
 
        self.runbzr("--pants off", retcode=1)
113
 
        self.runbzr("diff --message foo", retcode=1)
 
128
        self.runbzr("pants", retcode=3)
 
129
        self.runbzr("--pants off", retcode=3)
 
130
        self.runbzr("diff --message foo", retcode=3)
114
131
 
115
132
    def test_empty_commit(self):
116
133
        self.runbzr("init")
117
134
        self.build_tree(['hello.txt'])
118
 
        self.runbzr("commit -m empty", retcode=1)
 
135
        self.runbzr("commit -m empty", retcode=3)
119
136
        self.runbzr("add hello.txt")
120
 
        self.runbzr("commit -m added")
 
137
        self.runbzr("commit -m added")       
121
138
 
122
139
    def test_empty_commit_message(self):
123
140
        self.runbzr("init")
124
141
        file('foo.c', 'wt').write('int main() {}')
125
142
        self.runbzr(['add', 'foo.c'])
126
 
        self.runbzr(["commit", "-m", ""] , retcode=1) 
 
143
        self.runbzr(["commit", "-m", ""] , retcode=3) 
127
144
 
128
145
    def test_remove_deleted(self):
129
146
        self.runbzr("init")
148
165
        self.runbzr(['add', 'branch/foo.c'])
149
166
        self.runbzr(['add', 'branch'])
150
167
        # can't commit files in different trees; sane error
151
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
 
168
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
152
169
        self.runbzr('commit -m newstuff branch/foo.c')
153
170
        self.runbzr('commit -m newstuff branch')
154
 
        self.runbzr('commit -m newstuff branch', retcode=1)
 
171
        self.runbzr('commit -m newstuff branch', retcode=3)
155
172
 
156
173
    def test_ignore_patterns(self):
157
174
        from bzrlib.branch import Branch
228
245
        self.runbzr('revert')
229
246
        os.chdir('..')
230
247
 
 
248
    def test_status(self):
 
249
        self.runbzr("init")
 
250
        self.build_tree(['hello.txt'])
 
251
        result = self.runbzr("status")
 
252
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
253
        self.runbzr("add hello.txt")
 
254
        result = self.runbzr("status")
 
255
        self.assert_("added:\n  hello.txt\n" in result, result)
 
256
        self.runbzr("commit -m added")
 
257
        result = self.runbzr("status -r 0..1")
 
258
        self.assert_("added:\n  hello.txt\n" in result, result)
 
259
        self.build_tree(['world.txt'])
 
260
        result = self.runbzr("status -r 0")
 
261
        self.assert_("added:\n  hello.txt\n" \
 
262
                     "unknown:\n  world.txt\n" in result, result)
231
263
 
232
264
    def test_mv_modes(self):
233
265
        """Test two modes of operation for mv"""
309
341
        self.assert_('\n+hello world!' in output)
310
342
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
311
343
        self.assert_('\n+baz' in output)
 
344
        file('moo', 'wb').write('moo')
 
345
        self.runbzr('add moo')
 
346
        os.unlink('moo')
 
347
        self.runbzr('diff')
312
348
 
313
349
    def test_diff_branches(self):
314
 
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
 
350
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
315
351
        branch = Branch.initialize('branch1')
316
352
        branch.working_tree().add(['file'])
317
353
        branch.working_tree().commit('add file')
318
354
        copy_branch(branch, 'branch2')
319
 
        print >> open('branch2/file', 'w'), 'new content'
 
355
        print >> open('branch2/file', 'wb'), 'new content'
320
356
        branch2 = Branch.open('branch2')
321
357
        branch2.working_tree().commit('update file')
322
358
        # should open branch1 and diff against branch2, 
324
360
                                        'branch1'],
325
361
                                       retcode=1)
326
362
        self.assertEquals(("=== modified file 'file'\n"
327
 
                           "--- file\n"
328
 
                           "+++ file\n"
 
363
                           "--- file\t\n"
 
364
                           "+++ file\t\n"
329
365
                           "@@ -1,1 +1,1 @@\n"
330
366
                           "-new content\n"
331
367
                           "+contents of branch1/file\n"
332
368
                           "\n", ''), output)
 
369
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
370
                                       retcode=1)
 
371
        self.assertEqualDiff(("=== modified file 'file'\n"
 
372
                              "--- file\t\n"
 
373
                              "+++ file\t\n"
 
374
                              "@@ -1,1 +1,1 @@\n"
 
375
                              "-new content\n"
 
376
                              "+contents of branch1/file\n"
 
377
                              "\n", ''), output)
 
378
 
333
379
 
334
380
    def test_branch(self):
335
381
        """Branch from one branch to another."""
365
411
        os.chdir('../a')
366
412
        file('hello', 'wt').write('quuux')
367
413
        # We can't merge when there are in-tree changes
368
 
        self.runbzr('merge ../b', retcode=1)
 
414
        self.runbzr('merge ../b', retcode=3)
369
415
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
370
416
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
371
 
                    retcode=1)
 
417
                    retcode=3)
372
418
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
373
419
        self.runbzr('revert --no-backup')
374
420
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
428
474
        os.chdir('a')
429
475
 
430
476
        self.example_branch()
431
 
        self.runbzr('pull', retcode=1)
432
 
        self.runbzr('missing', retcode=1)
 
477
        self.runbzr('pull', retcode=3)
 
478
        self.runbzr('missing', retcode=3)
433
479
        self.runbzr('missing .')
434
480
        self.runbzr('missing')
435
481
        self.runbzr('pull')
436
 
        self.runbzr('pull /', retcode=1)
 
482
        self.runbzr('pull /', retcode=3)
437
483
        self.runbzr('pull')
438
484
 
439
485
        os.chdir('..')
453
499
        os.chdir('../b')
454
500
        self.runbzr('commit -m blah3 --unchanged')
455
501
        # no overwrite
456
 
        self.runbzr('pull ../a', retcode=1)
 
502
        self.runbzr('pull ../a', retcode=3)
457
503
        os.chdir('..')
458
504
        self.runbzr('branch b overwriteme')
459
505
        os.chdir('overwriteme')
478
524
        self.runbzr('pull ../b')
479
525
        self.runbzr('pull ../b')
480
526
 
 
527
    def test_inventory(self):
 
528
        bzr = self.runbzr
 
529
        def output_equals(value, *args):
 
530
            out = self.runbzr(['inventory'] + list(args), backtick=True)
 
531
            self.assertEquals(out, value)
 
532
 
 
533
        bzr('init')
 
534
        open('a', 'wb').write('hello\n')
 
535
        os.mkdir('b')
 
536
 
 
537
        bzr('add a b')
 
538
        bzr('commit -m add')
 
539
 
 
540
        output_equals('a\n', '--kind', 'file')
 
541
        output_equals('b\n', '--kind', 'directory')        
 
542
 
481
543
    def test_ls(self):
482
544
        """Test the abilities of 'bzr ls'"""
483
545
        bzr = self.runbzr
493
555
        open('a', 'wb').write('hello\n')
494
556
 
495
557
        # Can't supply both
496
 
        bzr('ls --verbose --null', retcode=1)
 
558
        bzr('ls --verbose --null', retcode=3)
497
559
 
498
560
        ls_equals('a\n')
499
561
        ls_equals('?        a\n', '--verbose')
599
661
        out = bzr('pull --verbose ../b', backtick=True)
600
662
        self.failIfEqual(out.find('Added Revisions:'), -1)
601
663
        self.failIfEqual(out.find('message:\n  added b'), -1)
602
 
        self.failIfEqual(out.find('added:\n  b'), -1)
 
664
        self.failIfEqual(out.find('added b'), -1)
603
665
 
604
666
        # Check that --overwrite --verbose prints out the removed entries
605
667
        bzr('commit -m foo --unchanged')
606
668
        os.chdir('../b')
607
669
        bzr('commit -m baz --unchanged')
608
 
        bzr('pull ../a', retcode=1)
 
670
        bzr('pull ../a', retcode=3)
609
671
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
610
672
 
611
673
        remove_loc = out.find('Removed Revisions:')
627
689
        os.chdir('a')
628
690
        self.runbzr('init')
629
691
        self.runbzr('commit -m unchanged --unchanged')
630
 
        self.runbzr('pull', retcode=1)
631
 
        self.runbzr('merge', retcode=1)
 
692
        self.runbzr('pull', retcode=3)
 
693
        self.runbzr('merge', retcode=3)
632
694
        self.runbzr('branch . ../b')
633
695
        os.chdir('../b')
634
696
        self.runbzr('pull')
645
707
        os.chdir('../b')
646
708
        self.runbzr('pull')
647
709
        os.chdir('../d')
648
 
        self.runbzr('pull', retcode=1)
 
710
        self.runbzr('pull', retcode=3)
649
711
        self.runbzr('pull ../a --remember')
650
712
        self.runbzr('pull')
651
713
        
653
715
        """add command prints the names of added files."""
654
716
        b = Branch.initialize('.')
655
717
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
656
 
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
 
718
        out = self.run_bzr_captured(['add'], retcode=0)[0]
657
719
        # the ordering is not defined at the moment
658
720
        results = sorted(out.rstrip('\n').split('\n'))
659
721
        self.assertEquals(['added dir',
665
727
        """add -q does not print the names of added files."""
666
728
        b = Branch.initialize('.')
667
729
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
668
 
        out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
 
730
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
669
731
        # the ordering is not defined at the moment
670
732
        results = sorted(out.rstrip('\n').split('\n'))
671
733
        self.assertEquals([''], results)
741
803
    def test_unknown_command(self):
742
804
        """Handling of unknown command."""
743
805
        out, err = self.run_bzr_captured(['fluffy-badger'],
744
 
                                         retcode=1)
 
806
                                         retcode=3)
745
807
        self.assertEquals(out, '')
746
808
        err.index('unknown command')
747
809
 
748
 
    def test_conflicts(self):
749
 
        """Handling of merge conflicts"""
 
810
    def create_conflicts(self):
 
811
        """Create a conflicted tree"""
750
812
        os.mkdir('base')
751
813
        os.chdir('base')
752
814
        file('hello', 'wb').write("hi world")
766
828
        file('question', 'wb').write("What do you get when you multiply six"
767
829
                                   "times nine?")
768
830
        self.runbzr('commit -m this')
 
831
 
 
832
    def test_remerge(self):
 
833
        """Remerge command works as expected"""
 
834
        self.create_conflicts()
 
835
        self.runbzr('merge ../other --show-base', retcode=1)
 
836
        conflict_text = file('hello').read()
 
837
        assert '|||||||' in conflict_text
 
838
        assert 'hi world' in conflict_text
 
839
        self.runbzr('remerge', retcode=1)
 
840
        conflict_text = file('hello').read()
 
841
        assert '|||||||' not in conflict_text
 
842
        assert 'hi world' not in conflict_text
 
843
        os.unlink('hello.OTHER')
 
844
        self.runbzr('remerge hello --merge-type weave', retcode=1)
 
845
        assert os.path.exists('hello.OTHER')
 
846
        file_id = self.runbzr('file-id hello')
 
847
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
 
848
        self.runbzr('remerge --merge-type weave', retcode=1)
 
849
        assert os.path.exists('hello.OTHER')
 
850
        assert not os.path.exists('hello.BASE')
 
851
        assert '|||||||' not in conflict_text
 
852
        assert 'hi world' not in conflict_text
 
853
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
 
854
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
 
855
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
 
856
        self.runbzr('remerge hello --show-base', retcode=1)
 
857
        self.runbzr('remerge hello --reprocess', retcode=1)
 
858
        self.runbzr('resolve --all')
 
859
        self.runbzr('commit -m done',)
 
860
        self.runbzr('remerge', retcode=3)
 
861
 
 
862
 
 
863
    def test_conflicts(self):
 
864
        """Handling of merge conflicts"""
 
865
        self.create_conflicts()
769
866
        self.runbzr('merge ../other --show-base', retcode=1)
770
867
        conflict_text = file('hello').read()
771
868
        self.assert_('<<<<<<<' in conflict_text)
786
883
        self.runbzr('resolve hello')
787
884
        result = self.runbzr('conflicts', backtick=1)
788
885
        self.assertEquals(result, "question\n")
789
 
        self.runbzr('commit -m conflicts', retcode=1)
 
886
        self.runbzr('commit -m conflicts', retcode=3)
790
887
        self.runbzr('resolve --all')
791
888
        result = self.runbzr('conflicts', backtick=1)
792
889
        self.runbzr('commit -m conflicts')
836
933
        self.example_branch()
837
934
 
838
935
        # with no push target, fail
839
 
        self.runbzr('push', retcode=1)
 
936
        self.runbzr('push', retcode=3)
840
937
        # with an explicit target work
841
938
        self.runbzr('push ../output-branch')
842
939
        # with an implicit target work
856
953
        self.runbzr('commit --unchanged -m unchanged')
857
954
        os.chdir('../my-branch')
858
955
        # cannot push now
859
 
        self.runbzr('push', retcode=1)
 
956
        self.runbzr('push', retcode=3)
860
957
        # and there are difference
861
958
        self.runbzr('missing ../output-branch', retcode=1)
 
959
        self.runbzr('missing --verbose ../output-branch', retcode=1)
862
960
        # but we can force a push
863
961
        self.runbzr('push --overwrite')
864
962
        # nothing missing
865
963
        self.runbzr('missing ../output-branch')
866
964
        
867
965
        # pushing to a new dir with no parent should fail
868
 
        self.runbzr('push ../missing/new-branch', retcode=1)
 
966
        self.runbzr('push ../missing/new-branch', retcode=3)
869
967
        # unless we provide --create-prefix
870
968
        self.runbzr('push --create-prefix ../missing/new-branch')
871
969
        # nothing missing
900
998
 
901
999
            # It should not find the command in the local 
902
1000
            # directory by default, since it is not in my path
903
 
            bzr(cmd_name, retcode=1)
 
1001
            bzr(cmd_name, retcode=3)
904
1002
 
905
1003
            # Now put it into my path
906
1004
            os.environ['BZRPATH'] = '.'
915
1013
            # Make sure empty path elements are ignored
916
1014
            os.environ['BZRPATH'] = os.pathsep
917
1015
 
918
 
            bzr(cmd_name, retcode=1)
 
1016
            bzr(cmd_name, retcode=3)
919
1017
 
920
1018
        finally:
921
1019
            if oldpath:
987
1085
        runbzr("help st")
988
1086
        runbzr("help")
989
1087
        runbzr("help commands")
990
 
        runbzr("help slartibartfast", 1)
 
1088
        runbzr("help slartibartfast", 3)
991
1089
 
992
1090
        out = capture("help ci")
993
1091
        out.index('aliases: ')
994
1092
 
995
1093
        progress("can't rename unversioned file")
996
 
        runbzr("rename test.txt new-test.txt", 1)
 
1094
        runbzr("rename test.txt new-test.txt", 3)
997
1095
 
998
1096
        progress("adding a file")
999
1097
 
1013
1111
 
1014
1112
        progress("more complex renames")
1015
1113
        os.mkdir("sub1")
1016
 
        runbzr("rename hello.txt sub1", 1)
1017
 
        runbzr("rename hello.txt sub1/hello.txt", 1)
1018
 
        runbzr("move hello.txt sub1", 1)
 
1114
        runbzr("rename hello.txt sub1", 3)
 
1115
        runbzr("rename hello.txt sub1/hello.txt", 3)
 
1116
        runbzr("move hello.txt sub1", 3)
1019
1117
 
1020
1118
        runbzr("add sub1")
1021
1119
        runbzr("rename sub1 sub2")
1073
1171
        runbzr('log')
1074
1172
        runbzr('log -v')
1075
1173
        runbzr('log -v --forward')
1076
 
        runbzr('log -m', retcode=1)
 
1174
        runbzr('log -m', retcode=3)
1077
1175
        log_out = capture('log -m commit')
1078
1176
        self.assert_("this is my new commit\n  and" in log_out)
1079
1177
        self.assert_("rename nested" not in log_out)
1220
1318
        branch.working_tree().commit('add file', rev_id='A')
1221
1319
        url = self.get_remote_url('branch/file')
1222
1320
        output = self.capture('log %s' % url)
1223
 
        self.assertEqual(7, len(output.split('\n')))
 
1321
        self.assertEqual(8, len(output.split('\n')))