~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

MergeĀ fromĀ mainline

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_other_branch_commit(self):
129
146
        # this branch is to ensure consistent behaviour, whether we're run
140
157
        self.runbzr(['add', 'branch/foo.c'])
141
158
        self.runbzr(['add', 'branch'])
142
159
        # can't commit files in different trees; sane error
143
 
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=1)
 
160
        self.runbzr('commit -m newstuff branch/foo.c .', retcode=3)
144
161
        self.runbzr('commit -m newstuff branch/foo.c')
145
162
        self.runbzr('commit -m newstuff branch')
146
 
        self.runbzr('commit -m newstuff branch', retcode=1)
 
163
        self.runbzr('commit -m newstuff branch', retcode=3)
147
164
 
148
165
 
149
166
    def test_ignore_patterns(self):
225
242
        self.runbzr('revert')
226
243
        os.chdir('..')
227
244
 
 
245
    def test_status(self):
 
246
        self.runbzr("init")
 
247
        self.build_tree(['hello.txt'])
 
248
        result = self.runbzr("status")
 
249
        self.assert_("unknown:\n  hello.txt\n" in result, result)
 
250
        self.runbzr("add hello.txt")
 
251
        result = self.runbzr("status")
 
252
        self.assert_("added:\n  hello.txt\n" in result, result)
 
253
        self.runbzr("commit -m added")
 
254
        result = self.runbzr("status -r 0..1")
 
255
        self.assert_("added:\n  hello.txt\n" in result, result)
 
256
        self.build_tree(['world.txt'])
 
257
        result = self.runbzr("status -r 0")
 
258
        self.assert_("added:\n  hello.txt\n" \
 
259
                     "unknown:\n  world.txt\n" in result, result)
228
260
 
229
261
    def test_mv_modes(self):
230
262
        """Test two modes of operation for mv"""
306
338
        self.assert_('\n+hello world!' in output)
307
339
        output = self.runbzr('diff -r last:3..last:1', backtick=1, retcode=1)
308
340
        self.assert_('\n+baz' in output)
 
341
        file('moo', 'wb').write('moo')
 
342
        self.runbzr('add moo')
 
343
        os.unlink('moo')
 
344
        self.runbzr('diff')
309
345
 
310
346
    def test_diff_branches(self):
311
347
        self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
321
357
                                        'branch1'],
322
358
                                       retcode=1)
323
359
        self.assertEquals(("=== modified file 'file'\n"
324
 
                           "--- file\n"
325
 
                           "+++ file\n"
 
360
                           "--- file\t\n"
 
361
                           "+++ file\t\n"
326
362
                           "@@ -1,1 +1,1 @@\n"
327
363
                           "-new content\n"
328
364
                           "+contents of branch1/file\n"
329
365
                           "\n", ''), output)
 
366
        output = self.run_bzr_captured(['diff', 'branch2', 'branch1'],
 
367
                                       retcode=1)
 
368
        self.assertEqualDiff(("=== modified file 'file'\n"
 
369
                              "--- file\t\n"
 
370
                              "+++ file\t\n"
 
371
                              "@@ -1,1 +1,1 @@\n"
 
372
                              "-new content\n"
 
373
                              "+contents of branch1/file\n"
 
374
                              "\n", ''), output)
 
375
 
330
376
 
331
377
    def test_branch(self):
332
378
        """Branch from one branch to another."""
362
408
        os.chdir('../a')
363
409
        file('hello', 'wt').write('quuux')
364
410
        # We can't merge when there are in-tree changes
365
 
        self.runbzr('merge ../b', retcode=1)
 
411
        self.runbzr('merge ../b', retcode=3)
366
412
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
367
413
        self.runbzr('merge ../b -r last:1..last:1 --merge-type blooof',
368
 
                    retcode=1)
 
414
                    retcode=3)
369
415
        self.runbzr('merge ../b -r last:1..last:1 --merge-type merge3')
370
416
        self.runbzr('revert --no-backup')
371
417
        self.runbzr('merge ../b -r last:1..last:1 --merge-type weave')
425
471
        os.chdir('a')
426
472
 
427
473
        self.example_branch()
428
 
        self.runbzr('pull', retcode=1)
429
 
        self.runbzr('missing', retcode=1)
 
474
        self.runbzr('pull', retcode=3)
 
