20
20
from bzrlib import (
29
from bzrlib.tests import script
32
def load_tests(standard_tests, module, loader):
33
result = loader.suiteClass()
35
sp_tests, remaining_tests = tests.split_suite_by_condition(
36
standard_tests, tests.condition_isinstance((
37
TestParametrizedResolveConflicts,
39
# Each test class defines its own scenarios. This is needed for
40
# TestResolvePathConflictBefore531967 that verifies that the same tests as
41
# TestResolvePathConflict still pass.
42
for test in tests.iter_suite_tests(sp_tests):
43
tests.apply_scenarios(test, test.scenarios(), result)
45
# No parametrization for the remaining tests
46
result.addTests(remaining_tests)
27
from bzrlib.tests import (
33
load_tests = scenarios.load_tests_apply_scenarios
51
36
# TODO: Test commit with some added, and added-but-missing files
298
"""Return the scenario list for the conflict type defined by the class.
300
Each scenario is of the form:
301
(common, (left_name, left_dict), (right_name, right_dict))
305
* left_name and right_name are the scenario names that will be combined
307
* left_dict and right_dict are the attributes specific to each half of
308
the scenario. They should include at least 'actions' and 'check' and
309
will be available as '_this' and '_other' test instance attributes.
311
Daughters classes are free to add their specific attributes as they see
312
fit in any of the three dicts.
314
This is a class method so that load_tests can find it.
316
'_base_actions' in the common dict, 'actions' and 'check' in the left
317
and right dicts use names that map to methods in the test classes. Some
318
prefixes are added to these names to get the correspong methods (see
319
_get_actions() and _get_check()). The motivation here is to avoid
320
collisions in the class namespace.
322
# Only concrete classes return actual scenarios
277
"""The scenario list for the conflict type defined by the class.
279
Each scenario is of the form:
280
(common, (left_name, left_dict), (right_name, right_dict))
284
* left_name and right_name are the scenario names that will be combined
286
* left_dict and right_dict are the attributes specific to each half of
287
the scenario. They should include at least 'actions' and 'check' and
288
will be available as '_this' and '_other' test instance attributes.
290
Daughters classes are free to add their specific attributes as they see
291
fit in any of the three dicts.
293
This is a class method so that load_tests can find it.
295
'_base_actions' in the common dict, 'actions' and 'check' in the left
296
and right dicts use names that map to methods in the test classes. Some
297
prefixes are added to these names to get the correspong methods (see
298
_get_actions() and _get_check()). The motivation here is to avoid
299
collisions in the class namespace.
326
303
super(TestParametrizedResolveConflicts, self).setUp()
368
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
370
_conflict_type = conflicts.TextConflict
372
# Set by the scenarios
373
# path and file-id for the file involved in the conflict
377
scenarios = mirror_scenarios(
379
# File modified/deleted
380
(dict(_base_actions='create_file',
381
_path='file', _file_id='file-id'),
383
dict(actions='modify_file_A', check='file_has_content_A')),
385
dict(actions='modify_file_B', check='file_has_content_B')),),
388
def do_create_file(self):
389
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
391
def do_modify_file_A(self):
392
return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
394
def do_modify_file_B(self):
395
return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
397
def check_file_has_content_A(self):
398
self.assertFileEqual('trunk content\nfeature A\n', 'branch/file')
400
def check_file_has_content_B(self):
401
self.assertFileEqual('trunk content\nfeature B\n', 'branch/file')
403
def _get_resolve_path_arg(self, wt, action):
406
def assertTextConflict(self, wt, c):
407
self.assertEqual(self._file_id, c.file_id)
408
self.assertEqual(self._path, c.path)
409
_assert_conflict = assertTextConflict
391
412
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
393
_conflict_type = conflicts.ContentsConflict,
414
_conflict_type = conflicts.ContentsConflict
395
# Set by load_tests from scenarios()
416
# Set by the scenarios
396
417
# path and file-id for the file involved in the conflict
421
scenarios = mirror_scenarios(
403
423
# File modified/deleted
404
424
(dict(_base_actions='create_file',
405
425
_path='file', _file_id='file-id'),
407
427
dict(actions='modify_file', check='file_has_more_content')),
409
429
dict(actions='delete_file', check='file_doesnt_exist')),),
411
return mirror_scenarios(base_scenarios)
430
# File modified/deleted in dir
431
(dict(_base_actions='create_file_in_dir',
432
_path='dir/file', _file_id='file-id'),
433
('file_modified_in_dir',
434
dict(actions='modify_file_in_dir',
435
check='file_in_dir_has_more_content')),
436
('file_deleted_in_dir',
437
dict(actions='delete_file',
438
check='file_in_dir_doesnt_exist')),),
413
441
def do_create_file(self):
414
442
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
425
453
def check_file_doesnt_exist(self):
426
454
self.failIfExists('branch/file')
456
def do_create_file_in_dir(self):
457
return [('add', ('dir', 'dir-id', 'directory', '')),
458
('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
460
def do_modify_file_in_dir(self):
461
return [('modify', ('file-id', 'trunk content\nmore content\n'))]
463
def check_file_in_dir_has_more_content(self):
464
self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
466
def check_file_in_dir_doesnt_exist(self):
467
self.failIfExists('branch/dir/file')
428
469
def _get_resolve_path_arg(self, wt, action):
429
470
return self._path
437
478
class TestResolvePathConflict(TestParametrizedResolveConflicts):
439
_conflict_type = conflicts.PathConflict,
480
_conflict_type = conflicts.PathConflict
441
482
def do_nothing(self):
446
# Each side dict additionally defines:
447
# - path path involved (can be '<deleted>')
485
# Each side dict additionally defines:
486
# - path path involved (can be '<deleted>')
488
scenarios = mirror_scenarios(
450
490
# File renamed/deleted
451
491
(dict(_base_actions='create_file'),
457
497
# PathConflicts deletion handling requires a special
458
498
# hard-coded value
459
499
path='<deleted>', file_id='file-id')),),
500
# File renamed/deleted in dir
501
(dict(_base_actions='create_file_in_dir'),
502
('file_renamed_in_dir',
503
dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
504
path='dir/new-file', file_id='file-id')),
506
dict(actions='delete_file', check='file_in_dir_doesnt_exist',
507
# PathConflicts deletion handling requires a special
509
path='<deleted>', file_id='file-id')),),
460
510
# File renamed/renamed differently
461
511
(dict(_base_actions='create_file'),
484
534
dict(actions='rename_dir2', check='dir_renamed2',
485
535
path='new-dir2', file_id='dir-id')),),
487
return mirror_scenarios(base_scenarios)
489
538
def do_create_file(self):
490
539
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
532
581
def check_dir_doesnt_exist(self):
533
582
self.failIfExists('branch/dir')
584
def do_create_file_in_dir(self):
585
return [('add', ('dir', 'dir-id', 'directory', '')),
586
('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
588
def do_rename_file_in_dir(self):
589
return [('rename', ('dir/file', 'dir/new-file'))]
591
def check_file_in_dir_renamed(self):
592
self.failIfExists('branch/dir/file')
593
self.failUnlessExists('branch/dir/new-file')
595
def check_file_in_dir_doesnt_exist(self):
596
self.failIfExists('branch/dir/file')
535
598
def _get_resolve_path_arg(self, wt, action):
536
599
tpath = self._this['path']
537
600
opath = self._other['path']
569
632
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
571
_conflict_type = conflicts.DuplicateEntry,
634
_conflict_type = conflicts.DuplicateEntry
575
# Each side dict additionally defines:
636
scenarios = mirror_scenarios(
579
638
# File created with different file-ids
580
639
(dict(_base_actions='nothing'),
581
640
('filea_created',
625
683
# tests MissingParent resolution :-/
631
$ bzr commit -m 'Create trunk'
690
$ bzr commit -m 'Create trunk' -q
633
691
$ echo 'trunk content' >dir/file
635
$ bzr commit -m 'Add dir/file in trunk'
637
$ bzr branch . -r 1 ../branch
692
$ bzr add -q dir/file
693
$ bzr commit -q -m 'Add dir/file in trunk'
694
$ bzr branch -q . -r 1 ../branch
640
$ bzr commit -m 'Remove dir in branch'
697
$ bzr commit -q -m 'Remove dir in branch'
642
698
$ bzr merge ../trunk
650
706
def test_take_this(self):
651
707
self.run_script("""
708
$ bzr rm -q dir --force
653
709
$ bzr resolve dir
654
$ bzr commit --strict -m 'No more conflicts nor unknown files'
710
2>2 conflict(s) resolved, 0 remaining
711
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
657
714
def test_take_other(self):
658
715
self.run_script("""
659
716
$ bzr resolve dir
660
$ bzr commit --strict -m 'No more conflicts nor unknown files'
717
2>2 conflict(s) resolved, 0 remaining
718
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
670
729
$ echo 'trunk content' >dir/file
672
$ bzr commit -m 'Create trunk'
731
$ bzr commit -m 'Create trunk' -q
674
732
$ echo 'trunk content' >dir/file2
676
$ bzr commit -m 'Add dir/file2 in branch'
678
$ bzr branch . -r 1 ../branch
733
$ bzr add -q dir/file2
734
$ bzr commit -q -m 'Add dir/file2 in branch'
735
$ bzr branch -q . -r 1 ../branch
680
$ bzr rm dir/file --force
682
$ bzr commit -m 'Remove dir/file'
737
$ bzr rm -q dir/file --force
739
$ bzr commit -q -m 'Remove dir/file'
684
740
$ bzr merge ../trunk
692
748
def test_keep_them_all(self):
693
749
self.run_script("""
694
750
$ bzr resolve dir
695
$ bzr commit --strict -m 'No more conflicts nor unknown files'
751
2>2 conflict(s) resolved, 0 remaining
752
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
698
755
def test_adopt_child(self):
699
756
self.run_script("""
700
$ bzr mv dir/file2 file2
757
$ bzr mv -q dir/file2 file2
758
$ bzr rm -q dir --force
702
759
$ bzr resolve dir
703
$ bzr commit --strict -m 'No more conflicts nor unknown files'
760
2>2 conflict(s) resolved, 0 remaining
761
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
706
764
def test_kill_them_all(self):
707
765
self.run_script("""
766
$ bzr rm -q dir --force
709
767
$ bzr resolve dir
710
$ bzr commit --strict -m 'No more conflicts nor unknown files'
768
2>2 conflict(s) resolved, 0 remaining
769
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
713
772
def test_resolve_taking_this(self):
714
773
self.run_script("""
715
774
$ bzr resolve --take-this dir
716
$ bzr commit --strict -m 'No more conflicts nor unknown files'
776
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
719
779
def test_resolve_taking_other(self):
720
780
self.run_script("""
721
781
$ bzr resolve --take-other dir
722
$ bzr commit --strict -m 'No more conflicts nor unknown files'
783
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
732
794
$ echo 'trunk content' >dir/file
734
$ bzr commit -m 'Create trunk'
736
$ bzr rm dir/file --force
738
$ bzr commit -m 'Remove dir/file'
740
$ bzr branch . -r 1 ../branch
796
$ bzr commit -m 'Create trunk' -q
797
$ bzr rm -q dir/file --force
798
$ bzr rm -q dir --force
799
$ bzr commit -q -m 'Remove dir/file'
800
$ bzr branch -q . -r 1 ../branch
742
802
$ echo 'branch content' >dir/file2
744
$ bzr commit -m 'Add dir/file2 in branch'
803
$ bzr add -q dir/file2
804
$ bzr commit -q -m 'Add dir/file2 in branch'
746
805
$ bzr merge ../trunk
748
807
2>Conflict: can't delete dir because it is not empty. Not deleting.
753
812
def test_keep_them_all(self):
754
813
self.run_script("""
755
814
$ bzr resolve dir
756
$ bzr commit --strict -m 'No more conflicts nor unknown files'
815
2>2 conflict(s) resolved, 0 remaining
816
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
759
819
def test_adopt_child(self):
760
820
self.run_script("""
761
$ bzr mv dir/file2 file2
821
$ bzr mv -q dir/file2 file2
822
$ bzr rm -q dir --force
763
823
$ bzr resolve dir
764
$ bzr commit --strict -m 'No more conflicts nor unknown files'
824
2>2 conflict(s) resolved, 0 remaining
825
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
767
828
def test_kill_them_all(self):
768
829
self.run_script("""
830
$ bzr rm -q dir --force
770
831
$ bzr resolve dir
771
$ bzr commit --strict -m 'No more conflicts nor unknown files'
832
2>2 conflict(s) resolved, 0 remaining
833
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
774
836
def test_resolve_taking_this(self):
775
837
self.run_script("""
776
838
$ bzr resolve --take-this dir
777
$ bzr commit --strict -m 'No more conflicts nor unknown files'
839
2>2 conflict(s) resolved, 0 remaining
840
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
780
843
def test_resolve_taking_other(self):
781
844
self.run_script("""
782
845
$ bzr resolve --take-other dir
783
$ bzr commit --strict -m 'No more conflicts nor unknown files'
848
2>2 conflict(s) resolved, 0 remaining
849
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
787
853
class TestResolveParentLoop(TestParametrizedResolveConflicts):
789
_conflict_type = conflicts.ParentLoop,
855
_conflict_type = conflicts.ParentLoop
791
857
_this_args = None
792
858
_other_args = None
796
# Each side dict additionally defines:
797
# - dir_id: the directory being moved
798
# - target_id: The target directory
799
# - xfail: whether the test is expected to fail if the action is
800
# involved as 'other'
860
# Each side dict additionally defines:
861
# - dir_id: the directory being moved
862
# - target_id: The target directory
863
# - xfail: whether the test is expected to fail if the action is
864
# involved as 'other'
865
scenarios = mirror_scenarios(
802
867
# Dirs moved into each other
803
868
(dict(_base_actions='create_dir1_dir2'),
804
869
('dir1_into_dir2',
815
880
('dir3_into_dir2',
816
881
dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
882
dir_id='dir3-id', target_id='dir2-id', xfail=True))),
819
return mirror_scenarios(base_scenarios)
821
885
def do_create_dir1_dir2(self):
822
886
return [('add', ('dir1', 'dir1-id', 'directory', '')),
887
$ bzr commit -m 'Create trunk'
953
$ bzr commit -m 'Create trunk' -q
888
954
$ echo "Boing" >foo/bar
890
$ bzr commit -m 'Add foo/bar'
892
$ bzr branch . -r 1 ../branch
956
$ bzr commit -q -m 'Add foo/bar'
957
$ bzr branch -q . -r 1 ../branch
895
960
$ echo "Boo!" >foo
896
$ bzr commit -m 'foo is now a file'
961
$ bzr commit -q -m 'foo is now a file'
898
962
$ bzr merge ../trunk
900
964
2>RK foo => foo.new/
907
971
def test_take_this(self):
908
972
self.run_script("""
909
$ bzr rm foo.new --force
973
$ bzr rm -q foo.new --force
910
974
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
975
# aside ? -- vila 090916
913
977
$ bzr resolve foo.new
914
$ bzr commit --strict -m 'No more conflicts nor unknown files'
978
2>1 conflict(s) resolved, 0 remaining
979
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
917
982
def test_take_other(self):
918
983
self.run_script("""
984
$ bzr rm -q foo --force
985
$ bzr mv -q foo.new foo
921
986
$ bzr resolve foo
922
$ bzr commit --strict -m 'No more conflicts nor unknown files'
987
2>1 conflict(s) resolved, 0 remaining
988
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
925
991
def test_resolve_taking_this(self):
926
992
self.run_script("""
927
993
$ bzr resolve --take-this foo.new
928
$ bzr commit --strict -m 'No more conflicts nor unknown files'
995
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
931
998
def test_resolve_taking_other(self):
932
999
self.run_script("""
933
1000
$ bzr resolve --take-other foo.new
934
$ bzr commit --strict -m 'No more conflicts nor unknown files'
1002
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
944
1012
self.run_script("""
945
1013
$ bzr init trunk
948
$ bzr commit -m 'Create trunk'
1018
$ bzr commit -m 'Create trunk' -q
950
1020
$ echo "Boo!" >foo
951
$ bzr commit -m 'foo is now a file'
953
$ bzr branch . -r 1 ../branch
1021
$ bzr commit -m 'foo is now a file' -q
1022
$ bzr branch -q . -r 1 ../branch -q
955
1024
$ echo "Boing" >foo/bar
957
$ bzr commit -m 'Add foo/bar'
1025
$ bzr add -q foo/bar -q
1026
$ bzr commit -m 'Add foo/bar' -q
959
1027
$ bzr merge ../trunk
960
1028
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]