275
|
1 |
"{ Package: 'stx:goodies/monticello' }"
|
|
2 |
|
|
3 |
MCTestCase subclass:#MCMergingTest
|
|
4 |
instanceVariableNames:'conflictBlock conflicts'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Monticello-Tests'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!MCMergingTest methodsFor:'asserting'!
|
|
12 |
|
|
13 |
assert: aCollection hasElements: anArray
|
|
14 |
self assert: (aCollection collect: [:ea | ea token]) asSet = anArray asSet
|
|
15 |
!
|
|
16 |
|
|
17 |
assertMerge: local with: remote base: ancestor gives: result conflicts: conflictResult
|
|
18 |
| merger |
|
|
19 |
conflicts := #().
|
|
20 |
merger := MCThreeWayMerger
|
|
21 |
base: (self snapshotWithElements: local)
|
|
22 |
target: (self snapshotWithElements: remote)
|
|
23 |
ancestor: (self snapshotWithElements: ancestor).
|
|
24 |
merger conflicts do: [:ea | self handleConflict: ea].
|
|
25 |
self assert: merger mergedSnapshot definitions hasElements: result.
|
|
26 |
self assert: conflicts asSet = conflictResult asSet.
|
|
27 |
! !
|
|
28 |
|
|
29 |
!MCMergingTest methodsFor:'emulating'!
|
|
30 |
|
|
31 |
handleConflict: aConflict
|
|
32 |
| d l r|
|
|
33 |
l := #removed.
|
|
34 |
r := #removed.
|
|
35 |
(d := aConflict localDefinition) ifNotNil: [ l := d token].
|
|
36 |
(d := aConflict remoteDefinition) ifNotNil: [ r := d token].
|
|
37 |
conflicts := conflicts copyWith: (Array with: r with: l).
|
|
38 |
(l = #removed or: [r = #removed])
|
|
39 |
ifTrue: [aConflict chooseRemote]
|
|
40 |
ifFalse:
|
|
41 |
[l > r
|
|
42 |
ifTrue: [aConflict chooseLocal]
|
|
43 |
ifFalse: [aConflict chooseRemote]]
|
|
44 |
|
|
45 |
"Modified: / 12-09-2010 / 17:38:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
46 |
!
|
|
47 |
|
|
48 |
snapshotWithElements: anArray
|
|
49 |
^ MCSnapshot
|
|
50 |
fromDefinitions: (anArray collect: [:t | self mockToken: t])
|
|
51 |
! !
|
|
52 |
|
|
53 |
!MCMergingTest methodsFor:'tests'!
|
|
54 |
|
|
55 |
testAdditiveConflictlessMerge
|
|
56 |
self
|
|
57 |
assertMerge: #(a1 b1)
|
|
58 |
with: #(a1 c1)
|
|
59 |
base: #(a1)
|
|
60 |
|
|
61 |
gives: #(a1 b1 c1)
|
|
62 |
conflicts: #()
|
|
63 |
!
|
|
64 |
|
|
65 |
testComplexConflictlessMerge
|
|
66 |
self
|
|
67 |
assertMerge: #(a1 b1 d1)
|
|
68 |
with: #(a2 c1)
|
|
69 |
base: #(a1 c1 d1)
|
|
70 |
|
|
71 |
gives: #(a2 b1)
|
|
72 |
conflicts: #()
|
|
73 |
!
|
|
74 |
|
|
75 |
testIdenticalModification
|
|
76 |
self
|
|
77 |
assertMerge: #(a2 b1)
|
|
78 |
with: #(a2 b1)
|
|
79 |
base: #(a1 b1)
|
|
80 |
|
|
81 |
gives: #(a2 b1)
|
|
82 |
conflicts: #()
|
|
83 |
!
|
|
84 |
|
|
85 |
testLocalModifyRemoteRemove
|
|
86 |
self assertMerge: #(a2 b1)
|
|
87 |
with: #(b1)
|
|
88 |
base: #(a1 b1)
|
|
89 |
|
|
90 |
gives: #(b1)
|
|
91 |
conflicts: #((removed a2)).
|
|
92 |
|
|
93 |
self assertMerge: #(a1 b1)
|
|
94 |
with: #(b1)
|
|
95 |
base: #(a2 b1)
|
|
96 |
|
|
97 |
gives: #(b1)
|
|
98 |
conflicts: #((removed a1)).
|
|
99 |
!
|
|
100 |
|
|
101 |
testLocalRemoveRemoteModify
|
|
102 |
self assertMerge: #(b1)
|
|
103 |
with: #(a1 b1)
|
|
104 |
base: #(a2 b1)
|
|
105 |
|
|
106 |
gives: #(a1 b1)
|
|
107 |
conflicts: #((a1 removed)).
|
|
108 |
|
|
109 |
self assertMerge: #(b1)
|
|
110 |
with: #(a2 b1)
|
|
111 |
base: #(a1 b1)
|
|
112 |
|
|
113 |
gives: #(a2 b1)
|
|
114 |
conflicts: #((a2 removed)).
|
|
115 |
!
|
|
116 |
|
|
117 |
testMultiPackageMerge
|
|
118 |
| merger |
|
|
119 |
conflicts := #().
|
|
120 |
merger := MCThreeWayMerger new.
|
|
121 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)).
|
|
122 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))).
|
|
123 |
merger applyPatch: ((self snapshotWithElements: #(a2 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))).
|
|
124 |
merger conflicts do: [:ea | self handleConflict: ea].
|
|
125 |
self assert: merger mergedSnapshot definitions hasElements: #(a2 b1).
|
|
126 |
self assert: conflicts isEmpty
|
|
127 |
!
|
|
128 |
|
|
129 |
testMultiPackageMerge2
|
|
130 |
| merger |
|
|
131 |
conflicts := #().
|
|
132 |
merger := MCThreeWayMerger new.
|
|
133 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)).
|
|
134 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))).
|
|
135 |
merger applyPatch: ((self snapshotWithElements: #(a1 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))).
|
|
136 |
merger conflicts do: [:ea | self handleConflict: ea].
|
|
137 |
self assert: merger mergedSnapshot definitions hasElements: #(a1 b1).
|
|
138 |
self assert: conflicts isEmpty
|
|
139 |
!
|
|
140 |
|
|
141 |
testMultiPackageMerge3
|
|
142 |
| merger |
|
|
143 |
conflicts := #().
|
|
144 |
merger := MCThreeWayMerger new.
|
|
145 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)).
|
|
146 |
merger applyPatch: ((self snapshotWithElements: #(a1 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))).
|
|
147 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))).
|
|
148 |
merger conflicts do: [:ea | self handleConflict: ea].
|
|
149 |
self assert: merger mergedSnapshot definitions hasElements: #(a1 b1).
|
|
150 |
self assert: conflicts isEmpty
|
|
151 |
!
|
|
152 |
|
|
153 |
testMultipleConflicts
|
|
154 |
self assertMerge: #(a1 b3 c1)
|
|
155 |
with: #(a1 b2 d1)
|
|
156 |
base: #(a1 b1 c2)
|
|
157 |
|
|
158 |
gives: #(a1 b3 d1)
|
|
159 |
conflicts: #((removed c1) (b2 b3))
|
|
160 |
|
|
161 |
!
|
|
162 |
|
|
163 |
testSimultaneousModification
|
|
164 |
self assertMerge: #(a2)
|
|
165 |
with: #(a3)
|
|
166 |
base: #(a1)
|
|
167 |
|
|
168 |
gives: #(a3)
|
|
169 |
conflicts: #((a3 a2)).
|
|
170 |
!
|
|
171 |
|
|
172 |
testSimultaneousRemove
|
|
173 |
self assertMerge: #(a1)
|
|
174 |
with: #(a1)
|
|
175 |
base: #(a1 b1)
|
|
176 |
|
|
177 |
gives: #(a1)
|
|
178 |
conflicts: #()
|
|
179 |
!
|
|
180 |
|
|
181 |
testSubtractiveConflictlessMerge
|
|
182 |
self assertMerge: #(a1 b1)
|
|
183 |
with: #()
|
|
184 |
base: #(a1)
|
|
185 |
|
|
186 |
gives: #(b1)
|
|
187 |
conflicts: #()
|
|
188 |
! !
|
|
189 |
|
|
190 |
!MCMergingTest class methodsFor:'documentation'!
|
|
191 |
|
|
192 |
version
|
|
193 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCMergingTest.st,v 1.1 2011-08-20 12:03:03 cg Exp $'
|
|
194 |
!
|
|
195 |
|
|
196 |
version_CVS
|
|
197 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCMergingTest.st,v 1.1 2011-08-20 12:03:03 cg Exp $'
|
|
198 |
!
|
|
199 |
|
|
200 |
version_SVN
|
|
201 |
^ '§Id: MCMergingTest.st 8 2010-09-12 17:15:52Z vranyj1 §'
|
|
202 |
! !
|