475
        self.runbzr('missing', retcode=3)
430
476
        self.runbzr('missing .')
431
477
        self.runbzr('missing')
432
478
        self.runbzr('pull')
433
 
        self.runbzr('pull /', retcode=1)
 
479
        self.runbzr('pull /', retcode=3)
434
480
        self.runbzr('pull')
435
481
 
436
482
        os.chdir('..')
450
496
        os.chdir('../b')
451
497
        self.runbzr('commit -m blah3 --unchanged')
452
498
        # no overwrite
453
 
        self.runbzr('pull ../a', retcode=1)
 
499
        self.runbzr('pull ../a', retcode=3)
454
500
        os.chdir('..')
455
501
        self.runbzr('branch b overwriteme')
456
502
        os.chdir('overwriteme')
490
536
        open('a', 'wb').write('hello\n')
491
537
 
492
538
        # Can't supply both
493
 
        bzr('ls --verbose --null', retcode=1)
 
539
        bzr('ls --verbose --null', retcode=3)
494
540
 
495
541
        ls_equals('a\n')
496
542
        ls_equals('?        a\n', '--verbose')
583
629
        os.chdir('a')
584
630
        self.runbzr('init')
585
631
        self.runbzr('commit -m unchanged --unchanged')
586
 
        self.runbzr('pull', retcode=1)
587
 
        self.runbzr('merge', retcode=1)
 
632
        self.runbzr('pull', retcode=3)
 
633
        self.runbzr('merge', retcode=3)
588
634
        self.runbzr('branch . ../b')
589
635
        os.chdir('../b')
590
636
        self.runbzr('pull')
601
647
        os.chdir('../b')
602
648
        self.runbzr('pull')
603
649
        os.chdir('../d')
604
 
        self.runbzr('pull', retcode=1)
 
650
        self.runbzr('pull', retcode=3)
605
651
        self.runbzr('pull ../a --remember')
606
652
        self.runbzr('pull')
607
653
        
629
675
    def test_unknown_command(self):
630
676
        """Handling of unknown command."""
631
677
        out, err = self.run_bzr_captured(['fluffy-badger'],
632
 
                                         retcode=1)
 
678
                                         retcode=3)
633
679
        self.assertEquals(out, '')
634
680
        err.index('unknown command')
635
681
 
636
 
    def test_conflicts(self):
637
 
        """Handling of merge conflicts"""
 
682
    def create_conflicts(self):
 
683
        """Create a conflicted tree"""
638
684
        os.mkdir('base')
639
685
        os.chdir('base')
640
686
        file('hello', 'wb').write("hi world")
654
700
        file('question', 'wb').write("What do you get when you multiply six"
655
701
                                   "times nine?")
656
702
        self.runbzr('commit -m this')
 
703
 
 
704
    def test_remerge(self):
 
705
        """Remerge command works as expected"""
 
706
        self.create_conflicts()
 
707
        self.runbzr('merge ../other --show-base', retcode=1)
 
708
        conflict_text = file('hello').read()
 
709
        assert '|||||||' in conflict_text
 
710
        assert 'hi world' in conflict_text
 
711
        self.runbzr('remerge', retcode=1)
 
712
        conflict_text = file('hello').read()
 
713
        assert '|||||||' not in conflict_text
 
714
        assert 'hi world' not in conflict_text
 
715
        os.unlink('hello.OTHER')
 
716
        self.runbzr('remerge hello --merge-type weave', retcode=1)
 
717
        assert os.path.exists('hello.OTHER')
 
718
        file_id = self.runbzr('file-id hello')
 
719
        file_id = self.runbzr('file-id hello.THIS', retcode=3)
 
720
        self.runbzr('remerge --merge-type weave', retcode=1)
 
721
        assert os.path.exists('hello.OTHER')
 
722
        assert not os.path.exists('hello.BASE')
 
723
        assert '|||||||' not in conflict_text
 
724
        assert 'hi world' not in conflict_text
 
725
        self.runbzr('remerge . --merge-type weave --show-base', retcode=3)
 
726
        self.runbzr('remerge . --merge-type weave --reprocess', retcode=3)
 
727
        self.runbzr('remerge . --show-base --reprocess', retcode=3)
 
728
        self.runbzr('remerge hello --show-base', retcode=1)
 
