~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox/__init__.py

[merge] robertc's integration, updated tests to check for retcode=3

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) 
 
144
 
 
145
    def test_remove_deleted(self):
 
146
        self.runbzr("init")
 
147
        self.build_tree(['a'])
 
148
        self.runbzr(['add', 'a'])
 
149
        self.runbzr(['commit', '-m', 'added a'])
 
150
        os.unlink('a')
 
151
        self.runbzr(['remove', 'a'])
127
152
 
128
153
    def test_other_branch_commit(self):
129
154
        # this branch is to ensure consistent behaviour, whether we're run
140
165
        self.runbzr(['add', 'branch/foo.c'])
141
166
        self.runbzr(['add', 'branch'])
142
167
        # can't commit files in different trees; sane error
143
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
 
168
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
144
169
        self.runbzr('commit -m newstuff branch/foo.c')
145
170
        self.runbzr('commit -m newstuff branch')
146
 
        self.runbzr('commit -m newstuff branch', retcode=1)
 
171
        self.runbzr('commit -m newstuff branch', retcode=3)
147
172
 
148
173
 
149
174
    def test_ignore_patterns(self):
225
250
        self.runbzr('revert')
226
251
        os.chdir('..')
227
252
 
 
253
    def test_status(self):
 
254
        self.runbzr("init")
 
255
        self.build_tree(['hello.txt'])
 
256
        result = self.runbzr("status")
 
257
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
258
        self.runbzr("add hello.txt")
 
259
        result = self.runbzr("status")
 
260
        self.assert_("added:\n  hello.txt\n" in result, result)
 
261
        self.runbzr("commit -m added")
 
262
        result = self.runbzr("status -r 0..1")
 
263
        self.assert_("added:\n  hello.txt\n" in result, result)
 
264
        self.build_tree(['world.txt'])
 
265
        result = self.runbzr("status -r 0")
 
266
        self.assert_("added:\n  hello.txt\n" \
 
267
                     "unknown:\n  world.txt\n" in result, result)
228
268
 
229
269
    def test_mv_modes(self):
230
270
        """Test two modes of operation for mv"""
275
315
        self.assertEqual(file('../first.gz/hello', 'rt').read(), 'foo')
276
316
        self.runbzr('export ../first.bz2 -r 1')
277
317
        self.assertEqual(file('../first.bz2/hello', 'rt').read(), 'foo')
 
318
 
 
319
        from tarfile import TarFile
278
320
        self.runbzr('export ../first.tar -r 1')
279
321
        self.assert_(os.path.isfile('../first.tar'))
280
 
        from tarfile import TarFile
281
322
        tf = TarFile('../first.tar')
282
323
        self.assert_('first/hello' in tf.getnames(), tf.getnames())
283
324
        self.assertEqual(tf.extractfile('first/hello').read(), 'foo')
289
330
        self.assert_(os.path.isfile('../first.tar.bz2'))
290
331
        self.runbzr('export ../first.tar.tbz2 -r 1')
291
332
        self.assert_(os.path.isfile('../first.tar.tbz2'))
 
333
 
292
334
        from bz2 import BZ2File
293
335
        tf = TarFile('../first.tar.tbz2', 
294
336
                     fileobj=BZ2File('../first.tar.tbz2', 'r'))
298
340
        tf = TarFile('../first2.tar')
299
341
        self.assert_('pizza/hello' in tf.getnames(), tf.getnames())
300
342
 
 
343
        from zipfile import ZipFile
 
344
        self.runbzr('export ../first.zip -r 1')
 
345
        self.failUnlessExists('../first.zip')
 
346
        zf = ZipFile('../first.zip')
 
347
        self.assert_('first/hello' in zf.namelist(), zf.namelist())
 
348
        self.assertEqual(zf.read('first/hello'), 'foo')
 
349
 
 
350
        self.runbzr('export ../first2.zip -r 1 --root pizza')
 
351
        zf = ZipFile('../first2.zip')
 
352
        self.assert_('pizza/hello' in zf.namelist(), zf.namelist())
 
