author | convert-repo |
Mon, 13 Feb 2017 04:35:21 +0000 | |
changeset 675 | 384514ae296e |
parent 215 | 6db48dedef3a |
permissions | -rw-r--r-- |
210 | 1 |
"{ Package: 'stx:goodies/sunit' }" |
2 |
||
3 |
ApplicationModel subclass:#TestTester |
|
4 |
instanceVariableNames:'currentSource testCaseClassListApp testCaseMethodListApp |
|
5 |
testeeClassListApp testeeMethodListApp selectedTesteeClasses |
|
6 |
selectedTesteeMethods selectedTestCaseClasses |
|
7 |
selectedTestCaseMethods testeeMethodListHolder |
|
8 |
testCaseSourceHolder mutatedMethodSourceHolder |
|
9 |
originalMethodSourceHolder testCaseClassGeneratorHolder |
|
10 |
selectedTesteeMethod selectedTestCaseClass infoLabelHolder |
|
214 | 11 |
diffTextView numberOfTriedMutations maxTestExecutionTime' |
210 | 12 |
classVariableNames:'' |
13 |
poolDictionaries:'' |
|
14 |
category:'SUnit-UI' |
|
15 |
! |
|
16 |
||
17 |
Object subclass:#Mutator |
|
18 |
instanceVariableNames:'blockToCall treeTop' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
privateIn:TestTester |
|
22 |
! |
|
23 |
||
214 | 24 |
Error subclass:#TestSuiteIncompleteError |
25 |
instanceVariableNames:'' |
|
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:TestTester |
|
29 |
! |
|
30 |
||
31 |
Error subclass:#TimeoutError |
|
32 |
instanceVariableNames:'' |
|
33 |
classVariableNames:'' |
|
34 |
poolDictionaries:'' |
|
35 |
privateIn:TestTester |
|
36 |
! |
|
37 |
||
210 | 38 |
|
39 |
!TestTester class methodsFor:'interface specs'! |
|
40 |
||
41 |
windowSpec |
|
42 |
"This resource specification was automatically generated |
|
43 |
by the UIPainter of ST/X." |
|
44 |
||
45 |
"Do not manually edit this!! If it is corrupted, |
|
46 |
the UIPainter may not be able to read the specification." |
|
47 |
||
48 |
" |
|
49 |
UIPainter new openOnClass:TestTester andSelector:#windowSpec |
|
50 |
TestTester new openInterface:#windowSpec |
|
51 |
TestTester open |
|
52 |
" |
|
53 |
||
54 |
<resource: #canvas> |
|
55 |
||
56 |
^ |
|
57 |
#(FullSpec |
|
58 |
name: windowSpec |
|
59 |
window: |
|
60 |
(WindowSpec |
|
61 |
label: 'TestTester' |
|
62 |
name: 'TestTester' |
|
63 |
min: (Point 10 10) |
|
64 |
max: (Point 1024 768) |
|
65 |
bounds: (Rectangle 0 0 554 504) |
|
66 |
menu: mainMenu |
|
67 |
) |
|
68 |
component: |
|
69 |
(SpecCollection |
|
70 |
collection: ( |
|
71 |
(MenuPanelSpec |
|
72 |
name: 'ToolBar1' |
|
73 |
layout: (LayoutFrame 0 0.0 0 0 0 1.0 36 0) |
|
74 |
menu: toolbarMenu |
|
75 |
textDefault: true |
|
76 |
) |
|
77 |
(ViewSpec |
|
78 |
name: 'Box4' |
|
79 |
layout: (LayoutFrame 0 0 36 0 0 1 -26 1) |
|
80 |
component: |
|
81 |
(SpecCollection |
|
82 |
collection: ( |
|
83 |
(ViewSpec |
|
84 |
name: 'TestedMethodSelectionBox' |
|
85 |
layout: (LayoutFrame 0 0 0 0 0 0.4 0 0.5) |
|
86 |
component: |
|
87 |
(SpecCollection |
|
88 |
collection: ( |
|
89 |
(LabelSpec |
|
90 |
label: 'Tested Method' |
|
91 |
name: 'Label4' |
|
92 |
layout: (LayoutFrame 0 0.0 0 0 0 1.0 22 0) |
|
93 |
translateLabel: true |
|
94 |
) |
|
95 |
(SubCanvasSpec |
|
96 |
name: 'TestedMethodClassList' |
|
97 |
layout: (LayoutFrame 0 0 22 0 0 0.5 0 1) |
|
98 |
hasHorizontalScrollBar: false |
|
99 |
hasVerticalScrollBar: false |
|
100 |
majorKey: #'Tools::ClassList' |
|
101 |
subAspectHolders: |
|
102 |
(Array |
|
103 |
||
104 |
(SubChannelInfoSpec |
|
105 |
subAspect: selectedClasses |
|
106 |
aspect: selectedTesteeClasses |
|
107 |
) |
|
108 |
) |
|
109 |
createNewApplication: true |
|
110 |
createNewBuilder: true |
|
111 |
postBuildCallback: postBuildTestedClassList: |
|
112 |
) |
|
113 |
(SubCanvasSpec |
|
114 |
name: 'TestedMethodMethodList' |
|
115 |
layout: (LayoutFrame 0 0.5 22 0 0 1 0 1) |
|
116 |
hasHorizontalScrollBar: false |
|
117 |
hasVerticalScrollBar: false |
|
118 |
majorKey: #'Tools::MethodList' |
|
119 |
subAspectHolders: |
|
120 |
(Array |
|
121 |
||
122 |
(SubChannelInfoSpec |
|
123 |
subAspect: inGeneratorHolder |
|
124 |
aspect: testeeMethodListHolder |
|
125 |
) |
|
126 |
(SubChannelInfoSpec |
|
127 |
subAspect: selectedMethods |
|
128 |
aspect: selectedTesteeMethods |
|
129 |
) |
|
130 |
) |
|
131 |
createNewApplication: true |
|
132 |
createNewBuilder: true |
|
133 |
postBuildCallback: postBuildTestedMethodList: |
|
134 |
) |
|
135 |
) |
|
136 |
||
137 |
) |
|
138 |
) |
|
139 |
(LabelSpec |
|
140 |
label: 'Original' |
|
141 |
name: 'Label5' |
|
142 |
layout: (LayoutFrame 0 0.4 0 0 0 0.7 22 0) |
|
143 |
translateLabel: true |
|
144 |
) |
|
145 |
(TextEditorSpec |
|
146 |
name: 'OriginalMethodEditor' |
|
147 |
layout: (LayoutFrame 0 0.4 22 0 0 0.7 0 0.5) |
|
148 |
model: originalMethodSourceHolder |
|
149 |
hasHorizontalScrollBar: true |
|
150 |
hasVerticalScrollBar: true |
|
151 |
hasKeyboardFocusInitially: false |
|
152 |
) |
|
153 |
(LabelSpec |
|
154 |
label: 'Mutation' |
|
155 |
name: 'Label6' |
|
156 |
layout: (LayoutFrame 0 0.7 0 0 0 1 22 0) |
|
157 |
translateLabel: true |
|
158 |
) |
|
159 |
(TextEditorSpec |
|
160 |
name: 'MutatedMethodEditor' |
|
161 |
layout: (LayoutFrame 0 0.7 22 0 0 1 0 0.5) |
|
162 |
model: mutatedMethodSourceHolder |
|
163 |
hasHorizontalScrollBar: true |
|
164 |
hasVerticalScrollBar: true |
|
165 |
hasKeyboardFocusInitially: false |
|
166 |
) |
|
167 |
(ViewSpec |
|
168 |
name: 'TestSuiteSelectionBox' |
|
169 |
layout: (LayoutFrame 0 0 0 0.5 0 0.4 0 1) |
|
170 |
component: |
|
171 |
(SpecCollection |
|
172 |
collection: ( |
|
173 |
(LabelSpec |
|
174 |
label: 'TestCase' |
|
175 |
name: 'Label3' |
|
176 |
layout: (LayoutFrame 0 0.0 0 0 0 1.0 22 0) |
|
177 |
translateLabel: true |
|
178 |
) |
|
179 |
(SubCanvasSpec |
|
180 |
name: 'TestCaseClassList' |
|
181 |
layout: (LayoutFrame 0 0 22 0 0 1 0 1) |
|
182 |
hasHorizontalScrollBar: false |
|
183 |
hasVerticalScrollBar: false |
|
184 |
majorKey: #'Tools::ClassList' |
|
185 |
subAspectHolders: |
|
186 |
(Array |
|
187 |
||
188 |
(SubChannelInfoSpec |
|
189 |
subAspect: inGeneratorHolder |
|
190 |
aspect: testCaseClassGeneratorHolder |
|
191 |
) |
|
192 |
(SubChannelInfoSpec |
|
193 |
subAspect: selectedClasses |
|
194 |
aspect: selectedTestCaseClasses |
|
195 |
) |
|
196 |
) |
|
197 |
createNewApplication: true |
|
198 |
createNewBuilder: true |
|
199 |
postBuildCallback: postBuildTestCaseClassList: |
|
200 |
) |
|
201 |
) |
|
202 |
||
203 |
) |
|
204 |
) |
|
205 |
(LabelSpec |
|
206 |
name: 'Label7' |
|
207 |
layout: (LayoutFrame 0 0.5 0 0.5 0 1 22 0.5) |
|
208 |
translateLabel: true |
|
209 |
) |
|
210 |
(TextEditorSpec |
|
211 |
name: 'TextCaseEditor1' |
|
212 |
layout: (LayoutFrame 0 0.4 22 0.5 0 1 0 1) |
|
213 |
model: testCaseSourceHolder |
|
214 |
hasHorizontalScrollBar: true |
|
215 |
hasVerticalScrollBar: true |
|
216 |
hasKeyboardFocusInitially: false |
|
217 |
) |
|
218 |
(ArbitraryComponentSpec |
|
219 |
name: 'ArbitraryComponent1' |
|
220 |
layout: (LayoutFrame 0 0.4 0 0 0 1 0 0.5) |
|
221 |
hasHorizontalScrollBar: true |
|
222 |
hasVerticalScrollBar: true |
|
223 |
miniScrollerHorizontal: true |
|
224 |
component: DiffTextView |
|
225 |
postBuildCallback: postBuildDiffTextView: |
|
226 |
) |
|
227 |
) |
|
228 |
||
229 |
) |
|
230 |
) |
|
231 |
(ViewSpec |
|
232 |
name: 'Box2' |
|
233 |
layout: (LayoutFrame 0 0 -26 1 0 1 0 1) |
|
234 |
level: 1 |
|
235 |
component: |
|
236 |
(SpecCollection |
|
237 |
collection: ( |
|
238 |
(LabelSpec |
|
239 |
label: 'InfoLabel' |
|
240 |
name: 'Label2' |
|
241 |
layout: (LayoutFrame 0 0 -26 1 -1 1 0 1) |
|
242 |
level: -1 |
|
243 |
translateLabel: true |
|
244 |
labelChannel: infoLabelHolder |
|
245 |
adjust: left |
|
246 |
) |
|
247 |
) |
|
248 |
||
249 |
) |
|
250 |
) |
|
251 |
) |
|
252 |
||
253 |
) |
|
254 |
) |
|
255 |
! ! |
|
256 |
||
257 |
!TestTester class methodsFor:'menu specs'! |
|
258 |
||
259 |
mainMenu |
|
260 |
"This resource specification was automatically generated |
|
261 |
by the MenuEditor of ST/X." |
|
262 |
||
263 |
"Do not manually edit this!! If it is corrupted, |
|
264 |
the MenuEditor may not be able to read the specification." |
|
265 |
||
266 |
" |
|
267 |
MenuEditor new openOnClass:TestTester andSelector:#mainMenu |
|
268 |
(Menu new fromLiteralArrayEncoding:(TestTester mainMenu)) startUp |
|
269 |
" |
|
270 |
||
271 |
<resource: #menu> |
|
272 |
||
273 |
^ |
|
274 |
#(Menu |
|
275 |
( |
|
276 |
(MenuItem |
|
277 |
label: 'File' |
|
278 |
translateLabel: true |
|
279 |
submenu: |
|
280 |
(Menu |
|
281 |
( |
|
282 |
(MenuItem |
|
283 |
label: 'Exit' |
|
284 |
itemValue: closeRequest |
|
285 |
translateLabel: true |
|
286 |
) |
|
287 |
) |
|
288 |
nil |
|
289 |
nil |
|
290 |
) |
|
291 |
) |
|
292 |
(MenuItem |
|
293 |
label: 'Help' |
|
294 |
translateLabel: true |
|
295 |
startGroup: right |
|
296 |
submenu: |
|
297 |
(Menu |
|
298 |
( |
|
299 |
(MenuItem |
|
300 |
label: 'Documentation' |
|
301 |
itemValue: openDocumentation |
|
302 |
translateLabel: true |
|
303 |
) |
|
304 |
(MenuItem |
|
305 |
label: '-' |
|
306 |
) |
|
307 |
(MenuItem |
|
308 |
label: 'About this Application...' |
|
309 |
itemValue: openAboutThisApplication |
|
310 |
translateLabel: true |
|
311 |
) |
|
312 |
) |
|
313 |
nil |
|
314 |
nil |
|
315 |
) |
|
316 |
) |
|
317 |
) |
|
318 |
nil |
|
319 |
nil |
|
320 |
) |
|
321 |
! |
|
322 |
||
323 |
toolbarMenu |
|
324 |
"This resource specification was automatically generated |
|
325 |
by the MenuEditor of ST/X." |
|
326 |
||
327 |
"Do not manually edit this!! If it is corrupted, |
|
328 |
the MenuEditor may not be able to read the specification." |
|
329 |
||
330 |
" |
|
331 |
MenuEditor new openOnClass:TestTester andSelector:#toolbarMenu |
|
332 |
(Menu new fromLiteralArrayEncoding:(TestTester toolbarMenu)) startUp |
|
333 |
" |
|
334 |
||
335 |
<resource: #menu> |
|
336 |
||
337 |
^ |
|
338 |
#(Menu |
|
339 |
( |
|
340 |
(MenuItem |
|
341 |
label: 'RunCheck' |
|
342 |
itemValue: menuRunCheck |
|
343 |
translateLabel: true |
|
344 |
isButton: true |
|
345 |
labelImage: (ResourceRetriever ToolbarIconLibrary make22x22Icon) |
|
346 |
) |
|
347 |
) |
|
348 |
nil |
|
349 |
nil |
|
350 |
) |
|
351 |
! ! |
|
352 |
||
353 |
!TestTester methodsFor:'aspects'! |
|
354 |
||
355 |
infoLabelHolder |
|
356 |
infoLabelHolder isNil ifTrue:[ |
|
357 |
infoLabelHolder := ValueHolder new. |
|
358 |
]. |
|
359 |
^ infoLabelHolder |
|
360 |
||
361 |
"Created: / 25-04-2010 / 21:01:00 / cg" |
|
362 |
! |
|
363 |
||
364 |
mutatedMethodSourceHolder |
|
365 |
mutatedMethodSourceHolder isNil ifTrue:[ |
|
366 |
mutatedMethodSourceHolder := ValueHolder new. |
|
367 |
]. |
|
368 |
^ mutatedMethodSourceHolder |
|
369 |
||
370 |
"Created: / 25-04-2010 / 15:53:44 / cg" |
|
371 |
! |
|
372 |
||
373 |
originalMethodSourceHolder |
|
374 |
originalMethodSourceHolder isNil ifTrue:[ |
|
375 |
originalMethodSourceHolder := ValueHolder new. |
|
376 |
]. |
|
377 |
^ originalMethodSourceHolder |
|
378 |
||
379 |
"Created: / 25-04-2010 / 15:53:58 / cg" |
|
380 |
! |
|
381 |
||
382 |
selectedTestCaseClasses |
|
383 |
selectedTestCaseClasses isNil ifTrue:[ |
|
384 |
selectedTestCaseClasses := ValueHolder new. |
|
385 |
selectedTestCaseClasses onChangeSend:#selectedTestCaseClassesChanged to:self. |
|
386 |
]. |
|
387 |
^ selectedTestCaseClasses |
|
388 |
||
389 |
"Created: / 25-04-2010 / 16:23:56 / cg" |
|
390 |
! |
|
391 |
||
392 |
selectedTesteeClasses |
|
393 |
selectedTesteeClasses isNil ifTrue:[ |
|
394 |
selectedTesteeClasses := ValueHolder new. |
|
395 |
selectedTesteeClasses onChangeSend:#selectedTesteeClassesChanged to:self. |
|
396 |
]. |
|
397 |
^ selectedTesteeClasses |
|
398 |
||
399 |
"Created: / 25-04-2010 / 14:00:14 / cg" |
|
400 |
! |
|
401 |
||
402 |
selectedTesteeMethods |
|
403 |
selectedTesteeMethods isNil ifTrue:[ |
|
404 |
selectedTesteeMethods := ValueHolder new. |
|
405 |
selectedTesteeMethods onChangeSend:#selectedTesteeMethodsChanged to:self. |
|
406 |
]. |
|
407 |
^ selectedTesteeMethods |
|
408 |
||
409 |
"Created: / 25-04-2010 / 15:50:10 / cg" |
|
410 |
! |
|
411 |
||
412 |
testCaseClassGeneratorHolder |
|
413 |
testCaseClassGeneratorHolder isNil ifTrue:[ |
|
414 |
testCaseClassGeneratorHolder := ValueHolder new. |
|
415 |
]. |
|
416 |
^ testCaseClassGeneratorHolder |
|
417 |
||
418 |
"Created: / 25-04-2010 / 16:01:28 / cg" |
|
419 |
! |
|
420 |
||
421 |
testCaseSourceHolder |
|
422 |
testCaseSourceHolder isNil ifTrue:[ |
|
423 |
testCaseSourceHolder := ValueHolder new. |
|
424 |
]. |
|
425 |
^ testCaseSourceHolder |
|
426 |
||
427 |
"Created: / 25-04-2010 / 15:53:07 / cg" |
|
428 |
! |
|
429 |
||
430 |
testeeMethodListHolder |
|
431 |
testeeMethodListHolder isNil ifTrue:[ |
|
432 |
testeeMethodListHolder := ValueHolder new. |
|
433 |
]. |
|
434 |
^ testeeMethodListHolder |
|
435 |
||
436 |
"Created: / 25-04-2010 / 14:05:25 / cg" |
|
437 |
! ! |
|
438 |
||
439 |
!TestTester methodsFor:'initialization'! |
|
440 |
||
441 |
postBuildDiffTextView:aView |
|
442 |
diffTextView := aView |
|
443 |
||
444 |
"Created: / 26-04-2010 / 10:36:42 / cg" |
|
445 |
! |
|
446 |
||
447 |
postBuildTestCaseClassList:aSubCanvas |
|
448 |
|classGenerator| |
|
449 |
||
450 |
classGenerator := |
|
451 |
Iterator |
|
452 |
on:[:whatToDo | |
|
453 |
TestCase allSubclasses |
|
454 |
select:[:cls | cls isAbstract not] |
|
455 |
thenDo:[:cls | |
|
456 |
whatToDo |
|
457 |
value:cls |
|
458 |
]. |
|
459 |
]. |
|
460 |
||
461 |
self testCaseClassGeneratorHolder value:classGenerator |
|
462 |
||
463 |
"Modified: / 25-04-2010 / 16:04:44 / cg" |
|
464 |
! |
|
465 |
||
466 |
postBuildTestCaseMethodList:aSubCanvas |
|
467 |
testCaseMethodListApp := aSubCanvas |
|
468 |
||
469 |
"Created: / 25-04-2010 / 13:51:42 / cg" |
|
470 |
! |
|
471 |
||
472 |
postBuildTestedClassList:aSubCanvas |
|
473 |
testeeClassListApp := aSubCanvas |
|
474 |
||
475 |
"Modified: / 25-04-2010 / 13:50:41 / cg" |
|
476 |
! |
|
477 |
||
478 |
postBuildTestedMethodList:aSubCanvas |
|
479 |
testeeMethodListApp := aSubCanvas |
|
480 |
||
481 |
"Created: / 25-04-2010 / 13:50:58 / cg" |
|
482 |
! |
|
483 |
||
484 |
postBuildWith:aBuilder |
|
485 |
"/ testCaseClassListApp inGeneratorHolder:[ Smalltalk allClasses ] |
|
486 |
||
487 |
"Created: / 25-04-2010 / 13:47:59 / cg" |
|
488 |
! ! |
|
489 |
||
490 |
!TestTester methodsFor:'menu actions'! |
|
491 |
||
492 |
menuRunCheck |
|
214 | 493 |
selectedTestCaseClass isNil ifTrue:[ |
494 |
Dialog information:'No TestCase class selected'. |
|
495 |
^ self. |
|
496 |
]. |
|
497 |
||
498 |
(AbortOperationRequest , TestSuiteIncompleteError) handle:[:ex | |
|
499 |
ex signal == TestSuiteIncompleteError ifTrue:[ |
|
500 |
self mutatedMethodSourceHolder value:ex parameter. |
|
501 |
]. |
|
210 | 502 |
self infoLabelHolder value:ex errorString. |
503 |
] do:[ |
|
504 |
self withWaitCursorDo:[ |
|
505 |
self infoLabelHolder value:'Running Suite...'. |
|
506 |
self |
|
507 |
testMethod:(selectedTesteeMethod) |
|
508 |
usingTest:selectedTestCaseClass. |
|
509 |
self infoLabelHolder value:nil. |
|
510 |
]. |
|
511 |
self mutatedMethodSourceHolder value:nil. |
|
512 |
]. |
|
513 |
self updateDiffTextView. |
|
514 |
||
214 | 515 |
"Modified: / 27-04-2010 / 09:46:09 / cg" |
210 | 516 |
! |
517 |
||
518 |
openAboutThisApplication |
|
519 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
520 |
It will be invoked when the menu-item 'help-about' is selected." |
|
521 |
||
522 |
"/ could open a customized aboutBox here ... |
|
523 |
super openAboutThisApplication |
|
524 |
! |
|
525 |
||
526 |
openDocumentation |
|
527 |
"This method was generated by the Browser/CodeGeneratorTool. |
|
528 |
It will be invoked when the menu-item 'help-documentation' is selected." |
|
529 |
||
530 |
"/ change below as required ... |
|
531 |
||
532 |
"/ to open an HTML viewer on some document (under 'doc/online/<language>/' ): |
|
533 |
self openDocumentationFile:'TOP.html'. |
|
534 |
||
535 |
"/ add application-specific help files under the 'doc/online/<language>/help/appName' |
|
536 |
"/ directory, and open a viewer with: |
|
537 |
"/ self openDocumentationFile:'help/<MyApplication>/TOP.html'. |
|
538 |
! ! |
|
539 |
||
540 |
!TestTester methodsFor:'misc'! |
|
541 |
||
542 |
showAllClassesInNameSpaceOrganisation |
|
543 |
^ true |
|
544 |
||
545 |
"Created: / 25-04-2010 / 13:56:24 / cg" |
|
546 |
! ! |
|
547 |
||
548 |
!TestTester methodsFor:'testing methods'! |
|
549 |
||
550 |
testMethod:aMethod using:selector fromTest:aTestCaseClass |
|
551 |
"motivation: |
|
552 |
assuming that aTestCase is a good test for aMethod, |
|
553 |
any change in aMethod should be rewarded by a failing testRun." |
|
554 |
||
555 |
^ self |
|
556 |
testMethod:aMethod |
|
557 |
usingTest:aTestCaseClass |
|
558 |
selectors:(aTestCaseClass testSelectors) |
|
559 |
||
560 |
"Modified: / 24-04-2010 / 14:03:57 / cg" |
|
561 |
! |
|
562 |
||
563 |
testMethod:aMethod usingSuite:aTestSuite |
|
564 |
|tree newSource methodClass methodSelector| |
|
565 |
||
566 |
numberOfTriedMutations := 0. |
|
214 | 567 |
maxTestExecutionTime := nil. |
210 | 568 |
|
569 |
methodClass := aMethod mclass. |
|
570 |
methodSelector := aMethod selector. |
|
571 |
||
214 | 572 |
self mutatedMethodSourceHolder value:nil. |
573 |
||
210 | 574 |
AssertionFailedError handle:[:ex | |
214 | 575 |
TestSuiteIncompleteError |
210 | 576 |
raiseWith:aMethod source |
577 |
errorString:'Test failed for original'. |
|
578 |
] do:[ |
|
212 | 579 |
self infoLabelHolder value:'Running Suite on original code...'. |
210 | 580 |
self runSuiteExpectingSuccess:aTestSuite. |
581 |
]. |
|
582 |
tree := RBParser parseMethod:(aMethod source) onError:[:str :pos | nil ]. |
|
583 |
tree isNil ifTrue:[ |
|
584 |
self error:'cannot parse method'. |
|
585 |
]. |
|
214 | 586 |
tree source:nil. |
587 |
||
210 | 588 |
"/ just to make sure: check if compiled method behaves the same |
589 |
newSource := tree formattedCode. |
|
590 |
self withCode:newSource installedAs:methodSelector inClass:methodClass do:[:newMethod | |
|
214 | 591 |
AssertionFailedError handle:[:ex | |
592 |
TestSuiteIncompleteError |
|
593 |
raiseWith:aMethod source |
|
594 |
errorString:'Test failed for original'. |
|
595 |
] do:[ |
|
596 |
self infoLabelHolder value:'Running Suite on original code again...'. |
|
597 |
self runSuiteExpectingSuccess:aTestSuite. |
|
598 |
] |
|
210 | 599 |
]. |
600 |
||
212 | 601 |
self originalMethodSourceHolder value:newSource. |
602 |
self mutatedMethodSourceHolder value:newSource. |
|
603 |
self updateDiffTextView. |
|
604 |
||
210 | 605 |
"/ start to fiddle with the code; the tests MUST detect each !! |
606 |
self mutationsOf:tree do:[:modifiedTree | |
|
607 |
newSource := modifiedTree formattedCode. |
|
212 | 608 |
self mutatedMethodSourceHolder value:newSource. |
609 |
self updateDiffTextView. |
|
610 |
||
210 | 611 |
self withCode:newSource installedAs:methodSelector inClass:methodClass do:[:newMethod | |
612 |
AssertionFailedError handle:[:ex | |
|
214 | 613 |
TestSuiteIncompleteError |
210 | 614 |
raiseWith:newSource |
212 | 615 |
errorString:ex errorString. |
210 | 616 |
] do:[ |
617 |
numberOfTriedMutations := numberOfTriedMutations + 1. |
|
212 | 618 |
self infoLabelHolder value:('Running Suite on mutation %1...' bindWith:numberOfTriedMutations). |
210 | 619 |
self runSuiteExpectingFailure:aTestSuite. |
620 |
] |
|
621 |
]. |
|
622 |
]. |
|
623 |
||
624 |
" |
|
625 |
self new |
|
626 |
testMethod:(Integer >> #factorial) |
|
627 |
usingTest:RegressionTests::IntegerTest |
|
628 |
selector:#testFactorial |
|
629 |
" |
|
630 |
||
631 |
"Created: / 24-04-2010 / 14:06:07 / cg" |
|
214 | 632 |
"Modified: / 27-04-2010 / 09:41:14 / cg" |
210 | 633 |
! |
634 |
||
635 |
testMethod:aMethod usingTest:aTestCaseClass |
|
636 |
"motivation: |
|
637 |
assuming that aTestCase is a good test for aMethod, |
|
638 |
any change in aMethod should be rewarded by a failing testRun." |
|
639 |
||
640 |
^ self |
|
641 |
testMethod:aMethod |
|
642 |
usingTest:aTestCaseClass |
|
643 |
selectors:(aTestCaseClass testSelectors) |
|
644 |
||
645 |
" |
|
646 |
self new |
|
647 |
testMethod:(Integer >> #factorial) |
|
648 |
usingTest:RegressionTests::IntegerTest |
|
649 |
" |
|
650 |
||
651 |
"Created: / 25-04-2010 / 16:29:22 / cg" |
|
652 |
! |
|
653 |
||
654 |
testMethod:aMethod usingTest:aTestCaseClass selector:selector |
|
655 |
"motivation: |
|
656 |
assuming that aTestCase is a good test for aMethod, |
|
657 |
any change in aMethod should be rewarded by a failing testRun." |
|
658 |
||
659 |
^ self |
|
660 |
testMethod:aMethod |
|
661 |
usingTest:aTestCaseClass |
|
662 |
selectors:(Array with:selector) |
|
663 |
||
664 |
" |
|
665 |
self new |
|
666 |
testMethod:(Integer >> #factorial) |
|
667 |
usingTest:RegressionTests::IntegerTest |
|
668 |
selector:#testFactorial |
|
669 |
" |
|
670 |
||
671 |
"Created: / 24-04-2010 / 13:59:18 / cg" |
|
672 |
! |
|
673 |
||
674 |
testMethod:aMethod usingTest:aTestCaseClass selectors:collectionOfSelectors |
|
675 |
"motivation: |
|
676 |
assuming that aTestCase is a good test for aMethod, |
|
677 |
any change in aMethod should be rewarded by a failing testRun." |
|
678 |
||
679 |
|suite| |
|
680 |
||
681 |
suite := TestSuite new. |
|
682 |
collectionOfSelectors do:[:selector | |
|
683 |
suite |
|
684 |
addTest: (aTestCaseClass selector: selector). |
|
685 |
]. |
|
686 |
^ self testMethod:aMethod usingSuite:suite |
|
687 |
||
688 |
" |
|
689 |
self new |
|
690 |
testMethod:(Integer >> #factorial) |
|
691 |
usingTest:RegressionTests::IntegerTest |
|
692 |
selector:#testFactorial |
|
693 |
" |
|
694 |
||
695 |
"Created: / 24-04-2010 / 14:03:09 / cg" |
|
696 |
! ! |
|
697 |
||
214 | 698 |
!TestTester methodsFor:'testing-helpers'! |
699 |
||
700 |
mutationsOf:aTree do:aBlock |
|
701 |
(Mutator new) mutationsOf:aTree do:aBlock |
|
702 |
"/ aTree acceptVisitor:(Mutator forBlock:aBlock). |
|
703 |
||
704 |
" |
|
705 |
self new |
|
706 |
testMethod:(Integer >> #factorial) |
|
707 |
usingTest:RegressionTests::IntegerTest |
|
708 |
selector:#testFactorial |
|
709 |
" |
|
710 |
||
711 |
"Created: / 24-04-2010 / 16:22:51 / cg" |
|
712 |
"Modified: / 24-04-2010 / 18:12:48 / cg" |
|
713 |
! |
|
714 |
||
715 |
runSuite:aTestSuite |
|
716 |
|t timedOut result| |
|
717 |
||
718 |
timedOut := false. |
|
719 |
||
720 |
t := Time millisecondsToRun:[ |
|
721 |
maxTestExecutionTime isNil ifTrue:[ |
|
722 |
result := aTestSuite run. |
|
723 |
] ifFalse:[ |
|
724 |
[ |
|
725 |
result := aTestSuite run. |
|
726 |
] valueWithWatchDog:[ timedOut := true ] afterMilliseconds:(maxTestExecutionTime * 5). |
|
727 |
]. |
|
728 |
]. |
|
729 |
timedOut ifTrue:[ TimeoutError raiseErrorString:'Timeout - code possibly ran into endless loop ?']. |
|
730 |
maxTestExecutionTime := (maxTestExecutionTime ? t) max:t. |
|
731 |
^ result |
|
732 |
||
733 |
"Created: / 27-04-2010 / 01:37:42 / cg" |
|
734 |
"Modified: / 27-04-2010 / 09:31:56 / cg" |
|
735 |
! |
|
736 |
||
737 |
runSuiteExpectingFailure:aTestSuite |
|
738 |
|result| |
|
739 |
||
740 |
TimeoutError handle:[:ex | |
|
741 |
Transcript showCR:ex description. |
|
742 |
^ self |
|
743 |
] do:[ |
|
744 |
result := self runSuite:aTestSuite. |
|
745 |
]. |
|
746 |
||
747 |
self |
|
748 |
assert:result runCount > 0; |
|
749 |
"/ assert:(result passedCount = 0) message:'test should not have passed'; |
|
750 |
assert:((result failureCount + result errorCount) > 0) |
|
751 |
message:'Some test should have failed'. |
|
752 |
||
753 |
"Created: / 24-04-2010 / 16:17:47 / cg" |
|
754 |
"Modified: / 27-04-2010 / 09:46:27 / cg" |
|
755 |
! |
|
756 |
||
757 |
runSuiteExpectingSuccess:aTestSuite |
|
758 |
|result| |
|
759 |
||
760 |
result := self runSuite:aTestSuite. |
|
761 |
result errorCount > 0 ifTrue:[self halt]. |
|
762 |
||
763 |
self |
|
764 |
assert:result runCount > 0; |
|
765 |
assert:(result passedCount > 0) message:'All tests should have passed'; |
|
766 |
assert:(result failureCount = 0) message:'No test should have failed'; |
|
767 |
assert:(result errorCount = 0) message:'No test should have errors'. |
|
768 |
||
769 |
"Modified: / 27-04-2010 / 09:46:40 / cg" |
|
770 |
! |
|
771 |
||
772 |
withCode:newSource installedAs:selector inClass:aClass do:aBlock |
|
773 |
|oldMethod newMethod| |
|
774 |
||
775 |
oldMethod := aClass compiledMethodAt:selector. |
|
776 |
newMethod := Compiler compile:newSource forClass:aClass install:false. |
|
777 |
||
778 |
[ |
|
779 |
"/ install new method |
|
780 |
aClass basicAddSelector:selector withMethod:newMethod. |
|
781 |
aBlock value:newMethod |
|
782 |
] ensure:[ |
|
783 |
"/ restore original method |
|
784 |
aClass basicAddSelector:selector withMethod:oldMethod. |
|
785 |
]. |
|
786 |
||
787 |
"Created: / 24-04-2010 / 16:26:00 / cg" |
|
788 |
! ! |
|
789 |
||
210 | 790 |
!TestTester methodsFor:'user actions'! |
791 |
||
792 |
selectedTestCaseClassesChanged |
|
793 |
selectedTestCaseClass := selectedTestCaseClasses value firstIfEmpty:nil. |
|
794 |
||
795 |
"Created: / 25-04-2010 / 16:25:18 / cg" |
|
796 |
! |
|
797 |
||
798 |
selectedTesteeClassesChanged |
|
799 |
|methodGenerator| |
|
800 |
||
801 |
methodGenerator := |
|
802 |
Iterator |
|
803 |
on:[:whatToDo | |
|
804 |
|methodClass| |
|
805 |
||
806 |
methodClass := self selectedTesteeClasses value first. |
|
807 |
methodClass methodDictionary |
|
808 |
keysAndValuesDo:[:methodSelector :method | |
|
809 |
whatToDo |
|
810 |
value:methodClass |
|
811 |
value:method category |
|
812 |
value:methodSelector |
|
813 |
value:method. |
|
814 |
]. |
|
815 |
]. |
|
816 |
||
817 |
self testeeMethodListHolder value:methodGenerator |
|
818 |
||
819 |
"Modified: / 25-04-2010 / 15:48:04 / cg" |
|
820 |
! |
|
821 |
||
822 |
selectedTesteeMethodsChanged |
|
823 |
|methods method source| |
|
824 |
||
825 |
methods := self selectedTesteeMethods value. |
|
826 |
methods notEmpty ifTrue:[ |
|
827 |
method := methods first. |
|
828 |
source := method source. |
|
829 |
]. |
|
214 | 830 |
selectedTesteeMethod ~~ method ifTrue:[ |
831 |
(self originalMethodSourceHolder value) ~= source ifTrue:[ |
|
832 |
selectedTesteeMethod := method. |
|
833 |
"/ self halt. |
|
834 |
self originalMethodSourceHolder value:source. |
|
215
6db48dedef3a
changed: #selectedTesteeMethodsChanged
Claus Gittinger <cg@exept.de>
parents:
214
diff
changeset
|
835 |
self mutatedMethodSourceHolder value:nil. |
210 | 836 |
|
214 | 837 |
self updateDiffTextView. |
838 |
]. |
|
839 |
]. |
|
210 | 840 |
|
841 |
"Created: / 25-04-2010 / 15:51:03 / cg" |
|
215
6db48dedef3a
changed: #selectedTesteeMethodsChanged
Claus Gittinger <cg@exept.de>
parents:
214
diff
changeset
|
842 |
"Modified: / 27-04-2010 / 09:54:19 / cg" |
210 | 843 |
! |
844 |
||
845 |
updateDiffTextView |
|
846 |
diffTextView |
|
847 |
text1:(self originalMethodSourceHolder value ? '') |
|
848 |
text2:(self mutatedMethodSourceHolder value ? ''). |
|
212 | 849 |
self windowGroup repairDamage. |
210 | 850 |
|
851 |
"Created: / 26-04-2010 / 10:38:39 / cg" |
|
212 | 852 |
"Modified: / 26-04-2010 / 12:19:26 / cg" |
210 | 853 |
! ! |
854 |
||
855 |
!TestTester::Mutator class methodsFor:'instance creation'! |
|
856 |
||
857 |
forBlock:aBlock |
|
858 |
^ self new blockToCall:aBlock |
|
859 |
||
860 |
"Created: / 24-04-2010 / 16:55:24 / cg" |
|
861 |
! ! |
|
862 |
||
863 |
!TestTester::Mutator methodsFor:'accessing'! |
|
864 |
||
865 |
blockToCall:something |
|
866 |
blockToCall := something. |
|
867 |
! ! |
|
868 |
||
869 |
!TestTester::Mutator methodsFor:'mutating'! |
|
870 |
||
871 |
mutationsOf:aTree do:aBlock |
|
872 |
blockToCall := aBlock. |
|
873 |
treeTop := aTree. |
|
874 |
aTree acceptVisitor:self. |
|
875 |
||
876 |
"Created: / 24-04-2010 / 17:12:19 / cg" |
|
877 |
"Modified: / 24-04-2010 / 19:02:24 / cg" |
|
878 |
! ! |
|
879 |
||
880 |
!TestTester::Mutator methodsFor:'visiting'! |
|
881 |
||
214 | 882 |
acceptAssignmentNode:anAssignmentNode |
883 |
|oldExpr| |
|
884 |
||
885 |
oldExpr := anAssignmentNode value. |
|
886 |
[ |
|
887 |
(self class new) mutationsOf:oldExpr do:[:newExpr | |
|
888 |
anAssignmentNode value:newExpr. |
|
889 |
blockToCall value:treeTop. |
|
890 |
]. |
|
891 |
] ensure:[ |
|
892 |
anAssignmentNode value:oldExpr |
|
893 |
]. |
|
894 |
||
895 |
"Created: / 27-04-2010 / 00:32:14 / cg" |
|
896 |
! |
|
897 |
||
210 | 898 |
acceptBlockNode:aBlockNode |
899 |
self acceptMethodOrBlockNode:aBlockNode |
|
900 |
||
901 |
"Modified: / 24-04-2010 / 19:06:49 / cg" |
|
902 |
! |
|
903 |
||
904 |
acceptLiteralNode:aLiteralNode |
|
905 |
|oldValue| |
|
906 |
||
907 |
oldValue := aLiteralNode value. |
|
908 |
oldValue isInteger ifTrue:[ |
|
909 |
[ |
|
214 | 910 |
Transcript showCR:('Replacing value %1 with: %2' bindWith:oldValue with:oldValue+1). |
210 | 911 |
aLiteralNode token value:oldValue + 1. |
912 |
blockToCall value:treeTop. |
|
214 | 913 |
Transcript showCR:('Replacing value %1 with: %2' bindWith:oldValue with:oldValue-1). |
210 | 914 |
aLiteralNode token value:oldValue - 1. |
915 |
blockToCall value:treeTop. |
|
214 | 916 |
((oldValue ~= 1) and:[oldValue ~= -1 and:[oldValue ~= 0]]) ifTrue:[ |
917 |
Transcript showCR:('Replacing value %1 with: %2' bindWith:oldValue with:0). |
|
210 | 918 |
aLiteralNode token value:0. |
919 |
blockToCall value:treeTop. |
|
920 |
]. |
|
921 |
] ensure:[ |
|
922 |
aLiteralNode token value:oldValue. |
|
923 |
]. |
|
924 |
^ self. |
|
925 |
]. |
|
926 |
oldValue isFloat ifTrue:[ |
|
927 |
self halt. |
|
928 |
^ self. |
|
929 |
]. |
|
930 |
oldValue isSymbol ifTrue:[ |
|
931 |
^ self. |
|
932 |
]. |
|
933 |
oldValue isString ifTrue:[ |
|
934 |
^ self. |
|
935 |
]. |
|
936 |
oldValue isArray ifTrue:[ |
|
937 |
^ self. |
|
938 |
]. |
|
939 |
oldValue isByteArray ifTrue:[ |
|
940 |
self halt. |
|
941 |
^ self. |
|
942 |
]. |
|
943 |
self halt. |
|
944 |
||
945 |
"Created: / 25-04-2010 / 21:32:12 / cg" |
|
214 | 946 |
"Modified: / 27-04-2010 / 09:45:18 / cg" |
210 | 947 |
! |
948 |
||
949 |
acceptMessageNode:aMessageNode |
|
950 |
|selector arguments| |
|
951 |
||
952 |
selector := aMessageNode selector. |
|
953 |
||
954 |
( #( ifTrue: ifFalse: ifTrue:ifFalse: ifFalse:ifTrue:) includes:selector) ifTrue:[ |
|
955 |
self tryWithNegatedCondition:aMessageNode. |
|
956 |
]. |
|
957 |
||
958 |
arguments := aMessageNode arguments. |
|
959 |
1 to:arguments size do:[:idx | |
|
960 |
|oldArg| |
|
961 |
||
962 |
oldArg := arguments at:idx. |
|
963 |
[ |
|
964 |
(self class new) mutationsOf:oldArg do:[:newArg | |
|
965 |
arguments at:idx put:newArg. |
|
966 |
blockToCall value:treeTop. |
|
967 |
]. |
|
968 |
] ensure:[ |
|
969 |
arguments at:idx put:oldArg |
|
970 |
]. |
|
971 |
]. |
|
972 |
||
973 |
"Modified: / 24-04-2010 / 19:07:22 / cg" |
|
974 |
! |
|
975 |
||
976 |
acceptMethodNode:aMethodNode |
|
977 |
self acceptMethodOrBlockNode:aMethodNode |
|
978 |
||
979 |
"Modified: / 24-04-2010 / 19:06:44 / cg" |
|
980 |
! |
|
981 |
||
982 |
acceptMethodOrBlockNode:aMethodOrBlockNode |
|
983 |
|oldBody| |
|
984 |
||
985 |
oldBody := aMethodOrBlockNode body. |
|
986 |
oldBody notNil ifTrue:[ |
|
987 |
[ |
|
988 |
(self class new) mutationsOf:oldBody do:[:newBody | |
|
989 |
aMethodOrBlockNode body:newBody. |
|
990 |
blockToCall value:treeTop. |
|
991 |
]. |
|
992 |
] ensure:[ |
|
993 |
aMethodOrBlockNode body:oldBody |
|
994 |
]. |
|
995 |
]. |
|
996 |
||
997 |
"Created: / 24-04-2010 / 19:06:33 / cg" |
|
998 |
! |
|
999 |
||
1000 |
acceptReturnNode:aReturnNode |
|
1001 |
|oldExpr| |
|
1002 |
||
1003 |
oldExpr := aReturnNode value. |
|
1004 |
[ |
|
1005 |
(self class new) mutationsOf:oldExpr do:[:newExpr | |
|
1006 |
aReturnNode value:newExpr. |
|
1007 |
blockToCall value:treeTop. |
|
1008 |
]. |
|
1009 |
] ensure:[ |
|
1010 |
aReturnNode value:oldExpr |
|
1011 |
]. |
|
1012 |
||
1013 |
"Modified: / 25-04-2010 / 21:30:13 / cg" |
|
1014 |
! |
|
1015 |
||
1016 |
acceptSequenceNode:aSequenceNode |
|
1017 |
|statements| |
|
1018 |
||
1019 |
statements := aSequenceNode statements. |
|
1020 |
||
1021 |
1 to:statements size do:[:idx | |
|
1022 |
|oldStat| |
|
1023 |
||
1024 |
oldStat := statements at:idx. |
|
1025 |
[ |
|
1026 |
(self class new) mutationsOf:oldStat do:[:newStat | |
|
1027 |
statements at:idx put:newStat. |
|
1028 |
blockToCall value:treeTop. |
|
1029 |
]. |
|
1030 |
] ensure:[ |
|
1031 |
statements at:idx put:oldStat |
|
1032 |
]. |
|
1033 |
]. |
|
1034 |
"/ |oldBody| |
|
1035 |
"/ |
|
1036 |
"/ oldBody := aMethodNode body. |
|
1037 |
"/ oldBody notNil ifTrue:[ |
|
1038 |
"/ [ |
|
1039 |
"/ (self class new) mutationsOf:oldBody do:[:newBody | |
|
1040 |
"/self halt. |
|
1041 |
"/ ]. |
|
1042 |
"/ ] ensure:[ |
|
1043 |
"/ aMethodNode body:oldBody |
|
1044 |
"/ ]. |
|
1045 |
"/ ]. |
|
1046 |
"/ |
|
1047 |
"/ "Created: / 24-04-2010 / 16:56:12 / cg" |
|
1048 |
"/ |
|
1049 |
||
1050 |
"Created: / 24-04-2010 / 18:23:35 / cg" |
|
1051 |
! |
|
1052 |
||
1053 |
acceptVariableNode:aVariableNode |
|
1054 |
||
1055 |
"Created: / 25-04-2010 / 21:35:26 / cg" |
|
1056 |
! |
|
1057 |
||
1058 |
tryWithNegatedCondition:aMessageNode |
|
1059 |
|sel repl| |
|
1060 |
||
1061 |
sel := aMessageNode selector. |
|
1062 |
repl := (Dictionary new |
|
1063 |
at: #ifTrue: put: #ifFalse: ; |
|
1064 |
at: #ifFalse: put: #ifTrue: ; |
|
1065 |
at: #ifTrue:ifFalse: put: #ifFalse:ifTrue: ; |
|
1066 |
at: #ifFalse:ifTrue: put: #ifTrue:ifFalse: ; |
|
1067 |
yourself) |
|
1068 |
at:sel. |
|
1069 |
||
1070 |
[ |
|
1071 |
aMessageNode selector:repl. |
|
1072 |
blockToCall value:treeTop. |
|
1073 |
] ensure:[ |
|
1074 |
aMessageNode selector:sel. |
|
1075 |
]. |
|
1076 |
||
1077 |
"Modified: / 24-04-2010 / 19:03:44 / cg" |
|
1078 |
! ! |
|
1079 |
||
1080 |
!TestTester class methodsFor:'documentation'! |
|
1081 |
||
1082 |
version_CVS |
|
215
6db48dedef3a
changed: #selectedTesteeMethodsChanged
Claus Gittinger <cg@exept.de>
parents:
214
diff
changeset
|
1083 |
^ '$Header: /cvs/stx/stx/goodies/sunit/TestTester.st,v 1.4 2010-04-27 08:48:09 cg Exp $' |
210 | 1084 |
! ! |