729
        self.runbzr('remerge hello --reprocess', retcode=1)
 
730
        self.runbzr('resolve --all')
 
731
        self.runbzr('commit -m done',)
 
732
        self.runbzr('remerge', retcode=3)
 
733
 
 
734
 
 
735
    def test_conflicts(self):
 
736
        """Handling of merge conflicts"""
 
737
        self.create_conflicts()
657
738
        self.runbzr('merge ../other --show-base', retcode=1)
658
739
        conflict_text = file('hello').read()
659
740
        self.assert_('<<<<<<<' in conflict_text)
674
755
        self.runbzr('resolve hello')
675
756
        result = self.runbzr('conflicts', backtick=1)
676
757
        self.assertEquals(result, "question\n")
677
 
        self.runbzr('commit -m conflicts', retcode=1)
 
758
        self.runbzr('commit -m conflicts', retcode=3)
678
759
        self.runbzr('resolve --all')
679
760
        result = self.runbzr('conflicts', backtick=1)
680
761
        self.runbzr('commit -m conflicts')
724
805
        self.example_branch()
725
806
 
726
807
        # with no push target, fail
727
 
        self.runbzr('push', retcode=1)
 
808
        self.runbzr('push', retcode=3)
728
809
        # with an explicit target work
729
810
        self.runbzr('push ../output-branch')
730
811
        # with an implicit target work
744
825
        self.runbzr('commit --unchanged -m unchanged')
745
826
        os.chdir('../my-branch')
746
827
        # cannot push now
747
 
        self.runbzr('push', retcode=1)
 
828
        self.runbzr('push', retcode=3)
748
829
        # and there are difference
749
830
        self.runbzr('missing ../output-branch', retcode=1)
 
831
        self.runbzr('missing --verbose ../output-branch', retcode=1)
750
832
        # but we can force a push
751
833
        self.runbzr('push --overwrite')
752
834
        # nothing missing
753
835
        self.runbzr('missing ../output-branch')
754
836
        
755
837
        # pushing to a new dir with no parent should fail
756
 
        self.runbzr('push ../missing/new-branch', retcode=1)
 
838
        self.runbzr('push ../missing/new-branch', retcode=3)
757
839
        # unless we provide --create-prefix
758
840
        self.runbzr('push --create-prefix ../missing/new-branch')
759
841
        # nothing missing
825
907
        runbzr("help st")
826
908
        runbzr("help")
827
909
        runbzr("help commands")
828
 
        runbzr("help slartibartfast", 1)
 
910
        runbzr("help slartibartfast", 3)
829
911
 
830
912
        out = capture("help ci")
831
913
        out.index('aliases: ')
832
914
 
833
915
        progress("can't rename unversioned file")
834
 
        runbzr("rename test.txt new-test.txt", 1)
 
916
        runbzr("rename test.txt new-test.txt", 3)
835
917
 
836
918
        progress("adding a file")
837
919
 
851
933
 
852
934
        progress("more complex renames")
853
935
        os.mkdir("sub1")
854
 
        runbzr("rename hello.txt sub1", 1)
855
 
        runbzr("rename hello.txt sub1/hello.txt", 1)
856
 
        runbzr("move hello.txt sub1", 1)
 
936
        runbzr("rename hello.txt sub1", 3)
 
937
        runbzr("rename hello.txt sub1/hello.txt", 3)
 
938
        runbzr("move hello.txt sub1", 3)
857
939
 
858
940
        runbzr("add sub1")
859
941
        runbzr("rename sub1 sub2")
911
993
        runbzr('log')
912
994
        runbzr('log -v')
913
995
        runbzr('log -v --forward')
914
 
        runbzr('log -m', retcode=1)
 
996
        runbzr('log -m', retcode=3)
915
997
        log_out = capture('log -m commit')
916
998
        self.assert_("this is my new commit\n  and" in log_out)
917
999
        self.assert_("rename nested" not in log_out)
1058
1140
        branch.commit('add file', rev_id='A')
1059
1141
        url = self.get_remote_url('branch/file')
1060
1142
        output = self.capture('log %s' % url)
1061
 
        self.assertEqual(7, len(output.split('\n')))
 
1143
        self.assertEqual(8, len(output.split('\n')))
1062
1144
        
1063
1145
 
1064
1146