353
        
 
354
        self.runbzr('export ../first-zip --format=zip -r 1')
 
355
        zf = ZipFile('../first-zip')
 
356
        self.assert_('first-zip/hello' in zf.namelist(), zf.namelist())
 
357
 
301
358
    def test_diff(self):
302
359
        self.example_branch()
303
360
        file('hello', 'wt').write('hello world!')
306
363
        self.assert_('\n+hello world!' in output)
307
364
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
308
365
        self.assert_('\n+baz' in output)
 
366
        file('moo', 'wb').write('moo')
 
367
        self.runbzr('add moo')
 
368
        os.unlink('moo')
 
369
        self.runbzr('diff')
309
370
 
310
371
    def test_diff_branches(self):
311
372
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
321
382
                                        'branch1'],
322
383
                                       retcode=1)
323
384
        self.assertEquals(("=== modified file 'file'\n"
324
 
                           "--- file\n"
325
 
                           "+++ file\n"
 
385
                           "--- file\t\n"
 
386
                           "+++ file\t\n"
326
387
                           "@@ -1,1 +1,1 @@\n"
327
388
                           "-new content\n"
328
389
                           "+contents of branch1/file\n"
329
390
                           "\n", ''), output)
 
391
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
392
                                       retcode=1)
 
393
        self.assertEqualDiff(("=== modified file 'file'\n"
 
394
                              "--- file\t\n"
 
395
                              "+++ file\t\n"
 
396
                              "@@ -1,1 +1,1 @@\n"
 
397
                              "-new content\n"
 
398
                              "+contents of branch1/file\n"
 
399
                              "\n", ''), output)
 
400
 
330
401
 
331
402
    def test_branch(self):
332
403
        """Branch from one branch to another."""
362
433
        os.chdir('../a')
363
434
        file('hello', 'wt').write('quuux')
364
435
        # We can't merge when there are in-tree changes
365
 
        self.runbzr('merge ../b', retcode=1)
 
436
        self.runbzr('merge ../b', retcode=3)
366
437
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
367
438
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
368
 
                    retcode=1)
 
439
                    retcode=3)
369
440
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
370
441
        self.runbzr('revert --no-backup')
371
442
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
425
496
        os.chdir('a')
426
497
 
427
498
        self.example_branch()
428
 
        self.runbzr('pull', retcode=1)
429
 
        self.runbzr('missing', retcode=1)
 
499
        self.runbzr('pull', retcode=3)
 
500
        self.runbzr('missing', retcode=3)
430
501
        self.runbzr('missing .')
431
502
        self.runbzr('missing')
432
503
        self.runbzr('pull')
433
 
        self.runbzr('pull /', retcode=1)
 
504
        self.runbzr('pull /', retcode=3)
434
505
        self.runbzr('pull')
435
506
 
436
507
        os.chdir('..')
450
521
        os.chdir('../b')
451
522
        self.runbzr('commit -m blah3 --unchanged')
452
523
        # no overwrite
453
 
        self.runbzr('pull ../a', retcode=1)
 
524
        self.runbzr('pull ../a', retcode=3)
454
525
        os.chdir('..')
455
526
        self.runbzr('branch b overwriteme')
456
527
        os.chdir('overwriteme')
490
561
        open('a', 'wb').write('hello\n')
491
562
 
492
563
        # Can't supply both
493
 
        bzr('ls --verbose --null', retcode=1)
 
564
        bzr('ls --verbose --null', retcode=3)
494
565
 
495
566
        ls_equals('a\n')
496
567
        ls_equals('?        a\n', '--verbose')
576
647
                  'subdir/b\n'
577
648
                  , '--versioned')
578
649
 
 
650
    def test_pull_verbose(self):
 
651
        """Pull changes from one branch to another and watch the output."""
 
652
 
 
653
        os.mkdir('a')
 
654
        os.chdir('a')
 
655
 
 
656
        bzr = self.runbzr
 
657
        self.example_branch()
 
658
 
 
659
        os.chdir('..')
 
