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)
413
432
def do_create_file(self):
414
433
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
437
456
class TestResolvePathConflict(TestParametrizedResolveConflicts):
439
_conflict_type = conflicts.PathConflict,
458
_conflict_type = conflicts.PathConflict
441
460
def do_nothing(self):
446
# Each side dict additionally defines:
447
# - path path involved (can be '<deleted>')
463
# Each side dict additionally defines:
464
# - path path involved (can be '<deleted>')
466
scenarios = mirror_scenarios(
450
468
# File renamed/deleted
451
469
(dict(_base_actions='create_file'),
484
502
dict(actions='rename_dir2', check='dir_renamed2',
485
503
path='new-dir2', file_id='dir-id')),),
487
return mirror_scenarios(base_scenarios)
489
506
def do_create_file(self):
490
507
return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
569
586
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
571
_conflict_type = conflicts.DuplicateEntry,
588
_conflict_type = conflicts.DuplicateEntry
575
# Each side dict additionally defines:
590
scenarios = mirror_scenarios(
579
592
# File created with different file-ids
580
593
(dict(_base_actions='nothing'),
581
594
('filea_created',
625
637
# tests MissingParent resolution :-/
631
$ bzr commit -m 'Create trunk'
644
$ bzr commit -m 'Create trunk' -q
633
645
$ echo 'trunk content' >dir/file
635
$ bzr commit -m 'Add dir/file in trunk'
637
$ bzr branch . -r 1 ../branch
646
$ bzr add -q dir/file
647
$ bzr commit -q -m 'Add dir/file in trunk'
648
$ bzr branch -q . -r 1 ../branch
640
$ bzr commit -m 'Remove dir in branch'
651
$ bzr commit -q -m 'Remove dir in branch'
642
652
$ bzr merge ../trunk
650
660
def test_take_this(self):
651
661
self.run_script("""
662
$ bzr rm -q dir --force
653
663
$ bzr resolve dir
654
$ bzr commit --strict -m 'No more conflicts nor unknown files'
664
2>2 conflict(s) resolved, 0 remaining
665
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
657
668
def test_take_other(self):
658
669
self.run_script("""
659
670
$ bzr resolve dir
660
$ bzr commit --strict -m 'No more conflicts nor unknown files'
671
2>2 conflict(s) resolved, 0 remaining
672
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
670
683
$ echo 'trunk content' >dir/file
672
$ bzr commit -m 'Create trunk'
685
$ bzr commit -m 'Create trunk' -q
674
686
$ echo 'trunk content' >dir/file2
676
$ bzr commit -m 'Add dir/file2 in branch'
678
$ bzr branch . -r 1 ../branch
687
$ bzr add -q dir/file2
688
$ bzr commit -q -m 'Add dir/file2 in branch'
689
$ bzr branch -q . -r 1 ../branch
680
$ bzr rm dir/file --force
682
$ bzr commit -m 'Remove dir/file'
691
$ bzr rm -q dir/file --force
693
$ bzr commit -q -m 'Remove dir/file'
684
694
$ bzr merge ../trunk
692
702
def test_keep_them_all(self):
693
703
self.run_script("""
694
704
$ bzr resolve dir
695
$ bzr commit --strict -m 'No more conflicts nor unknown files'
705
2>2 conflict(s) resolved, 0 remaining
706
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
698
709
def test_adopt_child(self):
699
710
self.run_script("""
700
$ bzr mv dir/file2 file2
711
$ bzr mv -q dir/file2 file2
712
$ bzr rm -q dir --force
702
713
$ bzr resolve dir
703
$ bzr commit --strict -m 'No more conflicts nor unknown files'
714
2>2 conflict(s) resolved, 0 remaining
715
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
706
718
def test_kill_them_all(self):
707
719
self.run_script("""
720
$ bzr rm -q dir --force
709
721
$ bzr resolve dir
710
$ bzr commit --strict -m 'No more conflicts nor unknown files'
722
2>2 conflict(s) resolved, 0 remaining
723
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
713
726
def test_resolve_taking_this(self):
714
727
self.run_script("""
715
728
$ bzr resolve --take-this dir
716
$ bzr commit --strict -m 'No more conflicts nor unknown files'
730
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
719
733
def test_resolve_taking_other(self):
720
734
self.run_script("""
721
735
$ bzr resolve --take-other dir
722
$ bzr commit --strict -m 'No more conflicts nor unknown files'
737
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
732
748
$ 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
750
$ bzr commit -m 'Create trunk' -q
751
$ bzr rm -q dir/file --force
752
$ bzr rm -q dir --force
753
$ bzr commit -q -m 'Remove dir/file'
754
$ bzr branch -q . -r 1 ../branch
742
756
$ echo 'branch content' >dir/file2
744
$ bzr commit -m 'Add dir/file2 in branch'
757
$ bzr add -q dir/file2
758
$ bzr commit -q -m 'Add dir/file2 in branch'
746
759
$ bzr merge ../trunk
748
761
2>Conflict: can't delete dir because it is not empty. Not deleting.
753
766
def test_keep_them_all(self):
754
767
self.run_script("""
755
768
$ bzr resolve dir
756
$ bzr commit --strict -m 'No more conflicts nor unknown files'
769
2>2 conflict(s) resolved, 0 remaining
770
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
759
773
def test_adopt_child(self):
760
774
self.run_script("""
761
$ bzr mv dir/file2 file2
775
$ bzr mv -q dir/file2 file2
776
$ bzr rm -q dir --force
763
777
$ bzr resolve dir
764
$ bzr commit --strict -m 'No more conflicts nor unknown files'
778
2>2 conflict(s) resolved, 0 remaining
779
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
767
782
def test_kill_them_all(self):
768
783
self.run_script("""
784
$ bzr rm -q dir --force
770
785
$ bzr resolve dir
771
$ bzr commit --strict -m 'No more conflicts nor unknown files'
786
2>2 conflict(s) resolved, 0 remaining
787
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
774
790
def test_resolve_taking_this(self):
775
791
self.run_script("""
776
792
$ bzr resolve --take-this dir
777
$ bzr commit --strict -m 'No more conflicts nor unknown files'
793
2>2 conflict(s) resolved, 0 remaining
794
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
780
797
def test_resolve_taking_other(self):
781
798
self.run_script("""
782
799
$ bzr resolve --take-other dir
783
$ bzr commit --strict -m 'No more conflicts nor unknown files'
802
2>2 conflict(s) resolved, 0 remaining
803
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
787
807
class TestResolveParentLoop(TestParametrizedResolveConflicts):
789
_conflict_type = conflicts.ParentLoop,
809
_conflict_type = conflicts.ParentLoop
791
811
_this_args = None
792
812
_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'
814
# Each side dict additionally defines:
815
# - dir_id: the directory being moved
816
# - target_id: The target directory
817
# - xfail: whether the test is expected to fail if the action is
818
# involved as 'other'
819
scenarios = mirror_scenarios(
802
821
# Dirs moved into each other
803
822
(dict(_base_actions='create_dir1_dir2'),
804
823
('dir1_into_dir2',
815
834
('dir3_into_dir2',
816
835
dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
836
dir_id='dir3-id', target_id='dir2-id', xfail=True))),
819
return mirror_scenarios(base_scenarios)
821
839
def do_create_dir1_dir2(self):
822
840
return [('add', ('dir1', 'dir1-id', 'directory', '')),
887
$ bzr commit -m 'Create trunk'
907
$ bzr commit -m 'Create trunk' -q
888
908
$ echo "Boing" >foo/bar
890
$ bzr commit -m 'Add foo/bar'
892
$ bzr branch . -r 1 ../branch
910
$ bzr commit -q -m 'Add foo/bar'
911
$ bzr branch -q . -r 1 ../branch
895
914
$ echo "Boo!" >foo
896
$ bzr commit -m 'foo is now a file'
915
$ bzr commit -q -m 'foo is now a file'
898
916
$ bzr merge ../trunk
900
918
2>RK foo => foo.new/
907
925
def test_take_this(self):
908
926
self.run_script("""
909
$ bzr rm foo.new --force
927
$ bzr rm -q foo.new --force
910
928
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
929
# aside ? -- vila 090916
913
931
$ bzr resolve foo.new
914
$ bzr commit --strict -m 'No more conflicts nor unknown files'
932
2>1 conflict(s) resolved, 0 remaining
933
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
917
936
def test_take_other(self):
918
937
self.run_script("""
938
$ bzr rm -q foo --force
939
$ bzr mv -q foo.new foo
921
940
$ bzr resolve foo
922
$ bzr commit --strict -m 'No more conflicts nor unknown files'
941
2>1 conflict(s) resolved, 0 remaining
942
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
925
945
def test_resolve_taking_this(self):
926
946
self.run_script("""
927
947
$ bzr resolve --take-this foo.new
928
$ bzr commit --strict -m 'No more conflicts nor unknown files'
949
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
931
952
def test_resolve_taking_other(self):
932
953
self.run_script("""
933
954
$ bzr resolve --take-other foo.new
934
$ bzr commit --strict -m 'No more conflicts nor unknown files'
956
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
944
966
self.run_script("""
948
$ bzr commit -m 'Create trunk'
972
$ bzr commit -m 'Create trunk' -q
950
974
$ echo "Boo!" >foo
951
$ bzr commit -m 'foo is now a file'
953
$ bzr branch . -r 1 ../branch
975
$ bzr commit -m 'foo is now a file' -q
976
$ bzr branch -q . -r 1 ../branch -q
955
978
$ echo "Boing" >foo/bar
957
$ bzr commit -m 'Add foo/bar'
979
$ bzr add -q foo/bar -q
980
$ bzr commit -m 'Add foo/bar' -q
959
981
$ bzr merge ../trunk
960
982
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]