author | Patrik Svestka <patrik.svestka@gmail.com> |
Wed, 17 Feb 2021 15:24:09 +0100 | |
branch | jv |
changeset 4568 | 524471ef6575 |
parent 3011 | 1997ff6e7e55 |
permissions | -rw-r--r-- |
1445 | 1 |
" |
2 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1267 | 13 |
"{ Package: 'stx:libbasic3' }" |
14 |
||
15 |
"{ NameSpace: Packages }" |
|
16 |
||
17 |
AbstractTestCases subclass:#PackageManagerTests |
|
18 |
instanceVariableNames:'packageManager defaultPackage' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'Package-Managers' |
|
22 |
! |
|
23 |
||
24 |
!PackageManagerTests class methodsFor:'documentation'! |
|
25 |
||
1445 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 2003 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
1267 | 40 |
documentation |
41 |
" |
|
42 |
documentation to be added. |
|
43 |
||
44 |
[author:] |
|
45 |
(james@miraculix) |
|
46 |
||
47 |
[instance variables:] |
|
48 |
||
49 |
[class variables:] |
|
50 |
||
51 |
[see also:] |
|
52 |
||
53 |
" |
|
54 |
! |
|
55 |
||
56 |
history |
|
57 |
"Created: / 24.1.2003 / 16:15:21 / james" |
|
58 |
! ! |
|
59 |
||
60 |
!PackageManagerTests methodsFor:'initialize / release'! |
|
61 |
||
62 |
initialize |
|
63 |
||
64 |
packageManager ifNil:[ |
|
65 |
packageManager := self packageManager. |
|
66 |
]. |
|
67 |
||
68 |
defaultPackage ifNil:[ |
|
69 |
defaultPackage := packageManager defaultPackage. |
|
70 |
]. |
|
71 |
! |
|
72 |
||
73 |
setUp |
|
74 |
"common setup - invoked before testing" |
|
1273 | 75 |
super setUp. |
1267 | 76 |
self setUpUsedClasses. |
77 |
! |
|
78 |
||
79 |
setUpAllForQWERTY |
|
80 |
| class copyQWERTYDic| |
|
81 |
||
82 |
(class := Smalltalk at:#QWERTY) ifNil:[ |
|
83 |
self createClassNamed:#QWERTY. |
|
84 |
(class := Smalltalk at:#QWERTY). |
|
85 |
]. |
|
86 |
copyQWERTYDic := QWERTY methodDictionary copy. |
|
87 |
copyQWERTYDic removeKey:#aDummyMethod ifAbsent:[]. |
|
88 |
copyQWERTYDic removeKey:#aDummyMethod2 ifAbsent:[]. |
|
89 |
copyQWERTYDic removeKey:#aDummyMethod3 ifAbsent:[]. |
|
90 |
copyQWERTYDic keysAndValuesDo:[:key :value | |
|
91 |
QWERTY methodDictionary removeKey:key. |
|
92 |
]. |
|
93 |
||
94 |
(class compiledMethodAt:#aDummyMethod) ifNil:[ |
|
95 |
self createMethodFor:QWERTY source:'aDummyMethod 1 + 1.'. |
|
96 |
]. |
|
97 |
(class compiledMethodAt:#aDummyMethod2) ifNil:[ |
|
98 |
self createMethodFor:QWERTY source:'aDummyMethod2 1 + 1.'. |
|
99 |
]. |
|
100 |
(class compiledMethodAt:#aDummyMethod3) ifNil:[ |
|
101 |
self createMethodFor:QWERTY source:'aDummyMethod3 1 + 1.'. |
|
102 |
]. |
|
103 |
packageManager moveClass:QWERTY toPackage:defaultPackage. |
|
104 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod) toPackage:defaultPackage. |
|
105 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod2) toPackage:defaultPackage. |
|
106 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod3) toPackage:defaultPackage. |
|
107 |
! |
|
108 |
||
109 |
setUpAllForQWERTZ |
|
110 |
| class copyQWERTZDic| |
|
111 |
(class := Smalltalk at:#QWERTZ) ifNil:[ |
|
112 |
self createClassNamed:#QWERTZ. |
|
113 |
(class := Smalltalk at:#QWERTZ) |
|
114 |
]. |
|
115 |
||
116 |
copyQWERTZDic := QWERTZ methodDictionary copy. |
|
117 |
copyQWERTZDic removeKey:#aDummyMethod ifAbsent:[]. |
|
118 |
copyQWERTZDic removeKey:#aDummyMethod2 ifAbsent:[]. |
|
119 |
copyQWERTZDic removeKey:#aDummyMethod3 ifAbsent:[]. |
|
120 |
copyQWERTZDic keysAndValuesDo:[:key :value | |
|
121 |
QWERTZ methodDictionary removeKey:key. |
|
122 |
]. |
|
123 |
||
124 |
(class compiledMethodAt:#aDummyMethod) ifNil:[ |
|
125 |
self createMethodFor:QWERTZ source:'aDummyMethod 1 + 1.'. |
|
126 |
]. |
|
127 |
(class compiledMethodAt:#aDummyMethod2) ifNil:[ |
|
128 |
self createMethodFor:QWERTZ source:'aDummyMethod2 1 + 1.'. |
|
129 |
]. |
|
130 |
(class compiledMethodAt:#aDummyMethod3) ifNil:[ |
|
131 |
self createMethodFor:QWERTZ source:'aDummyMethod3 1 + 1.'. |
|
132 |
]. |
|
133 |
||
134 |
packageManager moveClass:QWERTZ toPackage:defaultPackage. |
|
135 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod) toPackage:defaultPackage. |
|
136 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod2) toPackage:defaultPackage. |
|
137 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod3) toPackage:defaultPackage. |
|
138 |
! |
|
139 |
||
140 |
setUpUsedClasses |
|
141 |
"common setup - invoked before testing" |
|
142 |
| | |
|
143 |
self setUpAllForQWERTZ. |
|
144 |
self setUpAllForQWERTY. |
|
145 |
! |
|
146 |
||
147 |
tearDown |
|
148 |
"common cleanup - invoked after testing" |
|
149 |
||
150 |
"move class package to where it was" |
|
151 |
super tearDown |
|
152 |
! ! |
|
153 |
||
154 |
!PackageManagerTests methodsFor:'test - adding and removing'! |
|
155 |
||
156 |
test_addClass_toPackage |
|
157 |
| packageTestCases oldPackage| |
|
158 |
"prerequisites to test" |
|
159 |
"QWERTZ is in workingPackage" |
|
160 |
self assert:(packageManager packageNamed:(QWERTZ package)) == defaultPackage. |
|
161 |
[ |
|
162 |
"set up" |
|
163 |
oldPackage := packageManager newPackageNamed:#'oldPackage'. |
|
164 |
packageManager moveClass:QWERTZ toPackage:oldPackage. |
|
165 |
||
166 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'. |
|
167 |
oldPackage := packageManager packageNamed:(QWERTZ package). |
|
168 |
packageManager addClass:QWERTZ toPackage:packageTestCases. |
|
169 |
||
170 |
self assert: (packageTestCases isDirty). |
|
171 |
self assert: (packageTestCases isInstalled). |
|
172 |
self assert: (packageTestCases packagedClassNamed:#QWERTZ) notNil. |
|
173 |
self assert: (packageTestCases packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
174 |
self assert: (oldPackage packagedClassNamed:#QWERTZ) notNil. |
|
175 |
self shouldnt: (oldPackage packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
176 |
||
177 |
] ensure: |
|
178 |
[ |
|
179 |
packageTestCases ifNotNil:[ |
|
180 |
packageManager removePackage:packageTestCases. |
|
181 |
]. |
|
182 |
oldPackage ifNotNil:[ |
|
183 |
packageManager removePackage:oldPackage. |
|
184 |
]. |
|
185 |
] |
|
186 |
! |
|
187 |
||
188 |
test_addMethod_toPackage |
|
189 |
|method1 method2 packageTestCases| |
|
190 |
"prerequisites to test" |
|
191 |
"none at the moment" |
|
192 |
[ |
|
193 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'. |
|
194 |
method1 := (QWERTZ compiledMethodAt:#aDummyMethod). |
|
195 |
method2 := (QWERTZ compiledMethodAt:#aDummyMethod2). |
|
196 |
||
197 |
packageManager addMethod:method1 toPackage:packageTestCases. |
|
198 |
packageManager addMethod:method2 toPackage:packageTestCases. |
|
199 |
||
200 |
self assert:(packageTestCases isDirty). |
|
201 |
self assert:(packageTestCases isInstalled). |
|
202 |
] ensure: |
|
203 |
[ |
|
204 |
packageTestCases ifNotNil:[ |
|
205 |
packageManager removePackage:packageTestCases. |
|
206 |
]. |
|
207 |
] |
|
208 |
! |
|
209 |
||
210 |
test_moveMethod_toPackage |
|
211 |
| packageTestCases method1 method2| |
|
212 |
"prerequisites to test" |
|
213 |
||
214 |
[ |
|
215 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'. |
|
216 |
method1 := (QWERTZ compiledMethodAt:#aDummyMethod). |
|
217 |
method2 := (QWERTZ compiledMethodAt:#aDummyMethod2). |
|
218 |
packageManager moveMethod:method1 toPackage:packageTestCases. |
|
219 |
packageManager moveMethod:method2 toPackage:packageTestCases. |
|
220 |
||
221 |
self assert:(packageTestCases isDirty). |
|
222 |
self assert:(packageTestCases isInstalled). |
|
223 |
||
224 |
] ensure: |
|
225 |
[ |
|
226 |
packageTestCases ifNotNil:[ |
|
227 |
packageManager removePackage:packageTestCases. |
|
228 |
]. |
|
229 |
] |
|
230 |
! |
|
231 |
||
232 |
test_removeClassNamed_fromPackage |
|
233 |
| packageTestCases | |
|
234 |
"prerequisites to test" |
|
235 |
||
236 |
[ |
|
237 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'. |
|
238 |
packageManager moveClass:QWERTZ toPackage:packageTestCases. |
|
239 |
packageManager removeClassNamed:#QWERTZ fromPackage:packageTestCases. |
|
240 |
||
241 |
"test the class was completely removed!!" |
|
242 |
self assert:(Smalltalk at:#QWERTZ) notNil. |
|
243 |
||
244 |
"test that the package was changed" |
|
245 |
self assert:(packageTestCases isDirty). |
|
246 |
"test that the package still is installed" |
|
247 |
self assert:(packageTestCases isInstalled). |
|
248 |
"test that the class was removed from packageTestCases" |
|
249 |
self shouldnt:(packageTestCases includesPackagedClassNamed:#QWERTZ). |
|
250 |
||
251 |
"the class was moved where. Check it is here" |
|
252 |
self assert:(packageManager defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
253 |
] ensure: |
|
254 |
[ |
|
255 |
packageTestCases ifNotNil:[ |
|
256 |
packageManager removePackage:packageTestCases. |
|
257 |
]. |
|
258 |
] |
|
259 |
! |
|
260 |
||
261 |
test_removeClass_fromPackage |
|
262 |
"to test that when a " |
|
263 |
| oldPackage | |
|
264 |
[ |
|
265 |
"pre-setup" |
|
266 |
"i expect setUp should do this!!" |
|
267 |
self assert:(packageManager defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
268 |
oldPackage := Package packageManager newPackageNamed:#'oldPackage'. |
|
269 |
packageManager moveClassNamed:#QWERTZ fromPackage:defaultPackage toPackage:oldPackage. |
|
270 |
||
271 |
"prerequisites" |
|
272 |
self shouldnt: (packageManager defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
273 |
self assert: (oldPackage includesPackagedClassNamed:#QWERTZ). |
|
274 |
self shouldnt: (defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
275 |
||
276 |
"check that the added class in oldPackage is in smalltalk |
|
277 |
and that that oldPackage has a packaged class representing it." |
|
278 |
self assert: (oldPackage packagedClassNamed:#QWERTZ) notNil. |
|
279 |
self assert: (oldPackage packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
280 |
||
281 |
packageManager removeClassNamed:#QWERTZ fromPackage:oldPackage. |
|
282 |
||
283 |
"check that oldPackage has NOT got a packaged class representing it." |
|
284 |
self assert: (oldPackage packagedClassNamed:#QWERTZ) isNil. |
|
285 |
"check that the deleted class is then stored in workingClass" |
|
286 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) notNil. |
|
287 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
288 |
||
289 |
] ensure: |
|
290 |
[ |
|
291 |
oldPackage ifNotNil:[ |
|
292 |
packageManager removePackage:oldPackage. |
|
293 |
]. |
|
294 |
]. |
|
295 |
! |
|
296 |
||
297 |
test_removeClass_fromPackage2 |
|
298 |
"Test: |
|
299 |
When the manager removes the responsibility of a class from a package via: |
|
300 |
PackageManager>>removeClass:fromPackage: |
|
301 |
||
302 |
If a package overid another package with a class, and this package was |
|
303 |
deleted, the overriden information has to be updated. |
|
304 |
||
305 |
Sequence of events |
|
306 |
package1 owns class1 |
|
307 |
package2 overrides class1 |
|
308 |
package2 owns class1 |
|
309 |
package1 stores class1 as overriddenBy: package2 |
|
310 |
packageManager remove:class1 from:package2 |
|
311 |
'at the moment' |
|
312 |
package2 no longer owns class1 |
|
313 |
package stores class1 as overriddenBy:package2 'WRONG!!!!' |
|
314 |
||
315 |
There are two ways of going from here: |
|
316 |
||
317 |
1) package1 brings its version forward redefining the smalltalk version |
|
318 |
2) defaultPackage now owns this definition of class1 and package1 must update |
|
319 |
this change. |
|
320 |
||
321 |
I choose (2) as (1) may confuse the user. (2) has the advanatage that the Smalltalk |
|
322 |
dictionary does not change - and is what i would expect... |
|
323 |
" |
|
324 |
| package1 package2 | |
|
325 |
"i expect setUp should do this!!" |
|
326 |
self assert:(defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
327 |
[ |
|
328 |
"pre-setup" |
|
329 |
package1 := Package packageManager newPackageNamed:#'package1'. |
|
330 |
package2 := Package packageManager newPackageNamed:#'package2'. |
|
331 |
packageManager moveClassNamed:#QWERTZ fromPackage:defaultPackage toPackage:package1. |
|
332 |
||
333 |
"prerequisites" |
|
334 |
self shouldnt: (defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
335 |
self assert: (package1 includesPackagedClassNamed:#QWERTZ). |
|
336 |
||
337 |
"check that the added class in package1 is in smalltalk |
|
338 |
and that that package1 has a packaged class representing it." |
|
339 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
340 |
self assert: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
341 |
||
342 |
"package2 overrides the responsibility of QWERTZ" |
|
343 |
packageManager addClass:QWERTZ toPackage:package2. |
|
344 |
"package2 should be responsible for QWERTZ and package1 should store that |
|
345 |
it was package2 that overrid the change" |
|
346 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
347 |
self shouldnt: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
348 |
self assert: (package2 packagedClassNamed:#QWERTZ) notNil. |
|
349 |
self assert: (package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
350 |
self assert:(package1 overriddenClassNamesByPackage:package2) size == 1. |
|
351 |
self assert:(package1 overriddenClassNamesByPackage:package2) first == #QWERTZ. |
|
352 |
||
353 |
"remove the class from the package2. This should make all the responsibilities |
|
354 |
go to defaultPackage in packageManager." |
|
355 |
packageManager removeClassNamed:#QWERTZ fromPackage:package2. |
|
356 |
||
357 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
358 |
self shouldnt: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
359 |
||
360 |
self assert: (package2 packagedClassNamed:#QWERTZ) isNil. |
|
361 |
self assert:(package1 overriddenClassNamesByPackage:package2) size == 0. |
|
362 |
||
363 |
self assert:(package1 overriddenClassNamesByPackage:defaultPackage) size == 1. |
|
364 |
self assert:(package1 overriddenClassNamesByPackage:defaultPackage) first == #QWERTZ. |
|
365 |
||
366 |
"check that the deleted class is then stored in workingClass" |
|
367 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) notNil. |
|
368 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
369 |
||
370 |
] ensure: |
|
371 |
[ |
|
372 |
package1 ifNotNil:[ |
|
373 |
packageManager removePackage:package1. |
|
374 |
]. |
|
375 |
package2 ifNotNil:[ |
|
376 |
packageManager removePackage:package2. |
|
377 |
]. |
|
378 |
]. |
|
379 |
! |
|
380 |
||
381 |
test_removeClass_fromPackage3 |
|
382 |
"to test that when a " |
|
383 |
| package1 | |
|
384 |
[ |
|
385 |
"pre-setup" |
|
386 |
"i expect setUp should do this!!" |
|
387 |
self assert:(packageManager defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
388 |
package1 := Package packageManager newPackageNamed:#'package1'. |
|
389 |
packageManager moveClassNamed:#QWERTZ fromPackage:defaultPackage toPackage:package1. |
|
390 |
||
391 |
"prerequisites" |
|
392 |
self shouldnt: (packageManager defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
393 |
self assert: (package1 includesPackagedClassNamed:#QWERTZ). |
|
394 |
self shouldnt: (defaultPackage includesPackagedClassNamed:#QWERTZ). |
|
395 |
||
396 |
"check that the added class in package1 is in smalltalk |
|
397 |
and that that package1 has a packaged class representing it." |
|
398 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
399 |
self assert: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
400 |
||
401 |
packageManager removeClassNamed:#QWERTZ fromPackage:package1. |
|
402 |
||
403 |
"check that package1 has NOT got a packaged class representing it." |
|
404 |
self assert: (package1 packagedClassNamed:#QWERTZ) isNil. |
|
405 |
"check that the deleted class is then stored in workingClass" |
|
406 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) notNil. |
|
407 |
self assert: (defaultPackage packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
408 |
self assert:((defaultPackage packagedClassNamed:#QWERTZ) packagedMethods size == 3). |
|
409 |
self assert: (package1 packagedMethods at:#QWERTZ ifAbsent:[nil]) isNil. |
|
410 |
] ensure: |
|
411 |
[ |
|
412 |
package1 ifNotNil:[ |
|
413 |
packageManager removePackage:package1. |
|
414 |
]. |
|
415 |
]. |
|
416 |
! |
|
417 |
||
418 |
test_removeMethod_fromPackage |
|
419 |
|method1 method2 packageTestCases| |
|
420 |
"prerequisites to test" |
|
421 |
||
422 |
[ |
|
423 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'. |
|
424 |
method1 := (QWERTZ compiledMethodAt:#aDummyMethod). |
|
425 |
method2 := (QWERTZ compiledMethodAt:#aDummyMethod2). |
|
426 |
||
427 |
packageManager moveClass:QWERTZ toPackage:packageTestCases. |
|
428 |
||
429 |
packageManager moveMethod:method1 toPackage:packageTestCases. |
|
430 |
packageManager moveMethod:method2 toPackage:packageTestCases. |
|
431 |
||
432 |
self packageManager removeMethod:method2 fromPackage:packageTestCases. |
|
433 |
||
434 |
self assert:(packageTestCases includesPackagedClassNamed:#QWERTZ). |
|
435 |
self assert:(Smalltalk at:#QWERTZ) notNil. |
|
436 |
self assert:(packageTestCases isDirty). |
|
437 |
self assert:(packageTestCases isInstalled). |
|
438 |
] ensure: |
|
439 |
[ |
|
440 |
packageTestCases ifNotNil:[ |
|
441 |
packageManager removePackage:packageTestCases. |
|
442 |
]. |
|
443 |
] |
|
444 |
! |
|
445 |
||
446 |
test_removePackage |
|
447 |
"Test: |
|
448 |
When the manager removes the responsibility of a class from a package via: |
|
449 |
PackageManager>>removeClass:fromPackage: |
|
450 |
||
451 |
If a package overid another package with a class, and this package was |
|
452 |
deleted, the overriden information has to be updated. |
|
453 |
||
454 |
Sequence of events |
|
455 |
package1 owns class1 |
|
456 |
package2 overrides class1 |
|
457 |
package3 overrides class1 |
|
458 |
package3 owns class1 |
|
459 |
package2 stores class1 as overriddenBy: package3 |
|
460 |
package1 stores class1 as overriddenBy: package2 |
|
461 |
||
462 |
packageManager removePackage:package2 |
|
463 |
'at the moment ' |
|
464 |
package stores class1 as overriddenBy:package2 'WRONG!!!!' |
|
465 |
package3 owns class1 |
|
466 |
||
467 |
" |
|
468 |
| package1 package2 package3 | |
|
469 |
"i expect setUp should do this!!" |
|
470 |
self assert:(packageManager workingPackage includesPackagedClassNamed:#QWERTZ). |
|
471 |
[ |
|
472 |
"pre-setup" |
|
473 |
package1 := Package packageManager newPackageNamed:#'package1'. |
|
474 |
package2 := Package packageManager newPackageNamed:#'package2'. |
|
475 |
package3 := Package packageManager newPackageNamed:#'package3'. |
|
476 |
packageManager moveClassNamed:#QWERTZ fromPackage:defaultPackage toPackage:package1. |
|
477 |
||
478 |
"prerequisites" |
|
479 |
self shouldnt: (packageManager workingPackage includesPackagedClassNamed:#QWERTZ). |
|
480 |
self assert: (package1 includesPackagedClassNamed:#QWERTZ). |
|
481 |
||
482 |
"check that the added class in oldPackage is in smalltalk |
|
483 |
and that that oldPackage has a packaged class representing it." |
|
484 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
485 |
self assert: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
486 |
||
487 |
"package2 overrides the responsibility of QWERTZ" |
|
488 |
packageManager addClass:QWERTZ toPackage:package2. |
|
489 |
"package2 should be responsible for QWERTZ and package1 should store that |
|
490 |
it was package2 that overrid the change" |
|
491 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
492 |
self shouldnt: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
493 |
self assert: (package2 packagedClassNamed:#QWERTZ) notNil. |
|
494 |
self assert: (package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
495 |
self assert:(package1 overriddenClassNamesByPackage:package2) size == 1. |
|
496 |
self assert:(package1 overriddenClassNamesByPackage:package2) first == #QWERTZ. |
|
497 |
||
498 |
"package3 overrides the responsibility of QWERTZ" |
|
499 |
packageManager addClass:QWERTZ toPackage:package3. |
|
500 |
"package3 should be responsible for QWERTZ and package2 should store that |
|
501 |
it was package2 that overrid the change and package1 should store that package2 |
|
502 |
overrid its changes" |
|
503 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
504 |
self shouldnt: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
505 |
self assert: (package2 packagedClassNamed:#QWERTZ) notNil. |
|
506 |
self shouldnt: (package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
507 |
||
508 |
self assert: (package3 packagedClassNamed:#QWERTZ) notNil. |
|
509 |
self assert: (package3 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
510 |
||
511 |
self assert:(package1 overriddenClassNamesByPackage:package2) size == 1. |
|
512 |
self assert:(package1 overriddenClassNamesByPackage:package2) first == #QWERTZ. |
|
513 |
self assert:(package2 overriddenClassNamesByPackage:package3) size == 1. |
|
514 |
self assert:(package2 overriddenClassNamesByPackage:package3) first == #QWERTZ. |
|
515 |
||
516 |
"remove the package package2. This should make all the responsibilities |
|
517 |
stay in package3!!" |
|
518 |
packageManager unloadPackage:package2. |
|
519 |
self assert: (package1 packagedClassNamed:#QWERTZ) notNil. |
|
520 |
self shouldnt: (package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
521 |
self assert:(package1 overriddenClassNamesByPackage:package2) size == 0. |
|
522 |
self assert:(package1 overriddenClassNamesByPackage:defaultPackage) size == 0. |
|
523 |
||
524 |
self shouldnt: (packageManager includesPackage:package2). |
|
525 |
||
526 |
"check that the deleted class is then stored in package3" |
|
527 |
self assert:(package1 overriddenClassNamesByPackage:package3) size == 1. |
|
528 |
self assert:(package1 overriddenClassNamesByPackage:package3) first == #QWERTZ. |
|
529 |
||
530 |
] ensure: |
|
531 |
[ |
|
532 |
package1 ifNotNil:[ |
|
533 |
packageManager removePackageNamed:#'package1'. |
|
534 |
]. |
|
535 |
(packageManager includesPackage:package2) ifTrue:[ |
|
536 |
packageManager removePackageNamed:#'package2'. |
|
537 |
]. |
|
538 |
package3 ifNotNil:[ |
|
539 |
packageManager removePackageNamed:#'package3'. |
|
540 |
]. |
|
541 |
]. |
|
542 |
! ! |
|
543 |
||
544 |
!PackageManagerTests methodsFor:'test - moving'! |
|
545 |
||
546 |
test_addClass_PackageError |
|
547 |
"Move QWERTZ class to the default package that already knows it!! it should complain" |
|
548 |
[ |
|
549 |
self should:[packageManager addClass:QWERTZ toPackage:defaultPackage] raise:PackageError |
|
550 |
||
551 |
] ensure:[ |
|
552 |
]. |
|
553 |
! |
|
554 |
||
555 |
test_addClass_Packaged_Error2 |
|
556 |
"A class can only be added to a package when it doesnt have a class with the same name. |
|
557 |
if it does a PackageError occurs!!" |
|
558 |
| package1 package2| |
|
559 |
[ |
|
560 |
package1 := packageManager newPackageNamed:#'package1'. |
|
561 |
package2 := packageManager newPackageNamed:#'package2'. |
|
562 |
||
563 |
self shouldnt:(package1 isDirty). |
|
564 |
self shouldnt:(package2 isDirty). |
|
565 |
||
566 |
"Add the class to package1 and package2 and then attempt to add it to package1 again" |
|
567 |
packageManager addClass:QWERTZ toPackage:package1. |
|
568 |
self assert:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
569 |
self shouldnt:(package2 includesPackagedClassNamed:#QWERTZ). |
|
570 |
||
571 |
packageManager addClass:QWERTZ toPackage:package2. |
|
572 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
573 |
self assert:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
574 |
||
575 |
"QWERTZ is already in Smalltalk assigned to package2" |
|
576 |
self should:[packageManager addClass:QWERTZ toPackage:package2] raise:PackageError. |
|
577 |
"The state should stay the same as before this action was carried out" |
|
578 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
579 |
self assert:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
580 |
||
581 |
"QWERTZ is already in Smalltalk but assigned to package2" |
|
582 |
packageManager addClass:QWERTZ toPackage:package1. |
|
583 |
"QWERTZ is assigned to package 1" |
|
584 |
self shouldnt:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
585 |
self assert:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
586 |
||
587 |
packageManager addClass:QWERTZ toPackage:defaultPackage. |
|
588 |
] ensure:[ |
|
589 |
packageManager unloadPackageNamed:#'package1'. |
|
590 |
packageManager unloadPackageNamed:#'package2'. |
|
591 |
]. |
|
592 |
! |
|
593 |
||
594 |
test_moveClass1 |
|
595 |
"Move QWERTZ class to a new package named the same as the old package |
|
596 |
but with a 1 on the end. Then move the class back." |
|
597 |
| package1 package2| |
|
598 |
[ |
|
599 |
package1 := packageManager newPackageNamed:#'package1'. |
|
600 |
package2 := packageManager newPackageNamed:#'package2'. |
|
601 |
||
602 |
self shouldnt:(package1 isDirty). |
|
603 |
self shouldnt:(package2 isDirty). |
|
604 |
||
605 |
"Make the representation of QWERTZ is in the default package and |
|
606 |
have overriddenPackagedClasses in package1 and package2!!" |
|
607 |
packageManager addClass:QWERTZ toPackage:package1. |
|
608 |
packageManager addClass:QWERTZ toPackage:package2. |
|
609 |
packageManager addClass:QWERTZ toPackage:defaultPackage. |
|
610 |
||
611 |
self assert:(QWERTZ package == defaultPackage name). |
|
612 |
||
613 |
self assert:(package1 overriddenClassChangesIncludesClassNamed:#QWERTZ). |
|
614 |
self assert:(package2 overriddenClassChangesIncludesClassNamed:#QWERTZ). |
|
615 |
||
616 |
self assert:(package1 includesPackagedClassNamed:#QWERTZ). |
|
617 |
self assert:(package2 includesPackagedClassNamed:#QWERTZ). |
|
618 |
||
619 |
self assert:(package1 isDirty). |
|
620 |
self assert:(package2 isDirty). |
|
621 |
||
622 |
"It is in defaultPackage" |
|
623 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
624 |
self shouldnt:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
625 |
||
626 |
"<tested method>" |
|
627 |
self should:[packageManager moveClassNamed:#QWERTZ fromPackage:package1 toPackage:package2] raise:PackageError. |
|
628 |
"If a class already owns a preresentation of a class by the same name it must be removed |
|
629 |
BEFORE the above action can take place. The state should remain the same as before" |
|
630 |
"</tested method>" |
|
631 |
||
632 |
self assert:(package1 overriddenClassChangesIncludesClassNamed:#QWERTZ). |
|
633 |
self assert:(package2 overriddenClassChangesIncludesClassNamed:#QWERTZ). |
|
634 |
||
635 |
self assert:(package1 includesPackagedClassNamed:#QWERTZ). |
|
636 |
self assert:(package2 includesPackagedClassNamed:#QWERTZ). |
|
637 |
||
638 |
self assert:(package1 isDirty). |
|
639 |
self assert:(package2 isDirty). |
|
640 |
"It is in defaultPackage" |
|
641 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
642 |
self shouldnt:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
643 |
||
644 |
"<tested method with it removed from package2>" |
|
645 |
packageManager removeClassNamed:#QWERTZ fromPackage:package2. |
|
646 |
packageManager moveClassNamed:#QWERTZ fromPackage:package1 toPackage:package2. |
|
647 |
"</tested method>" |
|
648 |
||
649 |
self assert:(package2 includesPackagedClassNamed:#QWERTZ). |
|
650 |
self shouldnt:(package1 includesPackagedClassNamed:#QWERTZ). |
|
651 |
self shouldnt:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
652 |
self assert:(QWERTZ package == defaultPackage name). |
|
653 |
||
654 |
self assert:(package2 isDirty). |
|
655 |
self assert:(package1 isDirty). |
|
656 |
||
657 |
"<tested method>" |
|
658 |
packageManager moveClassNamed:#QWERTZ fromPackage:package2 toPackage:package1. |
|
659 |
"</tested method>>" |
|
1278 | 660 |
self shouldnt:(package2 includesPackagedClassNamed:#QWERTZ). |
661 |
self assert:(package1 includesPackagedClassNamed:#QWERTZ). |
|
1267 | 662 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
663 |
||
664 |
self assert:(package2 isDirty). |
|
665 |
self assert:(package1 isDirty). |
|
666 |
||
667 |
"<tested method>" |
|
668 |
self should:[packageManager moveClassNamed:#QWERTZ fromPackage:package1 toPackage:defaultPackage] raise:PackageError. |
|
669 |
"</tested method>>" |
|
670 |
] ensure:[ |
|
671 |
packageManager unloadPackageNamed:#'package2'. |
|
672 |
packageManager unloadPackageNamed:#'package1'. |
|
673 |
]. |
|
674 |
! |
|
675 |
||
676 |
test_moveClass2 |
|
677 |
"Move QWERTZ class to a new package named the same as the old package |
|
678 |
but with a 1 on the end. Then move the class back." |
|
679 |
| package1 package2| |
|
680 |
[ |
|
681 |
package1 := packageManager packageNamed:#'package1' ifAbsent:[ |
|
682 |
packageManager newPackageNamed:#'package1' |
|
683 |
]. |
|
684 |
package2 := packageManager packageNamed:#'package2'ifAbsent:[ |
|
685 |
packageManager newPackageNamed:#'package2' |
|
686 |
]. |
|
687 |
self shouldnt:(package1 isDirty). |
|
688 |
self shouldnt:(package2 isDirty). |
|
689 |
||
690 |
"Make the representation of QWERTZ is in the default package and |
|
691 |
have overriddenPackagedClasses in package1 and package2!!" |
|
692 |
packageManager addClass:QWERTZ toPackage:package1. |
|
693 |
||
694 |
self assert:(QWERTZ package == package1 name). |
|
695 |
self assert:(package1 includesPackagedClassNamed:#QWERTZ). |
|
696 |
self assert:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
697 |
||
698 |
self assert:(package1 isDirty). |
|
699 |
||
700 |
"<tested method>" "here package1 'owns' the class in smalltalk. After the method has been evaluated |
|
701 |
package2 should 'own' the class in smalltalk" |
|
702 |
packageManager moveClassNamed:#QWERTZ fromPackage:package1 toPackage:package2. |
|
703 |
"</tested method>" |
|
704 |
||
705 |
self assert:(package2 includesPackagedClassNamed:#QWERTZ). |
|
706 |
self shouldnt:(package1 includesPackagedClassNamed:#QWERTZ). |
|
707 |
||
708 |
self assert:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk. |
|
709 |
||
710 |
self assert:(QWERTZ package == package2 name). |
|
711 |
||
712 |
self assert:(package2 isDirty). |
|
713 |
self assert:(package1 isDirty). |
|
714 |
||
715 |
||
716 |
"<tested method>" |
|
717 |
packageManager addClass:QWERTZ toPackage:defaultPackage. |
|
718 |
"</tested method>" |
|
719 |
||
720 |
] ensure:[ |
|
721 |
packageManager unloadPackage:package2. |
|
722 |
packageManager unloadPackage:package1. |
|
723 |
]. |
|
724 |
! ! |
|
725 |
||
726 |
!PackageManagerTests class methodsFor:'documentation'! |
|
727 |
||
728 |
version |
|
3011
1997ff6e7e55
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1445
diff
changeset
|
729 |
^ '$Header: /var/local/cvs/stx/libbasic3/packages/PackageManagerTests.st,v 1.4 2006-01-10 09:31:56 cg Exp $' |
1267 | 730 |
! ! |