660
        bzr('branch a b')
 
661
        os.chdir('b')
 
662
        open('b', 'wb').write('else\n')
 
663
        bzr('add b')
 
664
        bzr(['commit', '-m', 'added b'])
 
665
 
 
666
        os.chdir('../a')
 
667
        out = bzr('pull --verbose ../b', backtick=True)
 
668
        self.failIfEqual(out.find('Added Revisions:'), -1)
 
669
        self.failIfEqual(out.find('message:\n  added b'), -1)
 
670
        self.failIfEqual(out.find('added b'), -1)
 
671
 
 
672
        # Check that --overwrite --verbose prints out the removed entries
 
673
        bzr('commit -m foo --unchanged')
 
674
        os.chdir('../b')
 
675
        bzr('commit -m baz --unchanged')
 
676
        bzr('pull ../a', retcode=3)
 
677
        out = bzr('pull --overwrite --verbose ../a', backtick=1)
 
678
 
 
679
        remove_loc = out.find('Removed Revisions:')
 
680
        self.failIfEqual(remove_loc, -1)
 
681
        added_loc = out.find('Added Revisions:')
 
682
        self.failIfEqual(added_loc, -1)
 
683
 
 
684
        removed_message = out.find('message:\n  baz')
 
685
        self.failIfEqual(removed_message, -1)
 
686
        self.failUnless(remove_loc < removed_message < added_loc)
 
687
 
 
688
        added_message = out.find('message:\n  foo')
 
689
        self.failIfEqual(added_message, -1)
 
690
        self.failUnless(added_loc < added_message)
 
691
        
579
692
    def test_locations(self):
580
693
        """Using and remembering different locations"""
581
694
        os.mkdir('a')
582
695
        os.chdir('a')
583
696
        self.runbzr('init')
584
697
        self.runbzr('commit -m unchanged --unchanged')
585
 
        self.runbzr('pull', retcode=1)
586
 
        self.runbzr('merge', retcode=1)
 
698
        self.runbzr('pull', retcode=3)
 
699
        self.runbzr('merge', retcode=3)
587
700
        self.runbzr('branch . ../b')
588
701
        os.chdir('../b')
589
702
        self.runbzr('pull')
600
713
        os.chdir('../b')
601
714
        self.runbzr('pull')
602
715
        os.chdir('../d')
603
 
        self.runbzr('pull', retcode=1)
 
716
        self.runbzr('pull', retcode=3)
604
717
        self.runbzr('pull ../a --remember')
605
718
        self.runbzr('pull')
606
719
        
608
721
        """add command prints the names of added files."""
609
722
        b = Branch.initialize('.')
610
723
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
611
 
        out = self.run_bzr_captured(['add'], retcode = 0)[0]
 
724
        out = self.run_bzr_captured(['add'], retcode=0)[0]
612
725
        # the ordering is not defined at the moment
613
726
        results = sorted(out.rstrip('\n').split('\n'))
