author | HG Automerge |
Thu, 24 Nov 2016 21:56:31 +0000 | |
branch | jv |
changeset 1015 | 7b6393ea3d52 |
parent 803 | 5ae881a3d7c6 |
child 1121 | c5661215109c |
permissions | -rw-r--r-- |
16 | 1 |
"{ Package: 'stx:goodies/monticello/test' }" |
2 |
||
3 |
MCTestCase subclass:#MCMergingTest |
|
4 |
instanceVariableNames:'conflictBlock conflicts' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
803
5ae881a3d7c6
Tests moved to category SCM-Monticello-Tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16
diff
changeset
|
7 |
category:'SCM-Monticello-Tests' |
16 | 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 |
|l r| |
|
33 |
l _ #removed. |
|
34 |
r _ #removed. |
|
35 |
aConflict localDefinition ifNotNilDo: [:d | l _ d token]. |
|
36 |
aConflict remoteDefinition ifNotNilDo: [:d | 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 |
! |
|
46 |
||
47 |
snapshotWithElements: anArray |
|
48 |
^ MCSnapshot |
|
49 |
fromDefinitions: (anArray collect: [:t | self mockToken: t]) |
|
50 |
! ! |
|
51 |
||
52 |
!MCMergingTest methodsFor:'tests'! |
|
53 |
||
54 |
testAdditiveConflictlessMerge |
|
55 |
self |
|
56 |
assertMerge: #(a1 b1) |
|
57 |
with: #(a1 c1) |
|
58 |
base: #(a1) |
|
59 |
||
60 |
gives: #(a1 b1 c1) |
|
61 |
conflicts: #() |
|
62 |
! |
|
63 |
||
64 |
testComplexConflictlessMerge |
|
65 |
self |
|
66 |
assertMerge: #(a1 b1 d1) |
|
67 |
with: #(a2 c1) |
|
68 |
base: #(a1 c1 d1) |
|
69 |
||
70 |
gives: #(a2 b1) |
|
71 |
conflicts: #() |
|
72 |
! |
|
73 |
||
74 |
testIdenticalModification |
|
75 |
self |
|
76 |
assertMerge: #(a2 b1) |
|
77 |
with: #(a2 b1) |
|
78 |
base: #(a1 b1) |
|
79 |
||
80 |
gives: #(a2 b1) |
|
81 |
conflicts: #() |
|
82 |
! |
|
83 |
||
84 |
testLocalModifyRemoteRemove |
|
85 |
self assertMerge: #(a2 b1) |
|
86 |
with: #(b1) |
|
87 |
base: #(a1 b1) |
|
88 |
||
89 |
gives: #(b1) |
|
90 |
conflicts: #((removed a2)). |
|
91 |
||
92 |
self assertMerge: #(a1 b1) |
|
93 |
with: #(b1) |
|
94 |
base: #(a2 b1) |
|
95 |
||
96 |
gives: #(b1) |
|
97 |
conflicts: #((removed a1)). |
|
98 |
! |
|
99 |
||
100 |
testLocalRemoveRemoteModify |
|
101 |
self assertMerge: #(b1) |
|
102 |
with: #(a1 b1) |
|
103 |
base: #(a2 b1) |
|
104 |
||
105 |
gives: #(a1 b1) |
|
106 |
conflicts: #((a1 removed)). |
|
107 |
||
108 |
self assertMerge: #(b1) |
|
109 |
with: #(a2 b1) |
|
110 |
base: #(a1 b1) |
|
111 |
||
112 |
gives: #(a2 b1) |
|
113 |
conflicts: #((a2 removed)). |
|
114 |
! |
|
115 |
||
116 |
testMultiPackageMerge |
|
117 |
| merger | |
|
118 |
conflicts _ #(). |
|
119 |
merger _ MCThreeWayMerger new. |
|
120 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)). |
|
121 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))). |
|
122 |
merger applyPatch: ((self snapshotWithElements: #(a2 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))). |
|
123 |
merger conflicts do: [:ea | self handleConflict: ea]. |
|
124 |
self assert: merger mergedSnapshot definitions hasElements: #(a2 b1). |
|
125 |
self assert: conflicts isEmpty |
|
126 |
! |
|
127 |
||
128 |
testMultiPackageMerge2 |
|
129 |
| merger | |
|
130 |
conflicts _ #(). |
|
131 |
merger _ MCThreeWayMerger new. |
|
132 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)). |
|
133 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))). |
|
134 |
merger applyPatch: ((self snapshotWithElements: #(a1 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))). |
|
135 |
merger conflicts do: [:ea | self handleConflict: ea]. |
|
136 |
self assert: merger mergedSnapshot definitions hasElements: #(a1 b1). |
|
137 |
self assert: conflicts isEmpty |
|
138 |
! |
|
139 |
||
140 |
testMultiPackageMerge3 |
|
141 |
| merger | |
|
142 |
conflicts _ #(). |
|
143 |
merger _ MCThreeWayMerger new. |
|
144 |
merger addBaseSnapshot: (self snapshotWithElements: #(a1 b1)). |
|
145 |
merger applyPatch: ((self snapshotWithElements: #(a1 b1)) patchRelativeToBase: (self snapshotWithElements: #(b1))). |
|
146 |
merger applyPatch: ((self snapshotWithElements: #()) patchRelativeToBase: (self snapshotWithElements: #(a1))). |
|
147 |
merger conflicts do: [:ea | self handleConflict: ea]. |
|
148 |
self assert: merger mergedSnapshot definitions hasElements: #(a1 b1). |
|
149 |
self assert: conflicts isEmpty |
|
150 |
! |
|
151 |
||
152 |
testMultipleConflicts |
|
153 |
self assertMerge: #(a1 b3 c1) |
|
154 |
with: #(a1 b2 d1) |
|
155 |
base: #(a1 b1 c2) |
|
156 |
||
157 |
gives: #(a1 b3 d1) |
|
158 |
conflicts: #((removed c1) (b2 b3)) |
|
159 |
! |
|
160 |
||
161 |
testSimultaneousModification |
|
162 |
self assertMerge: #(a2) |
|
163 |
with: #(a3) |
|
164 |
base: #(a1) |
|
165 |
||
166 |
gives: #(a3) |
|
167 |
conflicts: #((a3 a2)). |
|
168 |
! |
|
169 |
||
170 |
testSimultaneousRemove |
|
171 |
self assertMerge: #(a1) |
|
172 |
with: #(a1) |
|
173 |
base: #(a1 b1) |
|
174 |
||
175 |
gives: #(a1) |
|
176 |
conflicts: #() |
|
177 |
! |
|
178 |
||
179 |
testSubtractiveConflictlessMerge |
|
180 |
self assertMerge: #(a1 b1) |
|
181 |
with: #() |
|
182 |
base: #(a1) |
|
183 |
||
184 |
gives: #(b1) |
|
185 |
conflicts: #() |
|
186 |
! ! |
|
187 |
||
188 |
!MCMergingTest class methodsFor:'documentation'! |
|
189 |
||
190 |
version |
|
803
5ae881a3d7c6
Tests moved to category SCM-Monticello-Tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16
diff
changeset
|
191 |
^ '$Header: /cvs/stx/stx/goodies/monticello/test/MCMergingTest.st,v 1.2 2013-05-29 00:00:02 vrany Exp $' |
16 | 192 |
! ! |
803
5ae881a3d7c6
Tests moved to category SCM-Monticello-Tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16
diff
changeset
|
193 |