614
727
        self.assertEquals(['added dir',
620
733
        """add -q does not print the names of added files."""
621
734
        b = Branch.initialize('.')
622
735
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
623
 
        out = self.run_bzr_captured(['add', '-q'], retcode = 0)[0]
 
736
        out = self.run_bzr_captured(['add', '-q'], retcode=0)[0]
624
737
        # the ordering is not defined at the moment
625
738
        results = sorted(out.rstrip('\n').split('\n'))
626
739
        self.assertEquals([''], results)
628
741
    def test_unknown_command(self):
629
742
        """Handling of unknown command."""
630
743
        out, err = self.run_bzr_captured(['fluffy-badger'],
631
 
                                         retcode=1)
 
744
                                         retcode=3)
632
745
        self.assertEquals(out, '')
633
746
        err.index('unknown command')
634
747
 
635
 
    def test_conflicts(self):
636
 
        """Handling of merge conflicts"""
 
748
    def create_conflicts(self):
 
749
        """Create a conflicted tree"""
637
750
        os.mkdir('base')
638
751
        os.chdir('base')
639
752
        file('hello', 'wb').write("hi world")
653
766
        file('question', 'wb').write("What do you get when you multiply six"
654
767
                                   "times nine?")
655
768
        self.runbzr('commit -m this')
 
769
 
 
770
    def test_remerge(self):
 
771
        """Remerge command works as expected"""
 
772
        self.create_conflicts()
 
773
        self.runbzr('merge ../other --show-base', retcode=1)
 
774
        conflict_text = file('hello').read()
 
775
        assert '|||||||' in conflict_text
 
776
        assert 'hi world' in conflict_text
 
777
        self.runbzr('remerge', retcode=1)
 
778
        conflict_text = file('hello').read()
 
779
        assert '|||||||' not in conflict_text
 
780
        assert 'hi world' not in conflict_text
 
781
        os.unlink('hello.OTHER')
 
782
        self.runbzr('remerge hello --merge-type weave', retcode=1)
 
783
        assert os.path.exists('hello.OTHER')
 
784
        file_id = self.runbzr('file-id hello')
 
785
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
 
786
        self.runbzr('remerge --merge-type weave', retcode=1)
 
787
        assert os.path.exists('hello.OTHER')
 
788
        assert not os.path.exists('hello.BASE')
 
789
        assert '|||||||' not in conflict_text
 
790
        assert 'hi world' not in conflict_text
 
791
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
 
792
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
 
793
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
 
794
        self.runbzr('remerge hello --show-base', retcode=1)
 
795
        self.runbzr('remerge hello --reprocess', retcode=1)
 
796
        self.runbzr('resolve --all')
 
797
        self.runbzr('commit -m done',)
 
798
        self.runbzr('remerge', retcode=3)
 
799
 
 
800
 
 
801
    def test_conflicts(self):
 
802
        """Handling of merge conflicts"""
 
803
        self.create_conflicts()
656
804
        self.runbzr('merge ../other --show-base', retcode=1)
657
805
        conflict_text = file('hello').read()
658
806
        self.assert_('<<<<<<<' in conflict_text)
673
821
        self.runbzr('resolve hello')
674
822
        result = self.runbzr('conflicts', backtick=1)
675
823
        self.assertEquals(result, "question\n")
676
 
        self.runbzr('commit -m conflicts', retcode=1)
 
824
        self.runbzr('commit -m conflicts', retcode=3)
677
825
        self.runbzr('resolve --all')
678
826
        result = self.runbzr('conflicts', backtick=1)
679
827
        self.runbzr('commit -m conflicts')
723
871
        self.example_branch()
724
872
 
725
873
        # with no push target, fail
726
 
        self.runbzr('push', retcode=1)
 
874
        self.runbzr('push', retcode=3)
727
875
        # with an explicit target work
728
876
        self.runbzr('push ../output-branch')
729
877
        # with an implicit target work
743
891
        self.runbzr('commit --unchanged -m unchanged')
744
892
        os.chdir('../my-branch')
745
893
        # cannot push now
746
 
        self.runbzr('push', retcode=1)
 
894
        self.runbzr('push', retcode=3)
747
895
        # and there are difference
748
896
        self.runbzr('missing ../output-branch', retcode=1)
 
897
        self.runbzr('missing --verbose ../output-branch', retcode=1)
749
898
        # but we can force a push
750
899
        self.runbzr('push --overwrite')
751
900
        # nothing missing
752
901
        self.runbzr('missing ../output-branch')
753
902
        
754
903
        # pushing to a new dir with no parent should fail
755
 
        self.runbzr('push ../missing/new-branch', retcode=1)
 
904
        self.runbzr('push ../missing/new-branch', retcode=3)
756
905
        # unless we provide --create-prefix
757
906
        self.runbzr('push --create-prefix ../missing/new-branch')
758
907
        # nothing missing
759
908
        self.runbzr('missing ../missing/new-branch')
760
909
 
 
910
    def test_external_command(self):
 
911
        """test that external commands can be run by setting the path"""
 
912
        cmd_name = 'test-command'
 
913
        output = 'Hello from test-command'
 
914
        if sys.platform == 'win32':
 
915
            cmd_name += '.bat'
 
916
            output += '\r\n'
 
917
        else:
 
918
            output += '\n'
 
919
 
 
920
        oldpath = os.environ.get('BZRPATH', None)
 
921
 
 
922
        bzr = self.capture
 
923
 
 
924
        try:
 
925
            if os.environ.has_key('BZRPATH'):
 
926
                del os.environ['BZRPATH']
 
927
 
 
928
            f = file(cmd_name, 'wb')
 
929
            if sys.platform == 'win32':
 
930
                f.write('@echo off\n')
 
931
            else:
 
932
                f.write('#!/bin/sh\n')
 
933
            f.write('echo Hello from test-command')
 
934
            f.close()
 
935
            os.chmod(cmd_name, 0755)
 
936
 
 
937
            # It should not find the command in the local 
 
938
            # directory by default, since it is not in my path
 
939
            bzr(cmd_name, retcode=3)
 
940
 
 
941
            # Now put it into my path
 
942
            os.environ['BZRPATH'] = '.'
 
943
 
 
944
            bzr(cmd_name)
 
945
            # The test suite does not capture stdout for external commands
 
946
            # this is because you have to have a real file object
 
947
            # to pass to Popen(stdout=FOO), and StringIO is not one of those.
 
948
            # (just replacing sys.stdout does not change a spawned objects stdout)
 
949
            #self.assertEquals(bzr(cmd_name), output)
 
950
 
 
951
            # Make sure empty path elements are ignored
 
952
            os.environ['BZRPATH'] = os.pathsep
 
953
 
 
954
            bzr(cmd_name, retcode=3)
 
955
 
 
956
        finally:
 
957
            if oldpath:
 
958
                os.environ['BZRPATH'] = oldpath
 
959
 
761
960
 
762
961
def listdir_sorted(dir):
763
962
    L = os.listdir(dir)
824
1023
        runbzr("help st")
825
1024
        runbzr("help")
826
1025
        runbzr("help commands")
827
 
        runbzr("help slartibartfast", 1)
 
1026
        runbzr("help slartibartfast", 3)
828
1027
 
829
1028
        out = capture("help ci")
830
1029
        out.index('aliases: ')
831
1030
 
832
1031
        progress("can't rename unversioned file")
833
 
        runbzr("rename test.txt new-test.txt", 1)
 
1032
        runbzr("rename test.txt new-test.txt", 3)
834
1033
 
835
1034
        progress("adding a file")
836
1035
 
850
1049
 
851
1050
        progress("more complex renames")
852
1051
        os.mkdir("sub1")
853
 
        runbzr("rename hello.txt sub1", 1)
854
 
        runbzr("rename hello.txt sub1/hello.txt", 1)
855
 
        runbzr("move hello.txt sub1", 1)
 
1052
        runbzr("rename hello.txt sub1", 3)
 
1053
        runbzr("rename hello.txt sub1/hello.txt", 3)
 
1054
        runbzr("move hello.txt sub1", 3)
856
1055
 
857
1056
        runbzr("add sub1")
858
1057
        runbzr("rename sub1 sub2")
910
1109
        runbzr('log')
911
1110
        runbzr('log -v')
912
1111
        runbzr('log -v --forward')
913
 
        runbzr('log -m', retcode=1)
 
1112
        runbzr('log -m', retcode=3)
914
1113
        log_out = capture('log -m commit')
915
1114
        self.assert_("this is my new commit\n  and" in log_out)
916
1115
        self.assert_("rename nested" not in log_out)
1057
1256
        branch.working_tree().commit('add file', rev_id='A')
1058
1257
        url = self.get_remote_url('branch/file')
1059
1258
        output = self.capture('log %s' % url)
1060
 
        self.assertEqual(7, len(output.split('\n')))
 
1259
        self.assertEqual(8, len(output.split('\n')))
1061
1260
        
1062
1261
 
1063
1262